summaryrefslogtreecommitdiff
path: root/src/fmt
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2014-09-09 11:45:46 -0700
committerRob Pike <r@golang.org>2014-09-09 11:45:46 -0700
commitf447de583f8a101c406a2ed2e54300bdabb90034 (patch)
tree8f6386d0ecf499003b5d590a0e3c30c32c15c6d3 /src/fmt
parent49384de5d72f451ca24e4d30847e1e02f7af6068 (diff)
downloadgo-f447de583f8a101c406a2ed2e54300bdabb90034.tar.gz
fmt: fix allocation test
With new interface allocation rules, the old counts were wrong and so was the commentary. LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/142760044
Diffstat (limited to 'src/fmt')
-rw-r--r--src/fmt/fmt_test.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/fmt/fmt_test.go b/src/fmt/fmt_test.go
index 8c577949a..89dde2b64 100644
--- a/src/fmt/fmt_test.go
+++ b/src/fmt/fmt_test.go
@@ -855,6 +855,7 @@ func BenchmarkManyArgs(b *testing.B) {
}
var mallocBuf bytes.Buffer
+var mallocPointer *int // A pointer so we know the interface value won't allocate.
var mallocTest = []struct {
count int
@@ -866,11 +867,13 @@ var mallocTest = []struct {
{1, `Sprintf("%x")`, func() { Sprintf("%x", 7) }},
{2, `Sprintf("%s")`, func() { Sprintf("%s", "hello") }},
{1, `Sprintf("%x %x")`, func() { Sprintf("%x %x", 7, 112) }},
- // For %g we use a float32, not float64, to guarantee passing the argument
- // does not need to allocate memory to store the result in a pointer-sized word.
- {2, `Sprintf("%g")`, func() { Sprintf("%g", float32(3.14159)) }},
- {0, `Fprintf(buf, "%x %x %x")`, func() { mallocBuf.Reset(); Fprintf(&mallocBuf, "%x %x %x", 7, 8, 9) }},
+ {2, `Sprintf("%g")`, func() { Sprintf("%g", float32(3.14159)) }}, // TODO: Can this be 1?
{1, `Fprintf(buf, "%s")`, func() { mallocBuf.Reset(); Fprintf(&mallocBuf, "%s", "hello") }},
+ // If the interface value doesn't need to allocate, amortized allocation overhead should be zero.
+ {0, `Fprintf(buf, "%x %x %x")`, func() {
+ mallocBuf.Reset()
+ Fprintf(&mallocBuf, "%x %x %x", mallocPointer, mallocPointer, mallocPointer)
+ }},
}
var _ bytes.Buffer