go-brainfuck-yourself

A Brainfuck interpreter that I wrote myself in Go
git clone git@abtrout.com:go-brainfuck-yourself.git
Log | Files | Refs | README

commit 2cc5adf4f02e109c888639692bbdd82294e6a399
parent aa565944a634fe5dbfc933226dc8174a94b5766c
Author: david cochran <about.trout@gmail.com>
Date:   Sun, 12 Jul 2026 14:24:59 -0700

add benchmarks for upcoming optimizations

```
$ go test -bench=.
goos: darwin
goarch: arm64
pkg: github.com/abtrout/gbfy
cpu: Apple M3
BenchmarkLong-8                        1        30521266042 ns/op
BenchmarkMandelbrot-8                  1        23543847083 ns/op
BenchmarkFactor-8                      1        1914946834 ns/op
PASS
ok      github.com/abtrout/gbfy 56.339s
```

Diffstat:
Mbf_test.go | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/bf_test.go b/bf_test.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io" + "os" "testing" "github.com/google/go-cmp/cmp" @@ -157,3 +158,19 @@ func Run(cmds []byte, in io.Reader) ([]byte, error) { } return out.Bytes(), nil } + +// Find your own source files! +func BenchmarkLong(b *testing.B) { runBenchmark(b, "long.bf", nil) } +func BenchmarkMandelbrot(b *testing.B) { runBenchmark(b, "mandelbrot.bf", nil) } +func BenchmarkFactor(b *testing.B) { runBenchmark(b, "factor.bf", bytes.NewReader([]byte("418151632\n"))) } + +func runBenchmark(b *testing.B, path string, in io.Reader) { + b.Helper() + src, err := os.ReadFile(path) + if err != nil { + b.Fatalf("Failed to read benchmark file %q: %v", path, err) + } + if _, err := Run(src, in); err != nil { + b.Fatalf("Failed to run benchmark program %q: %v", path, err) + } +}