1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-01-22 03:10:16 +02:00
chroma/lexers/lexer_benchmark_test.go
Alec Thomas cc0e4a59ab Switch to an Iterator interface.
This is to solve an issue where writers returned by the Formatter
were often stateful, but this fact was not obvious to the API consumer,
and failed in interesting ways.
2017-09-20 22:19:36 +10:00

38 lines
734 B
Go

package lexers
import (
"testing"
"github.com/stretchr/testify/assert"
)
const lexerBenchSource = `package chroma
import (
"io"
)
// A Formatter for Chroma lexers.
type Formatter interface {
// Format returns a formatting function for tokens.
Format(w io.Writer, style *Style) (func(*Token), error)
}
// A FormatterFunc is a Formatter implemented as a function.
type FormatterFunc func(io.Writer, *Style) (func(*Token), error)
func (f FormatterFunc) Format(w io.Writer, s *Style) (func(*Token), error) {
return f(w, s)
}
`
func Benchmark(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
it, err := Go.Tokenise(nil, lexerBenchSource)
assert.NoError(b, err)
for t := it(); t != nil; t = it() {
}
}
}