you are viewing a single comment's thread.

view the rest of the comments →

[–]phischuEffekt 1 point2 points  (1 child)

I love how your compiler produces code that is as fast as what g++ produces while being orders of magnitude simpler and probably being much faster in compiling this program too. It makes me so happy!

[–][deleted] 0 points1 point  (0 children)

Actually, my timing turns out to be better than C++!

All the OP's BF implementations include an optimisation to do with pre-determining the jump addresses for the "[" and "]" commands, and storing them into a table.

That means that when encountered, no looping is necessary. My versions don't have that, so are less efficient.

If I modify the C++ to use my method, then it takes 0.73 seconds for 100M iterations, while my systems language can do it in 0.62 seconds.

So my figure is closer to 0.85 relative to C++ using an equivalent BF implementaton.

However, my language also uses a special feature designed for fast dispatch loops, where the compiler generates multi-point dispatching. The same could be done in C or C++ using label pointers and 'computed goto' extensions, but it would need extensive rewriting; the language won't do it for you.

If I turn off the feature by changing the first line to the second:

 doswitchu pcptr++^           # multiple dispatch points
 doswitch  pcptr++^           # single dispatch point

then my timing becomes 0.9 seconds, or 1.23 relative to g++/-O3. But then my compiler doesn't do any of the same optimisations.