]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: rewrite map size test
authorRuss Cox <rsc@golang.org>
Wed, 31 Jul 2013 12:35:43 +0000 (08:35 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 31 Jul 2013 12:35:43 +0000 (08:35 -0400)
I don't know why the memstats code is flaky.

TBR=bradfitz
CC=golang-dev
https://golang.org/cl/12160043

src/pkg/runtime/hashmap.c
src/pkg/runtime/map_test.go

index 7e0c9572dde3c52596e927c69046af4d946cb3b1..4b51436dc2fc2571da484d55af78657e9e123e07 100644 (file)
@@ -1112,6 +1112,9 @@ runtimeĀ·makemap_c(MapType *typ, int64 hint)
        Type *key;
 
        key = typ->key;
+       
+       if(sizeof(Hmap) > 48)
+               runtimeĀ·panicstring("hmap too large");
 
        if(hint < 0 || (int32)hint != hint)
                runtimeĀ·panicstring("makemap: size out of range");
index 0e36bb2d34b037f7023a2d965dbe09688972737f..9f9c40d156335fe06b905a38f37c330cc252527a 100644 (file)
@@ -371,44 +371,3 @@ func testMapLookups(t *testing.T, m map[string]string) {
                }
        }
 }
-
-func TestMapSize(t *testing.T) {
-       if runtime.GOMAXPROCS(-1) != 1 {
-               t.Skip("gomaxprocs > 1 - not accurate")
-       }
-       var m map[struct{}]struct{}
-       size := bytesPerRun(100, func() {
-               m = make(map[struct{}]struct{})
-       })
-       if size > 48 {
-               t.Errorf("size = %v; want <= 48", size)
-       }
-}
-
-// like testing.AllocsPerRun, but for bytes of memory, not number of allocations.
-func bytesPerRun(runs int, f func()) (avg float64) {
-       defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
-
-       // Warm up the function
-       f()
-
-       // Measure the starting statistics
-       var memstats runtime.MemStats
-       runtime.ReadMemStats(&memstats)
-       sum := 0 - memstats.Alloc
-
-       // Run the function the specified number of times
-       for i := 0; i < runs; i++ {
-               f()
-       }
-
-       // Read the final statistics
-       runtime.ReadMemStats(&memstats)
-       sum += memstats.Alloc
-
-       // Average the mallocs over the runs (not counting the warm-up).
-       // We are forced to return a float64 because the API is silly, but do
-       // the division as integers so we can ask if AllocsPerRun()==1
-       // instead of AllocsPerRun()<2.
-       return float64(sum / uint64(runs))
-}