Yet another optimizing BrainF*ck interpreter in Go
go get github.com/dim13/golyb/cmd/golyb
Usage of golyb:
-dump
Dump AST and terminate
-file string
Source file (required)
-in string
Input file
-noop
Disable optimization
-out string
Output file or /dev/null
-profile string
Write CPU profile to file
-show
Dump tape cells
-tape value
Tape type: static or dynamic (default static)
- static: 32k byte cells including 1k margin on the lower end (used by default)
- dynamic: int cells allocated in 1k chunks as required on access
- Contraction
- Clear loops
- Copy loops
- Multiplication loops
- Scan loops (kind of)
- Operation offsets
- Reduce NOPs
Reference: http://calmerthanyouare.org/2015/01/07/optimizing-brainfuck.html
Program | w/o optimization | with optimization | speed gain |
---|---|---|---|
madelbrot.b | 52.3 sec | 11.8 sec | 4.4x |
long.b | 48.5 sec | 5.4 sec | 9.0x |
hanoi.b | 47.0 sec | 1.0 sec | 47.0x |
bench.b | 6.6 sec | 1.1 sec | 6.0x |
Executed on 1.3 GHz Intel Core i5