func_test.go 557 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package benchmark
  2. import (
  3. "testing"
  4. )
  5. var (
  6. str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  7. )
  8. func BenchmarkHash(b *testing.B) {
  9. for i := 0; i < b.N; i++ {
  10. Hash([]byte(str))
  11. }
  12. }
  13. func BenchmarkHash2(b *testing.B) {
  14. for i := 0; i < b.N; i++ {
  15. Hash2([]byte(str))
  16. }
  17. }
  18. // Concurrent
  19. func BenchmarkHashParallel(b *testing.B) {
  20. b.RunParallel(func(pb *testing.PB) {
  21. for pb.Next() {
  22. Hash([]byte(str))
  23. }
  24. })
  25. }
  26. // Concurrent
  27. func BenchmarkHash2Parallel(b *testing.B) {
  28. b.RunParallel(func(pb *testing.PB) {
  29. for pb.Next() {
  30. Hash2([]byte(str))
  31. }
  32. })
  33. }