Date post: | 04-Jul-2015 |
Category: |
Technology |
Upload: | sunao-komuro |
View: | 2,777 times |
Download: | 0 times |
Where is fastest BF interpreter?
It’s here!https://github.com/hogelog/fast-bf
Demo
http://esoteric.sange.fi/brainfuck/utils/mandelbrot/mandelbrot.b
Existing fastest(?) BF interpreter
$ time ./bff4 <sample/mandelbrot.b
real 0m8.525s
user 0m8.457s
sys 0m0.004s
Interpret with JIT
$ time ./bf-jit <sample/mandelbrot.b
real 0m3.906s
user 0m3.860s
sys 0m0.000s
Faster!
Interpret with optimizations
$ time ./bf-vm-opt <sample/mandelbrot.b
real 0m3.770s
user 0m3.724s
sys 0m0.000s
Faster!
Interpret with JIT, optimizations
$ time ./bf-jit-opt <sample/mandelbrot.b
real 0m1.573s
user 0m1.540s
sys 0m0.000s
Fastest!
If any other faster,
It’s bug!
Appendix A:
Brainf**k
Design Pattern
++++++++++
*ptr += 10
>>>>>>>>>>
ptr += 10
[-]
*ptr = 0
[>+<-]
*(ptr+1) += *ptr
*ptr = 0
Appendix B:
Brainf**k
Optimization
BF: ++++++++++
Interpret: ++*ptr;++*ptr; …
FetchInstruction
EvalIncrement
FetchInstruction
EvalIncrement
…
10 Instructions
BF: ++++++++++
Interpret: *ptr += 10
FetchInstruction
EvalCalc +10
1 Instruction
BF: >>>>>>>>>>
Interpret: ++ptr;++ptr; …
FetchInstruction
EvalNext
FetchInstruction
EvalNext
…
10 Instructions
BF: >>>>>>>>>>
Interpret: ptr += 10
FetchInstruction
EvalMove +10
1 Instruction
BF: [-]
Interpret:
if(!*ptr) goto ];--*ptr;goto [;
FetchInstruction
Jump If Zero
FetchInstruction
EvalDecrement
FetchInstruction
Jump
Contains Branch
BF: [-]
Interpret: *ptr = 0
FetchInstruction
EvalReset Zero
1 Instruction, No Branch
And othershttps://github.com/hogelog/fast-bf