Brainfuck compilersuite
After implementing a "Brainfuck to COBOL"-compiler I became inspired to implement other compilers as well.
Below you will find the whole collection of brainfuck compilers and how well the resulting code performs.
For each I tested the run-time of the brainfuck mandelbrot implementation. Where possible I used the "-flto -O3 -march=native -fomit-frame-pointer" compiler flags.
The compilers to do these compilations/conversions are in GitHub.
language | run time (HH:MM:SS.hh) | remarks |
---|---|---|
6502 asm (C64) | Vice 3.0.0.dfsg-2 | |
Ada | 00:00:02.65 | GNAT 6.1.1 |
Arduino | Nano328: 00:18:14.89 ESP8266: 00:02:55.97 | Nano328 with Arduino 1.0.5 environment ESP8266-F with Arduino 1.6.6 environment |
ARM asm | RPI 1b: 00:00:26.98 RPI 2: 00:00:11.74 RPI 3: 00:00:07.54s RPI 4: 00:00:03.71s | RPI = Raspberry Pi |
Bash | 05:15:58 | 4.3.24(1) |
C | 00:00:01.61 | GCC 5.3.1-14 |
C# | 00:00:04.32 | Mono C# 4.2.1.0 |
Cobol | cobc: 00:02:54.37 cobc+gcc: 00:02:50.48 | OpenCOBOL 1.1.0 GCC 5.3.1-14 |
Go | 00:00:03.58 | Go 1.6 |
HLASM | IBM system z (mainframe) | |
Java | 00:00:10.66 | java version "1.7.0_65" OpenJDK Runtime Environment (IcedTea 2.5.2) (7u65-2.5.2-2) OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode) |
Javascript (nodejs) | 00:00:06.24 | nodejs 4.2.1~dfsg-1 |
Lua | lua: 00:03:07.18 luajit: 00:00:09.04 | Lua 5.2.3 Lua jit 2.0.4 |
MIPS | ||
Pascal | 00:00:03.73 | fpc 3.0.0+dfsg-6 compiler switch: -O4 |
PDP-11 | 00:03:02 | simh V3.8-1 |
Perl 5 | 00:02:16.39 | perl 5.22.1 |
Perl 6 | 00:42:48.15 00:13:41 | 2016.05 2020.12+dfsg-1 |
PHP | 00:01:22.60 | PHP 5.6.16-2 (cli) Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies |
PL/1 | 00:04:32.78 | 0.9.9a (Iron Spring compiler) |
PowerShell | ||
Python | nuitka: 00:02:11 python 2: 00:02:58.05 python 3: 00:03:11.86 pypy: 00:00:08.12 pyston: 00:01:59.84 shedskin: 00:00:01.95 py2many: 00:00:02.21 | nuitka 0.5.25 python 2.7.9 python 3.4.2 pypy 5.3+dfsg-2 pyston 0.5.0 shedskin 0.9.4-1 (with -borsw switches) py2many: C++ target |
Ruby | 00:01:41.96 | ruby 2.1.2p95 (2014-05-08) |
Rust | 00:00:01.30 | rust 1.14.0+dfsg1-3 |
Scala | 00:00:51.46 | Scala code runner 2.11.8 |
SDL Basic | 00:22:23.00 | 0.0.20070714-5 |
SPARC | SunOS 5.6 | |
x86 asm | 00:00:01.48 | x86 assembler, at&t syntax |
Z80 asm (MSX) | 06:48:50 | OpenMSX 0.13.0-1+b1 |
changes
- 2016-06-16: made sure data values stay 8 bit unsigned. This affects run-times in some occassions.
- 2016-06-25: added Lua and Arduino. Note that the Arduino target uses a memory size of 1536 bytes while a Brainfuck interpreter usually has at least 32000 bytes. The mandelbrot works fine on a Nano328. Other Arduinos may have bigger memory (Arduino Mega?).
- 2016-06-25: added ESP8266 for Arduino environment
- 2016-06-26: added Bash and SDL Basic
- 2016-07-11: implemented Perl 6 suggestions by Brad Gilbert which made the resulting code 19x faster!
- 2016-07-14: x86 assembly code
- 2017-02-09: PL/1 target
- 2017-05-29: Scala target
- 2017-06-10: ARM (assembly) target
- 2017-06-28: Commodore 64 (assembly) target, MSX target bugfixing (is now able to run the mandelbrot benchmark)
- 2018-01-13: Rust target
- 2022-07-28: added PDP-11 target
- 2022-08-07: added MIPS target
- 2023-04-20: added SPARC target
- 2023-04-24: Power target
- 2023-10-20: Rust target is now 'safe'
- 2024-02-12: added PowerShell target
examples
Source file: mandelbrot-brainfuck-code.zip
- .prg file for the commodore 64 is in this zip: mandelbrot-c64.zip
- tape image for the PDP-11: mandelbrot-pdp11.zip