Created
April 8, 2022 16:10
-
-
Save Deleplace/570a9b1d08a0ff4a123dd0c5f2751041 to your computer and use it in GitHub Desktop.
Benchmark for a 2014 lexer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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