> Sure. I'll post it now to the list. Note that purpose
> is not to write the tightest loop in each language, but
> to write the code the most similar to generic do loop in
> other Lisp dialects. For example, Newlisp has following
> primitive designed for benchmarks.
> (time <some-code> <number-of-times-to-be-repeated>)
> It allows significant speed up in interpreted language,
> however, I didn't used it because I thought it would
> be unfair to take advantage of the clever primitives in
> a benchmark intended to measure the speed of eval.
OK, I understand that point. As you try to keep as close as possible to
the other solutions, I think you code is all right, and not much to
PicoLisp, BTW, has also a similar benchmarking function, called 'bench'.
It does no repetitions by itself, though, and the above would be
<some-code> ) )
Concerning the benchmarks itself, however, I'm afraid it measures
integer arithmetics rather than the overhead of 'eval'. Also, the
variable 'i' is not needed in the loops, as 'do' already does the
necessary counting. In addition, we could do some small changes by
replacing the 'setq's and '+' with 'zero' and 'inc' (no significant
effect on the runtime).
If we did all these changes (of course keeping in mind that this would
not be fair to the other implementations), we would get
(inc 'X) ) )
(inc 'X) ) ) )
'(prog (zero X) (inc 'X)) ) ) )
(prog (zero X) (inc 'X)) ) )
With that, the speed is more than doubled. Timings on my notebook:
0.248842 -> 0.125 sec
0.143861 -> 0.020 sec
0.305421 -> 0.146 sec
0.293531 -> 0.121 sec
Note the second result. It is even seven times faster. This is because
the body of the loop is just a call to 'quote', which is the fastest
function of all. In this case, the overhead caused by incrementing and
testing 'i' is clearly seen.