Execute Brain****/Brain****

From Rosetta Code
Execute Brain****/Brain**** is an implementation of Brainf***. Other implementations of Brainf***.

Dbfi is a brainfuck self-interpreter written by Daniel B. Cristofani [1] and described in detail in [2]. This is the shortest known brainfuck self-interpreter and possibly the shortest self-interpreter amongst all imperative languages. Note that a big part of dbfi code is devoted to ASCII decoding, comment handling, and avoiding undefined behaviour. Removing this would reduce the size to nearly half.

>>>+[[-]>>[-]++>+>+++++++[<++++>>++<-]++>>+>+>+++++[>++>++++++<<-]+>>>,<++[[>[
->>]<[>>]<<-]<[<]<+>>[>]>[<+>-[[<+>-]>]<[[[-]<]++<-[<+++++++++>[<->-]>>]>>]]<<
]<]<[[<]>[[>]>>[>>]+[<<]<[<]<+>>-]>[>]+[->>]<<<<[[<<]<[<]+<<[+>+<<-[>-->+<<-[>
+<[>>+<<-]]]>[<+>-]<]++>>-->[>]>>[>>]]<<[>>+<[[<]<]>[[<<]<[<]+[-<+>>-[<<+>++>-
[<->[<<+>>-]]]<[>+<-]>]>[>]>]>[>>]>>]<<[>>+>>+>>]<<[->>>>>>>>]<<[>.>>>>>>>]<<[
>->>>>>]<<[>,>>>]<<[>+>]<<[+<<]<]

Dbfi inspired Clive Gifford to write the fastest Brainfuck self-interpreter (since dbfi is the shortest, but not the fastest) [3]. Its compressed version is

>>>>>+[->>++>+>+++++++[<++++>>++<-]++>>+>+>+++++[>++>++++++<<-]+>>>,<++[[>[->>
]<[>>]<<-]<[<]<+>>[>]>[<+>-[[<+>-]>]<[[[-]<]++<-[<+++++++++>[<->-]>>]>>]]<<]>[
-]+<<[--[[-]>>->+<<<]>>[-<<<<[>+<-]>>>>>>+<]<<]>>[-]<<>>>[<<<+>>>-]<<<]>>>+<<<
<[<<]>>[[<+>>+<-]+<-[-[-[-[-[-[-[->->>[>>]>>[>>]<+<[<<]<<[<<]<]>[->>[>>]>>[>>]
<,<[<<]<<[<<]]<]>[->>[>>]>>[>>]<-<[<<]<<[<<]]<]>[->>[>>]>>[>>]<.<[<<]<<[<<]]<]
>[->>[>>]>>[>>]<<-<<[<<]<<[<<]]<]>[->>[>>]>>[>>]+[<<]<<[<<]]<]>[->>[>>]>>[>>]<
[>+>>+<<<-]>[<+>-]>>[<<+>>[-]]+<<[>>-<<-]>>[<<+>>>>+<<-]>>[<<+>>-]<<[>>+<<-]+>
>[<<->>-]<<<<[-<<[<<]<<[<<]<<<<<++>>]>>[-<<<<<<[<<]<<[<<]<]>]<]>[->>[>>]>>[>>]
<[>+>>+<<<-]>[[<+>-]>>[-]+<<]>>[<<+>>>>+<<-]>>[<<+>>-]<<[>>+<<-]+>>[<<->>-]<<<
<[-<<[<<]<<[<<]<<<<<+>>]>>[-<<<<<<[<<]<<[<<]<]>]>[<+>-]<<<<<<[>>+<<-[->>->>+[>
>>[-<+>>+<]+<-[-[[-]>[-]<]>[-1<<<+>>>]<]>[-<<<->>>]>[-<+>]<<<<[>>+<<-]>>]<<<<<
<]>>[-<<+[>>>[-<+>>+<]+<-[-[[-]>[-]<]>[-1<<<->>>]<]>[-<<<+>>>]>[-<+>]<<<<[<<+>
>-]<<]]]>>>>>>>]

Below is relative comparison of time to run a simple program with a stack of two self-interpreters.

Lower SI Upper SI Time
cgbfi cgbfi 9.1
cgbfi dbfi 7.0
dbfi cgbfi 35.0
dbfi dbfi 21.3

Here cgbfi stands for Clive Gifford Brainfuck Interpreter. Time is given in seconds, which does not matter, because only relative values are important.

The second line shows faster result because DBFI is shorter than CGBSI, and this outweighs the speed benefit of the faster self-interpreter used in the second level in the stack of interpreters. The short program used for the comparison is

>+>+>+>+>++<[>[<+++>-]<<]> [>+>+<<-]>[-]>.!

and the interpreter bff4.c.

Content is available under CC0 public domain dedication via the esolang wiki.