userdata_timing_test.go 950 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package fasthttp
  2. import (
  3. "testing"
  4. )
  5. func BenchmarkUserDataCustom(b *testing.B) {
  6. keys := []string{"foobar", "baz", "aaa", "bsdfs"}
  7. b.RunParallel(func(pb *testing.PB) {
  8. var u userData
  9. var v interface{} = u
  10. for pb.Next() {
  11. for _, key := range keys {
  12. u.Set(key, v)
  13. }
  14. for _, key := range keys {
  15. vv := u.Get(key)
  16. if _, ok := vv.(userData); !ok {
  17. b.Fatalf("unexpected value %v for key %q", vv, key)
  18. }
  19. }
  20. u.Reset()
  21. }
  22. })
  23. }
  24. func BenchmarkUserDataStdMap(b *testing.B) {
  25. keys := []string{"foobar", "baz", "aaa", "bsdfs"}
  26. b.RunParallel(func(pb *testing.PB) {
  27. u := make(map[string]interface{})
  28. var v interface{} = u
  29. for pb.Next() {
  30. for _, key := range keys {
  31. u[key] = v
  32. }
  33. for _, key := range keys {
  34. vv := u[key]
  35. if _, ok := vv.(map[string]interface{}); !ok {
  36. b.Fatalf("unexpected value %v for key %q", vv, key)
  37. }
  38. }
  39. for k := range u {
  40. delete(u, k)
  41. }
  42. }
  43. })
  44. }