-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite benchmarks not to use indirect calls
Move the important benchmarks back into the xxhash package itself. Updates #22
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package xxhash | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
var benchmarks = []struct { | ||
name string | ||
n int64 | ||
}{ | ||
{"4B", 4}, | ||
{"100B", 100}, | ||
{"4KB", 4e3}, | ||
{"10MB", 10e6}, | ||
} | ||
|
||
func BenchmarkSum64(b *testing.B) { | ||
for _, bb := range benchmarks { | ||
in := make([]byte, bb.n) | ||
for i := range in { | ||
in[i] = byte(i) | ||
} | ||
b.Run(bb.name, func(b *testing.B) { | ||
b.SetBytes(bb.n) | ||
for i := 0; i < b.N; i++ { | ||
_ = Sum64(in) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkSum64String(b *testing.B) { | ||
for _, bb := range benchmarks { | ||
s := strings.Repeat("a", int(bb.n)) | ||
b.Run(bb.name, func(b *testing.B) { | ||
b.SetBytes(bb.n) | ||
for i := 0; i < b.N; i++ { | ||
_ = Sum64String(s) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkDigestBytes(b *testing.B) { | ||
for _, bb := range benchmarks { | ||
in := make([]byte, bb.n) | ||
for i := range in { | ||
in[i] = byte(i) | ||
} | ||
b.Run(bb.name, func(b *testing.B) { | ||
b.SetBytes(bb.n) | ||
for i := 0; i < b.N; i++ { | ||
h := New() | ||
h.Write(in) | ||
_ = h.Sum64() | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkDigestString(b *testing.B) { | ||
for _, bb := range benchmarks { | ||
s := strings.Repeat("a", int(bb.n)) | ||
b.Run(bb.name, func(b *testing.B) { | ||
b.SetBytes(bb.n) | ||
for i := 0; i < b.N; i++ { | ||
h := New() | ||
h.WriteString(s) | ||
_ = h.Sum64() | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters