https://github.com/siraben/bf
Fast, simple brainfuck interpreter in C
https://github.com/siraben/bf
brainfuck c interpreter
Last synced: 11 months ago
JSON representation
Fast, simple brainfuck interpreter in C
- Host: GitHub
- URL: https://github.com/siraben/bf
- Owner: siraben
- License: mit
- Created: 2022-02-15T07:38:38.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-05-05T17:46:28.000Z (about 2 years ago)
- Last Synced: 2025-02-11T21:41:21.989Z (over 1 year ago)
- Topics: brainfuck, c, interpreter
- Language: C
- Homepage:
- Size: 960 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Brainfuck interpreter in C

This is an interpreter for Brainfuck I initially wrote in an evening
in C. The interpreter is essentially as fast as it can be without
resorting to JIT compilation, because the following optimizations were
performed:
- precomputing jump lengths between `[` and `]`
- precomputing runs of `+`, `-`, `>`, `<`
In terms of relative speedups, here's what my MacBookPro18,3 reports
(optimizations are cumulative, so subsequent ones include previous
ones).
| Optimization | Time to render mandelbrot set (s) |
|------------------|-----------------------------------|
| none | 28.57 |
| precompute jumps | 15.25 |
| precompute runs | 7.71 |
| no flush on . | 6.49 |
See the Mandelbrot set with
```ShellSession
$ nix run github:siraben/bf <(curl -s https://raw.githubusercontent.com/erikdubbelboer/brainfuck-jit/master/mandelbrot.bf)
```
## Building
With Nix, run `nix build github:siraben/bf`.
```ShellSession
$ gcc -O2 -o bf bf.c
```
## Tested Programs
- Mandelbrot set
- Hello world
- ROT13
- [Lost Kingdom](https://github.com/rdebath/LostKingdom) (text
adventure game)