https://github.com/dim13/golyb
Go love your brain - yet another optimizing BrainF*ck interpreter in Go
https://github.com/dim13/golyb
brainfuck golang
Last synced: 17 days ago
JSON representation
Go love your brain - yet another optimizing BrainF*ck interpreter in Go
- Host: GitHub
- URL: https://github.com/dim13/golyb
- Owner: dim13
- License: isc
- Created: 2015-11-22T20:03:55.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2025-09-24T21:24:57.000Z (9 months ago)
- Last Synced: 2025-09-24T23:28:41.696Z (9 months ago)
- Topics: brainfuck, golang
- Language: Go
- Homepage:
- Size: 744 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/dim13/golyb)
[](https://github.com/dim13/golyb/actions/workflows/go.yml)
# Go love your brain
Yet another optimizing BrainF\*ck interpreter in Go
## Installation
go get github.com/dim13/golyb/cmd/golyb
## Usage
```
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)
```
## Tape storage type
- 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
# Code optimization
- [x] Contraction
- [x] Clear loops
- [x] Copy loops
- [x] Multiplication loops
- [x] Scan loops (kind of)
- [x] Operation offsets
- [x] Reduce NOPs
Reference: http://calmerthanyouare.org/2015/01/07/optimizing-brainfuck.html
## Some rough results
| 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
## CPU profiles
### mandelbrot.b
#### optimized

#### not optimized

### long.b
#### optimized

#### not optimized

### hanoi.b
#### optimized

#### not optimized
