You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
670 B

  1. package benchmarks
  2. import (
  3. . "github.com/tendermint/go-common"
  4. "testing"
  5. )
  6. func BenchmarkSomething(b *testing.B) {
  7. b.StopTimer()
  8. numItems := 100000
  9. numChecks := 100000
  10. keys := make([]string, numItems)
  11. for i := 0; i < numItems; i++ {
  12. keys[i] = RandStr(32)
  13. }
  14. txs := make([]string, numChecks)
  15. for i := 0; i < numChecks; i++ {
  16. txs[i] = RandStr(32)
  17. }
  18. b.StartTimer()
  19. counter := 0
  20. for j := 0; j < b.N; j++ {
  21. foo := make(map[string]string)
  22. for _, key := range keys {
  23. foo[key] = key
  24. }
  25. for _, tx := range txs {
  26. if _, ok := foo[tx]; ok {
  27. counter++
  28. }
  29. }
  30. for _, tx := range txs {
  31. if _, ok := foo[tx]; ok {
  32. counter++
  33. }
  34. }
  35. }
  36. }