diff --git a/pkg/crypto/hashing/hashing_bench_test.go b/pkg/crypto/hashing/hashing_bench_test.go new file mode 100644 index 00000000..03246eaa --- /dev/null +++ b/pkg/crypto/hashing/hashing_bench_test.go @@ -0,0 +1,35 @@ +package hashing + +import ( + "testing" + "time" + + testutils "github.com/number571/go-peer/test/utils" +) + +/* +goos: linux +goarch: amd64 +pkg: github.com/number571/go-peer/pkg/crypto/hashing +cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz +BenchmarkHasher-12 1000000 268.5 ns/op +--- BENCH: BenchmarkHasher-12 + hashing_bench_test.go:37: Timer (N=1): 717ns + hashing_bench_test.go:37: Timer (N=1000000): 268.460938ms +PASS +*/ + +// go test -bench=BenchmarkHasher -benchtime=1000000x -timeout 99999s +func BenchmarkHasher(b *testing.B) { + b.StopTimer() + randomBytes := testutils.PseudoRandomBytes(int(time.Now().UnixNano())) + b.StartTimer() + + now := time.Now() + for i := 0; i < b.N; i++ { + _ = NewHasher(randomBytes).ToBytes() + } + end := time.Since(now) + + b.Logf("Timer (N=%d): %s", b.N, end) +} diff --git a/pkg/crypto/hashing/hashing_test.go b/pkg/crypto/hashing/hashing_test.go index 6d18a434..1d9480be 100644 --- a/pkg/crypto/hashing/hashing_test.go +++ b/pkg/crypto/hashing/hashing_test.go @@ -1,7 +1,6 @@ package hashing import ( - "fmt" "testing" ) @@ -21,8 +20,6 @@ func TestHasher(t *testing.T) { t.Error("bit didn't change the result ") return } - - fmt.Println(hash) } func TestHMACSHasher(t *testing.T) { diff --git a/test/result/badge_codelines.svg b/test/result/badge_codelines.svg index f7206dc8..3560dc96 100644 --- a/test/result/badge_codelines.svg +++ b/test/result/badge_codelines.svg @@ -1 +1 @@ -code lines: 12366code lines12366 \ No newline at end of file +code lines: 12363code lines12363 \ No newline at end of file diff --git a/test/result/coverage.svg b/test/result/coverage.svg index 29ffa1a8..0d847000 100644 --- a/test/result/coverage.svg +++ b/test/result/coverage.svg @@ -7,7 +7,7 @@ > - + - + - + - + - + - +