Skip to content

Commit 2c806b5

Browse files
committed
add benchmarks
1 parent a5144ac commit 2c806b5

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

challenge_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,19 @@ func TestFindChallenge_NotFound(t *testing.T) {
7171
t.Fatalf("not an expected error: %s, expected ErrNoChallenge", err.Error())
7272
}
7373
}
74+
75+
var challengeResult *Challenge
76+
77+
func BenchmarkParseChallenge(b *testing.B) {
78+
input := `Digest realm="AXIS_ACCC8EB3494E", nonce="PNHWZB6nBQA=316099a140230c2db387fc75ee1c8ae838a750d8", stale=true, algorithm=MD5, qop="auth"`
79+
var chal *Challenge
80+
b.ResetTimer()
81+
for i := 0; i < b.N; i++ {
82+
var err error
83+
chal, err = ParseChallenge(input)
84+
if err != nil {
85+
b.Fatal(err)
86+
}
87+
}
88+
challengeResult = chal
89+
}

credentials_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,19 @@ func TestCredentials(t *testing.T) {
5050
})
5151
}
5252
}
53+
54+
var credentialsResult *Credentials
55+
56+
func BenchmarkParseCredentials(b *testing.B) {
57+
input := `Digest username="root", realm="AXIS_ACCC8EB3494E", nonce="PNHWZB6nBQA=316099a140230c2db387fc75ee1c8ae838a750d8", uri="/axis-cgi/com/ptz.cgi?camera=1&continuouspantiltmove=-49,0", algorithm=MD5, cnonce="17b7311e0c27a979", qop=auth, nc=00000003, response="9bbb9764c769f388f8e5ff4d26bd0449"`
58+
var cred *Credentials
59+
b.ResetTimer()
60+
for range b.N {
61+
var err error
62+
cred, err = ParseCredentials(input)
63+
if err != nil {
64+
b.Fatal(err)
65+
}
66+
}
67+
credentialsResult = cred // prevent optimization
68+
}

digest_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,32 @@ func TestDigestAuthInt(t *testing.T) {
211211
Nc: 1,
212212
})
213213
}
214+
215+
var digestResult *Credentials
216+
217+
func BenchmarkDigest(b *testing.B) {
218+
opt := Options{
219+
Method: "GET",
220+
URI: "/dir/index.html",
221+
Username: "Mufasa",
222+
Password: "Circle of Life",
223+
Cnonce: "f2/wE4q74E6zIJEtWaHKaf5wv/H5QzzpXusqGemxURZJ",
224+
}
225+
chal := &Challenge{
226+
227+
Algorithm: "MD5",
228+
Nonce: "7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v",
229+
Opaque: "FQhe/qaU925kfnzjCev0ciny7QMkPqMAFRtzCUYo5tdS",
230+
QOP: []string{"auth", "auth-int"},
231+
}
232+
var cred *Credentials
233+
b.ResetTimer()
234+
for range b.N {
235+
var err error
236+
cred, err = Digest(chal, opt)
237+
if err != nil {
238+
b.Fatal(err)
239+
}
240+
}
241+
digestResult = cred // prevent optimizations
242+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/icholy/digest
22

3-
go 1.20
3+
go 1.22
44

55
require gotest.tools/v3 v3.5.1
66

0 commit comments

Comments
 (0)