score@kirisame ~/src/brainfucc % time stdbuf -o0 ./brainfucc-orig ../brainfuck-interpreter/toys/Golden.b
1.618033988749894848204586834365638117stdbuf -o0 ./brainfucc-orig ../brainfuck-interpreter/toys/Golden.b 13.45s user 4.84s system 99% cpu 18.287 total
score@kirisame ~/src/brainfucc % time stdbuf -o0 ./brainfucc ../brainfuck-interpreter/toys/Golden.b
1.618033988749894848204586834365638117stdbuf -o0 ./brainfucc ../brainfuck-interpreter/toys/Golden.b 0.72s user 0.00s system 99% cpu 0.728 total
That's a 25x speedup :^)
mmap probably doesn't work on Windows systems though, so you'll probably just want to buffer the whole file into memory. You'll likely get an identical speedup.
BTW, notice how long the original interpreter spends in "system" - that's 4.84 seconds spent on file seeking and re-reading alone.
I poked around with the code and replaced the stdio file calls with mmap.
Tested on this file: https://github.com/rdebath/Brainfuck/blob/master/testing/Golden.b
That's a 25x speedup :^)
mmap
probably doesn't work on Windows systems though, so you'll probably just want to buffer the whole file into memory. You'll likely get an identical speedup.BTW, notice how long the original interpreter spends in "system" - that's 4.84 seconds spent on file seeking and re-reading alone.
I leave the rest to you!