Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 time_test | 5 package time_test |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "encoding/gob" | 9 "encoding/gob" |
10 "encoding/json" | 10 "encoding/json" |
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1250 var mallocTest = []struct { | 1250 var mallocTest = []struct { |
1251 count int | 1251 count int |
1252 desc string | 1252 desc string |
1253 fn func() | 1253 fn func() |
1254 }{ | 1254 }{ |
1255 {0, `time.Now()`, func() { t = Now() }}, | 1255 {0, `time.Now()`, func() { t = Now() }}, |
1256 {0, `time.Now().UnixNano()`, func() { u = Now().UnixNano() }}, | 1256 {0, `time.Now().UnixNano()`, func() { u = Now().UnixNano() }}, |
1257 } | 1257 } |
1258 | 1258 |
1259 func TestCountMallocs(t *testing.T) { | 1259 func TestCountMallocs(t *testing.T) { |
1260 const N = 100 | |
rsc
2013/01/30 17:55:41
Same.
kevlar
2013/01/31 06:14:02
Done.
| |
1261 | |
1262 for _, mt := range mallocTest { | 1260 for _, mt := range mallocTest { |
1263 » » allocs := testing.AllocsPerRun(N, mt.fn) | 1261 » » allocs := int(testing.AllocsPerRun(100, mt.fn)) |
rsc
2013/01/30 17:55:41
The old version of this did
allocs := int(testing
kevlar
2013/01/31 06:14:02
Done.
| |
1264 » » if max := float64(mt.count); allocs > max { | 1262 » » if allocs > mt.count { |
1265 » » » t.Errorf("%s: %v allocs, want <=%v", mt.desc, allocs, ma x) | 1263 » » » t.Errorf("%s: %d allocs, want %d", mt.desc, allocs, mt.c ount) |
1266 } | 1264 } |
1267 } | 1265 } |
1268 } | 1266 } |
1269 | 1267 |
1270 func BenchmarkNow(b *testing.B) { | 1268 func BenchmarkNow(b *testing.B) { |
1271 for i := 0; i < b.N; i++ { | 1269 for i := 0; i < b.N; i++ { |
1272 t = Now() | 1270 t = Now() |
1273 } | 1271 } |
1274 } | 1272 } |
1275 | 1273 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1321 _ = t.Year() | 1319 _ = t.Year() |
1322 } | 1320 } |
1323 } | 1321 } |
1324 | 1322 |
1325 func BenchmarkDay(b *testing.B) { | 1323 func BenchmarkDay(b *testing.B) { |
1326 t := Now() | 1324 t := Now() |
1327 for i := 0; i < b.N; i++ { | 1325 for i := 0; i < b.N; i++ { |
1328 _ = t.Day() | 1326 _ = t.Day() |
1329 } | 1327 } |
1330 } | 1328 } |
LEFT | RIGHT |