Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package strconv_test | 5 package strconv_test |
6 | 6 |
7 import ( | 7 import ( |
8 "runtime" | |
9 . "strconv" | 8 . "strconv" |
10 "strings" | 9 "strings" |
11 "testing" | 10 "testing" |
12 ) | 11 ) |
13 | 12 |
14 var ( | 13 var ( |
15 globalBuf [64]byte | 14 globalBuf [64]byte |
16 nextToOne = "1.00000000000000011102230246251565404236316680908203125" + strings.Repeat("0", 10000) + "1" | 15 nextToOne = "1.00000000000000011102230246251565404236316680908203125" + strings.Repeat("0", 10000) + "1" |
17 | 16 |
18 mallocTest = []struct { | 17 mallocTest = []struct { |
(...skipping 18 matching lines...) Expand all Loading... | |
37 {0, `ParseFloat("1.000000000000000111022302462515654042363166809 082031251", 64)`, func() { | 36 {0, `ParseFloat("1.000000000000000111022302462515654042363166809 082031251", 64)`, func() { |
38 ParseFloat("1.000000000000000111022302462515654042363166 809082031251", 64) | 37 ParseFloat("1.000000000000000111022302462515654042363166 809082031251", 64) |
39 }}, | 38 }}, |
40 {0, `ParseFloat("1.000000000000000111022302462515654042363166809 0820312500...001", 64)`, func() { | 39 {0, `ParseFloat("1.000000000000000111022302462515654042363166809 0820312500...001", 64)`, func() { |
41 ParseFloat(nextToOne, 64) | 40 ParseFloat(nextToOne, 64) |
42 }}, | 41 }}, |
43 } | 42 } |
44 ) | 43 ) |
45 | 44 |
46 func TestCountMallocs(t *testing.T) { | 45 func TestCountMallocs(t *testing.T) { |
47 » defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1)) | 46 » const N = 100 |
rsc
2013/01/30 17:55:41
Same.
kevlar
2013/01/31 06:14:02
Done.
| |
47 | |
48 for _, mt := range mallocTest { | 48 for _, mt := range mallocTest { |
49 » » const N = 100 | 49 » » allocs := testing.AllocsPerRun(N, mt.fn) |
50 » » memstats := new(runtime.MemStats) | 50 » » if max := float64(mt.count); allocs > max { |
51 » » runtime.ReadMemStats(memstats) | 51 » » » t.Errorf("%s: %v allocs, want <=%v", mt.desc, allocs, ma x) |
52 » » mallocs := 0 - memstats.Mallocs | |
53 » » for i := 0; i < N; i++ { | |
54 » » » mt.fn() | |
55 » » } | |
56 » » runtime.ReadMemStats(memstats) | |
57 » » mallocs += memstats.Mallocs | |
58 » » if mallocs/N > uint64(mt.count) { | |
59 » » » t.Errorf("%s: expected %d mallocs, got %d", mt.desc, mt. count, mallocs/N) | |
60 } | 52 } |
61 } | 53 } |
62 } | 54 } |
OLD | NEW |