MCPcopy
hub / github.com/golang-jwt/jwt / BenchmarkECDSASigning

Function BenchmarkECDSASigning

ecdsa_test.go:129–166  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

127}
128
129func BenchmarkECDSASigning(b *testing.B) {
130 for _, data := range ecdsaTestData {
131 key, _ := os.ReadFile(data.keys["private"])
132
133 ecdsaKey, err := jwt.ParseECPrivateKeyFromPEM(key)
134 if err != nil {
135 b.Fatalf("Unable to parse ECDSA private key: %v", err)
136 }
137
138 method := jwt.GetSigningMethod(data.alg)
139
140 b.Run(data.name, func(b *testing.B) {
141 benchmarkSigning(b, method, ecdsaKey)
142 })
143
144 // Directly call method.Sign without the decoration of *Token.
145 b.Run(data.name+"/sign-only", func(b *testing.B) {
146 if !data.valid {
147 b.Skipf("Skipping because data is not valid")
148 }
149
150 parts := strings.Split(data.tokenString, ".")
151 toSign := strings.Join(parts[0:2], ".")
152
153 b.ReportAllocs()
154 b.ResetTimer()
155 for i := 0; i < b.N; i++ {
156 sig, err := method.Sign(toSign, ecdsaKey)
157 if err != nil {
158 b.Fatalf("[%v] Error signing token: %v", data.name, err)
159 }
160 if reflect.DeepEqual(sig, decodeSegment(b, parts[2])) {
161 b.Fatalf("[%v] Identical signatures\nbefore:\n%v\nafter:\n%v", data.name, parts[2], sig)
162 }
163 }
164 })
165 }
166}
167
168func decodeSegment(t interface{ Fatalf(string, ...any) }, signature string) (sig []byte) {
169 var err error

Callers

nothing calls this directly

Calls 3

benchmarkSigningFunction · 0.85
decodeSegmentFunction · 0.85
SignMethod · 0.65

Tested by

no test coverage detected