Guest User

Untitled

a guest
Jan 20th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "crypto/md5"
  5. "crypto/sha1"
  6. "crypto/sha256"
  7. "crypto/sha512"
  8. "hash"
  9. "hash/fnv"
  10. "testing"
  11. )
  12.  
  13. const (
  14. K = 1024
  15. DATALEN = 1 * K
  16. )
  17.  
  18. func runHash(b *testing.B, h hash.Hash, n int) {
  19. var data = make([]byte, n)
  20. for i := 0; i < n; i++ {
  21. data[i] = byte(i*i)
  22. }
  23. b.ResetTimer()
  24. for i := 0; i < b.N; i++ {
  25. h.Reset()
  26. h.Sum(data)
  27. }
  28. }
  29.  
  30. func BenchmarkFNV32(b *testing.B) {
  31. runHash(b, fnv.New32(), DATALEN)
  32. }
  33.  
  34. func BenchmarkFNV64(b *testing.B) {
  35. runHash(b, fnv.New64(), DATALEN)
  36. }
  37.  
  38. func BenchmarkFNV128(b *testing.B) {
  39. runHash(b, fnv.New128(), DATALEN)
  40. }
  41.  
  42. func BenchmarkMD5(b *testing.B) {
  43. runHash(b, md5.New(), DATALEN)
  44. }
  45.  
  46. func BenchmarkSHA1(b *testing.B) {
  47. runHash(b, sha1.New(), DATALEN)
  48. }
  49.  
  50. func BenchmarkSHA224(b *testing.B) {
  51. runHash(b, sha256.New224(), DATALEN)
  52. }
  53.  
  54. func BenchmarkSHA256(b *testing.B) {
  55. runHash(b, sha256.New(), DATALEN)
  56. }
  57.  
  58. func BenchmarkSHA512(b *testing.B) {
  59. runHash(b, sha512.New(), DATALEN)
  60. }
Add Comment
Please, Sign In to add comment