At the risk of side-tracking this thread, for now, while still interested in C, I'm currently using BCPL and I know that those 2 benchmarks aren't that good in BCPL on my '816 system, however the fib() one isn't bad either, so bearing in-mind that my system is an '816 running at 16Mhz, interpreting a 32-bit bytecode VM, all numbers are signed 32-bits and there is overhead to make the 64K pages transparent to user-land the results are:
Code:
% bench
fib result: 28657 - 3.762
tarai result: 10 - 43.852
first number is the result, 2nd the time in seconds to the nearest millisecond. Multiply by 8 to get the effective speed on a 2Mhz system, so fib() comes out at 30 seconds - only ~3 times slower than the LLVM one above which really isn't bad all things considered, and tarai() to 351 seconds. Ah well, can't win 'em all!
(although it may win on code-size at 248 bytes!)
-Gordon
code:
Code:
GET "libhdr.h"
GET "sys.h"
LET fib (n) = VALOF
{
TEST n < 2 THEN
RESULTIS n
ELSE
RESULTIS fib (n - 1) + fib (n - 2)
}
LET tarai (x, y, z) = VALOF
{
TEST x <= y THEN
RESULTIS y
ELSE
RESULTIS tarai (tarai (x - 1, y, z),
tarai (y - 1, z, x),
tarai (z - 1, x, y))
}
AND start () = VALOF
{
LET tStart, tEnd = ?, ?
LET r = ?
tStart := sys (Sys_cputime)
r := fib (23)
tEnd := sys (Sys_cputime)
writef (" fib result: %5d - %6.3d*n", r, tEnd - tStart)
tStart := sys (Sys_cputime)
r := tarai (10, 1, 0)
tEnd := sys (Sys_cputime)
writef ("tarai result: %5d - %6.3d*n", r, tEnd - tStart)
RESULTIS 0
}
_________________
--
Gordon Henderson.
See my
Ruby 6502 and 65816 SBC projects here:
https://projects.drogon.net/ruby/