diff options
author | Aliaksandr Valialkin <valyala@gmail.com> | 2015-11-14 20:36:33 +0200 |
---|---|---|
committer | Aliaksandr Valialkin <valyala@gmail.com> | 2015-11-14 20:36:33 +0200 |
commit | 91f896309a7d995d021766efc187807314cfe8b7 (patch) | |
tree | 44c9b8fa2036d5eb8bcb0209a00b63625456174f /args_timing_test.go | |
parent | Updated TODO (diff) | |
download | fasthttp-91f896309a7d995d021766efc187807314cfe8b7.tar.gz fasthttp-91f896309a7d995d021766efc187807314cfe8b7.tar.bz2 fasthttp-91f896309a7d995d021766efc187807314cfe8b7.zip |
Added benchmark for Args.Peek()
Diffstat (limited to 'args_timing_test.go')
-rw-r--r-- | args_timing_test.go | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/args_timing_test.go b/args_timing_test.go index 9fb22a7..d6e9e98 100644 --- a/args_timing_test.go +++ b/args_timing_test.go @@ -1,13 +1,30 @@ package fasthttp import ( + "bytes" "testing" ) func BenchmarkArgsParse(b *testing.B) { - var a Args s := []byte("foo=bar&baz=qqq&aaaaa=bbbb") - for i := 0; i < b.N; i++ { - a.ParseBytes(s) - } + b.RunParallel(func(pb *testing.PB) { + var a Args + for pb.Next() { + a.ParseBytes(s) + } + }) +} + +func BenchmarkArgsPeek(b *testing.B) { + value := []byte("foobarbaz1234") + key := "foobarbaz" + b.RunParallel(func(pb *testing.PB) { + var a Args + a.SetBytesV(key, value) + for pb.Next() { + if !bytes.Equal(a.Peek(key), value) { + b.Fatalf("unexpected arg value %q. Expecting %q", a.Peek(key), value) + } + } + }) } |