On 2/11/06, Jacob F. [email protected] wrote:
On 2/10/06, Ruby Q. [email protected] wrote:
This week’s Ruby Q. is to write FasterGenerator, your own
re-implementation of Generator with an eye towards working faster.Here’s the benchmark results from my own implementation:
Ok, since last night I’ve corrected my implementation to not evaluate
ahead, as per H. Yamamoto’s and Luke B.'s comments. I had
originally done this, then removed it for time savings. For
correctness (which Luke’s example brought to mind), I’ve reintroduced
it.
I also made the changes to the benchmark that Christoffer Lernö
suggested. Due to the slowness of the current generator (more
specifically, the current generator on my computer) I had to drop the
test constants in order to get it to finish in a reasonable time.
Here are my current benchmark results, with my benchmark code and
current implementation attached:
galadriel:~/ruby/qotw/66$ ruby benchmark.rb
Construction
Rehearsal -------------------------------------------------------------
Old callcc Generator 0.070000 0.140000 0.210000 ( 0.323153)
lukfugl’s FasterGenerator 0.010000 0.000000 0.010000 ( 0.003346)
---------------------------------------------------- total: 0.220000sec
user system total real
Old callcc Generator 0.140000 0.090000 0.230000 ( 0.354175)
lukfugl’s FasterGenerator 0.000000 0.000000 0.000000 ( 0.004274)
next()
Rehearsal -------------------------------------------------------------
Old callcc Generator 300.130000 182.660000 482.790000 (495.950825)
lukfugl’s FasterGenerator 5.550000 0.050000 5.600000 ( 5.751610)
-------------------------------------------------- total: 488.390000sec
user system total real
Old callcc Generator 225.030000 185.010000 410.040000 (425.286992)
lukfugl’s FasterGenerator 5.690000 0.020000 5.710000 (
5.821117)
Jacob F.