mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-31 22:05:17 +02:00
This was done to speed up incremental compilation when working on lexers. That is, modifying a single lexer will no longer require recompiling all lexers. This is a (slightly) backwards breaking change in that lexers are no longer exported directly in the lexers package. The registry API is "aliased" at the old location.
39 lines
776 B
Go
39 lines
776 B
Go
package lexers_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/alecthomas/assert"
|
|
"github.com/alecthomas/chroma/lexers/g"
|
|
)
|
|
|
|
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 := g.Go.Tokenise(nil, lexerBenchSource)
|
|
assert.NoError(b, err)
|
|
for t := it(); t != nil; t = it() {
|
|
}
|
|
}
|
|
}
|