Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(116)

Issue 12160043: code review 12160043: runtime: rewrite map size test (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 8 months ago by rsc
Modified:
11 years, 8 months ago
Reviewers:
dvyukov, bradfitz
CC:
bradfitz, golang-dev
Visibility:
Public.

Description

runtime: rewrite map size test I don't know why the memstats code is flaky.

Patch Set 1 #

Patch Set 2 : diff -r 19bc695d0c39 https://code.google.com/p/go/ #

Patch Set 3 : diff -r 19bc695d0c39 https://code.google.com/p/go/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+3 lines, -41 lines) Patch
M src/pkg/runtime/hashmap.c View 1 1 chunk +3 lines, -0 lines 0 comments Download
M src/pkg/runtime/map_test.go View 1 1 chunk +0 lines, -41 lines 0 comments Download

Messages

Total messages: 4
rsc
Hello bradfitz (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go/
11 years, 8 months ago (2013-07-31 12:35:38 UTC) #1
rsc
*** Submitted as https://code.google.com/p/go/source/detail?r=d39481d8010a *** runtime: rewrite map size test I don't know why the ...
11 years, 8 months ago (2013-07-31 12:35:47 UTC) #2
dvyukov
LGTM This is much simpler way to test the size :)
11 years, 8 months ago (2013-07-31 12:48:46 UTC) #3
bradfitz
11 years, 8 months ago (2013-07-31 14:57:18 UTC) #4
LGTM

Thanks :)
On Jul 31, 2013 5:35 AM, <rsc@golang.org> wrote:

> Reviewers: bradfitz,
>
> Message:
> Hello bradfitz (cc: golang-dev@googlegroups.com),
>
> I'd like you to review this change to
> https://code.google.com/p/go/
>
>
> Description:
> runtime: rewrite map size test
>
> I don't know why the memstats code is flaky.
>
> Please review this at
https://codereview.appspot.**com/12160043/<https://codereview.appspot.com/121...
>
> Affected files:
>   M src/pkg/runtime/hashmap.c
>   M src/pkg/runtime/map_test.go
>
>
> Index: src/pkg/runtime/hashmap.c
> ==============================**==============================**=======
> --- a/src/pkg/runtime/hashmap.c
> +++ b/src/pkg/runtime/hashmap.c
> @@ -1112,6 +1112,9 @@
>         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: src/pkg/runtime/map_test.go
> ==============================**==============================**=======
> --- a/src/pkg/runtime/map_test.go
> +++ b/src/pkg/runtime/map_test.go
> @@ -371,44 +371,3 @@
>                 }
>         }
>  }
> -
> -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))
> -}
>
>
>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b