Skip to content

Commit

Permalink
examples/uc/lexer: Add benchmark.
Browse files Browse the repository at this point in the history
As compared to Gocc, the regexp based lexer generated by genlex
is roughly two orders of magnitude slower.
  • Loading branch information
mewmew committed Feb 13, 2017
1 parent 476be9c commit eea4e50
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions examples/uc/lexer/lexer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package lexer_test

import (
"io"
"io/ioutil"
"testing"

"github.com/mewmew/speak/examples/uc/lexer"
"github.com/pkg/errors"
)

func BenchmarkLexerScan(b *testing.B) {
buf, err := ioutil.ReadFile("../testdata/input.c")
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
b.SetBytes(int64(len(buf)))
for i := 0; i < b.N; i++ {
l := lexer.NewFromBytes(buf)
for {
_, err := l.Scan()
if err != nil {
if errors.Cause(err) == io.EOF {
break
}
b.Fatalf("lexer error; %v", err)
}
}
}
}

0 comments on commit eea4e50

Please sign in to comment.