...
Run Format

Source file src/go/parser/performance_test.go

Documentation: go/parser

     1  // Copyright 2012 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.
     4  
     5  package parser
     6  
     7  import (
     8  	"go/token"
     9  	"io/ioutil"
    10  	"testing"
    11  )
    12  
    13  var src = readFile("parser.go")
    14  
    15  func readFile(filename string) []byte {
    16  	data, err := ioutil.ReadFile(filename)
    17  	if err != nil {
    18  		panic(err)
    19  	}
    20  	return data
    21  }
    22  
    23  func BenchmarkParse(b *testing.B) {
    24  	b.SetBytes(int64(len(src)))
    25  	for i := 0; i < b.N; i++ {
    26  		if _, err := ParseFile(token.NewFileSet(), "", src, ParseComments); err != nil {
    27  			b.Fatalf("benchmark failed due to parse error: %s", err)
    28  		}
    29  	}
    30  }
    31  

View as plain text