Skip to content

Instantly share code, notes, and snippets.

@Deleplace
Created April 8, 2022 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deleplace/570a9b1d08a0ff4a123dd0c5f2751041 to your computer and use it in GitHub Desktop.
Save Deleplace/570a9b1d08a0ff4a123dd0c5f2751041 to your computer and use it in GitHub Desktop.
Benchmark for a 2014 lexer
package main
import (
"io/ioutil"
"testing"
)
func BenchmarkLexer(b *testing.B) {
filebuf, err := ioutil.ReadFile("testdata/tblgen_input.td")
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
nl := NewLexer(filebuf)
toks := []Token{}
for {
nt := nl.NextToken()
toks = append(toks, nt)
if nt.Name == EOF {
break
}
}
if got, expected := len(toks), 139167; got != expected {
b.Fatalf("Expected %d, got %d", expected, got)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment