1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This file implements a simple printer performance benchmark:
6 // go test -bench=BenchmarkPrint
20 var testfile
*ast
.File
22 func testprint(out io
.Writer
, file
*ast
.File
) {
23 if err
:= (&Config
{TabIndent | UseSpaces
, 8, 0}).Fprint(out
, fset
, file
); err
!= nil {
24 log
.Fatalf("print error: %s", err
)
28 // cannot initialize in init because (printer) Fprint launches goroutines.
30 const filename
= "testdata/parser.go"
32 src
, err
:= ioutil
.ReadFile(filename
)
37 file
, err
:= parser
.ParseFile(fset
, filename
, src
, parser
.ParseComments
)
44 if !bytes
.Equal(buf
.Bytes(), src
) {
45 log
.Fatalf("print error: %s not idempotent", filename
)
51 func BenchmarkPrint(b
*testing
.B
) {
55 for i
:= 0; i
< b
.N
; i
++ {
56 testprint(ioutil
.Discard
, testfile
)