forked from mirror/jwt
cleaned up benchmarks
This commit is contained in:
parent
901c439dfe
commit
c0c67af490
23
hmac_test.go
23
hmac_test.go
|
@ -78,25 +78,14 @@ func TestHMACSign(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func BenchmarkHMACSigning(b *testing.B) {
|
||||
|
||||
var preppedData = make([]struct {
|
||||
t *jwt.Token
|
||||
method jwt.SigningMethod
|
||||
k interface{}
|
||||
}, len(hmacTestData))
|
||||
|
||||
for i, data := range hmacTestData {
|
||||
preppedData[i].t, _ = jwt.Parse(data.tokenString, func(*jwt.Token) (interface{}, error) { return nil, nil })
|
||||
preppedData[i].method = jwt.GetSigningMethod(data.alg)
|
||||
func BenchmarkHS256Signing(b *testing.B) {
|
||||
benchmarkSigning(b, jwt.SigningMethodHS256, hmacTestKey)
|
||||
}
|
||||
|
||||
for _, data := range preppedData {
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
data.t.SignedString(hmacTestKey)
|
||||
}
|
||||
})
|
||||
func BenchmarkHS384Signing(b *testing.B) {
|
||||
benchmarkSigning(b, jwt.SigningMethodHS384, hmacTestKey)
|
||||
}
|
||||
|
||||
func BenchmarkHS512Signing(b *testing.B) {
|
||||
benchmarkSigning(b, jwt.SigningMethodHS512, hmacTestKey)
|
||||
}
|
||||
|
|
11
jwt_test.go
11
jwt_test.go
|
@ -172,3 +172,14 @@ func TestParseRequest(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method for benchmarking various methods
|
||||
func benchmarkSigning(b *testing.B, method jwt.SigningMethod, key interface{}) {
|
||||
t := jwt.New(method)
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
t.SignedString(key)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
|
12
rsa_test.go
12
rsa_test.go
|
@ -142,3 +142,15 @@ func TestRSAKeyParsing(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkRS256Signing(b *testing.B) {
|
||||
benchmarkSigning(b, jwt.SigningMethodRS256, hmacTestKey)
|
||||
}
|
||||
|
||||
func BenchmarkRS384Signing(b *testing.B) {
|
||||
benchmarkSigning(b, jwt.SigningMethodRS384, hmacTestKey)
|
||||
}
|
||||
|
||||
func BenchmarkRS512Signing(b *testing.B) {
|
||||
benchmarkSigning(b, jwt.SigningMethodRS512, hmacTestKey)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue