mirror of
https://github.com/golang/go
synced 2024-11-16 23:44:42 -07:00
go/printer: report allocs and set bytes
We now get more than just time/op. name time/op Print-16 6.29ms ± 3% name speed Print-16 8.25MB/s ± 3% name alloc/op Print-16 483kB ± 0% name allocs/op Print-16 17.8k ± 0% Change-Id: I6b5e9a30a826ff8603724bd5983e6b7f5ec12708 Reviewed-on: https://go-review.googlesource.com/c/go/+/412554 Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
3af5280c00
commit
85d7bab91d
@ -17,7 +17,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testfile *ast.File
|
var (
|
||||||
|
testfile *ast.File
|
||||||
|
testsize int64
|
||||||
|
)
|
||||||
|
|
||||||
func testprint(out io.Writer, file *ast.File) {
|
func testprint(out io.Writer, file *ast.File) {
|
||||||
if err := (&Config{TabIndent | UseSpaces | normalizeNumbers, 8, 0}).Fprint(out, fset, file); err != nil {
|
if err := (&Config{TabIndent | UseSpaces | normalizeNumbers, 8, 0}).Fprint(out, fset, file); err != nil {
|
||||||
@ -46,12 +49,15 @@ func initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testfile = file
|
testfile = file
|
||||||
|
testsize = int64(len(src))
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkPrint(b *testing.B) {
|
func BenchmarkPrint(b *testing.B) {
|
||||||
if testfile == nil {
|
if testfile == nil {
|
||||||
initialize()
|
initialize()
|
||||||
}
|
}
|
||||||
|
b.ReportAllocs()
|
||||||
|
b.SetBytes(testsize)
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
testprint(io.Discard, testfile)
|
testprint(io.Discard, testfile)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user