aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/expvar/expvar_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/expvar/expvar_test.go')
-rw-r--r--libgo/go/expvar/expvar_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/libgo/go/expvar/expvar_test.go b/libgo/go/expvar/expvar_test.go
index 804b56c..7b1f83a 100644
--- a/libgo/go/expvar/expvar_test.go
+++ b/libgo/go/expvar/expvar_test.go
@@ -6,6 +6,7 @@ package expvar
import (
"bytes"
+ "crypto/sha1"
"encoding/json"
"fmt"
"net"
@@ -299,6 +300,26 @@ func BenchmarkMapSetDifferent(b *testing.B) {
})
}
+// BenchmarkMapSetDifferentRandom simulates such a case where the concerned
+// keys of Map.Set are generated dynamically and as a result insertion is
+// out of order and the number of the keys may be large.
+func BenchmarkMapSetDifferentRandom(b *testing.B) {
+ keys := make([]string, 100)
+ for i := range keys {
+ keys[i] = fmt.Sprintf("%x", sha1.Sum([]byte(fmt.Sprint(i))))
+ }
+
+ v := new(Int)
+ b.ResetTimer()
+
+ for i := 0; i < b.N; i++ {
+ m := new(Map).Init()
+ for _, k := range keys {
+ m.Set(k, v)
+ }
+ }
+}
+
func BenchmarkMapSetString(b *testing.B) {
m := new(Map).Init()
@@ -350,6 +371,25 @@ func BenchmarkMapAddDifferent(b *testing.B) {
})
}
+// BenchmarkMapAddDifferentRandom simulates such a case where that the concerned
+// keys of Map.Add are generated dynamically and as a result insertion is out of
+// order and the number of the keys may be large.
+func BenchmarkMapAddDifferentRandom(b *testing.B) {
+ keys := make([]string, 100)
+ for i := range keys {
+ keys[i] = fmt.Sprintf("%x", sha1.Sum([]byte(fmt.Sprint(i))))
+ }
+
+ b.ResetTimer()
+
+ for i := 0; i < b.N; i++ {
+ m := new(Map).Init()
+ for _, k := range keys {
+ m.Add(k, 1)
+ }
+ }
+}
+
func BenchmarkMapAddSameSteadyState(b *testing.B) {
m := new(Map).Init()
b.RunParallel(func(pb *testing.PB) {