Skip to content

Added a Next method to the Lexer (which avoids allocations) as an alternative to Scan (which provides more debugging info) - #148

Closed
awalterschulze wants to merge 1 commit into
goccmack:masterfrom
awalterschulze:master
Closed

awalterschulze wants to merge 1 commit into
goccmack:masterfrom
awalterschulze:master

Conversation

@awalterschulze

Copy link
Copy Markdown
Collaborator

Added a benchmark to show how there are now no allocations as part of Next, see example/mail/parser_test.go

mail % go test -v --test.bench=.
=== RUN   TestScan1
--- PASS: TestScan1 (0.00s)
=== RUN   TestNext1
--- PASS: TestNext1 (0.00s)
=== RUN   TestScan2
--- PASS: TestScan2 (0.00s)
=== RUN   TestNext2
--- PASS: TestNext2 (0.00s)
goos: darwin
goarch: arm64
pkg: github.com/goccmack/gocc/example/mail
cpu: Apple M4 Pro
BenchmarkScan
BenchmarkScan-14         3863421               294.4 ns/op           240 B/op          3 allocs/op
BenchmarkNext
BenchmarkNext-14         5198650               234.3 ns/op             0 B/op          0 allocs/op
PASS

The idea is that this can be used for high performance validation

Added a benchmark to show how there are now no allocations as part of Next

```
mail % go test -v --test.bench=.
=== RUN   TestScan1
--- PASS: TestScan1 (0.00s)
=== RUN   TestNext1
--- PASS: TestNext1 (0.00s)
=== RUN   TestScan2
--- PASS: TestScan2 (0.00s)
=== RUN   TestNext2
--- PASS: TestNext2 (0.00s)
goos: darwin
goarch: arm64
pkg: github.com/goccmack/gocc/example/mail
cpu: Apple M4 Pro
BenchmarkScan
BenchmarkScan-14         3863421               294.4 ns/op           240 B/op          3 allocs/op
BenchmarkNext
BenchmarkNext-14         5198650               234.3 ns/op             0 B/op          0 allocs/op
PASS
```
@awalterschulze

Copy link
Copy Markdown
Collaborator Author

This is not necessary we can just copy these methods beside the Lexer for faster lexing, we do not need to generate them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant