hashmap_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package hashmap_test
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/alphadose/haxmap"
  6. "github.com/cornelk/hashmap"
  7. )
  8. func BenchmarkGoMap(t *testing.B) {
  9. // 1000000 loop
  10. // goos: darwin
  11. // goarch: amd64
  12. // pkg: test/hashmap
  13. // cpu: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  14. // BenchmarkGoMap
  15. // BenchmarkGoMap-8 1000000000 0.5068 ns/op 0 B/op 0 allocs/op
  16. // PASS
  17. // ok test/hashmap 14.880s
  18. // 100000 loop
  19. // goos: darwin
  20. // goarch: amd64
  21. // pkg: test/hashmap
  22. // cpu: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  23. // BenchmarkGoMap
  24. // BenchmarkGoMap-8 1000000000 0.02783 ns/op 0 B/op 0 allocs/op
  25. // PASS
  26. // ok test/hashmap 0.721s
  27. m := map[string]int{}
  28. t.StartTimer()
  29. for i := 0; i < 100000; i++ {
  30. s := fmt.Sprint(i)
  31. m[s] = i
  32. }
  33. t.StopTimer()
  34. }
  35. func BenchmarkHaxMap(t *testing.B) {
  36. // 1000000 loop
  37. // goos: darwin
  38. // goarch: amd64
  39. // pkg: test/hashmap
  40. // cpu: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  41. // BenchmarkHaxMap
  42. // BenchmarkHaxMap-8 1000000000 0.8453 ns/op 0 B/op 0 allocs/op
  43. // PASS
  44. // ok test/hashmap 65.175s
  45. // 100000 loop
  46. // goos: darwin
  47. // goarch: amd64
  48. // pkg: test/hashmap
  49. // cpu: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  50. // BenchmarkHaxMap
  51. // BenchmarkHaxMap-8 1000000000 0.05282 ns/op 0 B/op 0 allocs/op
  52. // PASS
  53. // ok test/hashmap 1.154s
  54. m := haxmap.New[string, int]()
  55. t.StartTimer()
  56. for i := 0; i < 100000; i++ {
  57. s := fmt.Sprint(i)
  58. m.Set(s, i)
  59. }
  60. t.StopTimer()
  61. }
  62. func BenchmarkHashMap(t *testing.B) {
  63. // 1000000 loop Crash
  64. // 100000 loop
  65. // goos: darwin
  66. // goarch: amd64
  67. // pkg: test/hashmap
  68. // cpu: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  69. // BenchmarkHashMap
  70. // BenchmarkHashMap-8 1 33365603372 ns/op 11402896 B/op 399822 allocs/op
  71. // PASS
  72. // ok test/hashmap 33.493s
  73. m := hashmap.New[string, int]()
  74. t.StartTimer()
  75. for i := 0; i < 100000; i++ {
  76. s := fmt.Sprint(i)
  77. m.Set(s, i)
  78. }
  79. t.StopTimer()
  80. }