------art_10969_18553347.1139764193888
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On 2/11/06, Jacob Fugal <lukfugl / gmail.com> wrote:
> On 2/10/06, Ruby Quiz <james / grayproductions.net> wrote:
> > This week's Ruby Quiz 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 Blanshard'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 Lernsuggested. 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 Fugal

------art_10969_18553347.1139764193888
Content-Type: application/x-ruby; name="faster_generator.rb"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="faster_generator.rb"
X-Attachment-Id: f_ejlm5brj

cmVxdWlyZSAndGhyZWFkJwoKY2xhc3MgRmFzdGVyR2VuZXJhdG9yCiAgZGVmIGluaXRpYWxpemUo
IGVudW09bmlsLC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5jaHJvbml6ZXsgQGRvbmUgPSB0cnVl
IH0KICAgIH0KICAgIEB0aHJlYWQucnVuIGlmIEB0aHJlYWQuc3RhdHVzIGFuZCBuZWVkX3ZhbHVl
PwogICAgVGhyZWFkLnBhc3Mgd2hpbGUgbmVlZF92YWx1ZT8KICBlbmQKCiAgZGVmIG5lZWRfdmFs
dWU/CiAgICBAbXV0ZXguc3luY2hyb25pemV7IG5vdCBAcG9zaXRpb24gPCBAdmFsdWVzLnNpemUg
YW5kIG5vdCBAZG9uZSB9CiAgZW5kCgogIGRlZiBlb2Y/CiAgICBAbXV0ZXguc3luY2hyb25pemV7
IG5vdCBAcG9zaXRpb24gPCBAdmFsdWVzLnNpemUgYW5kIEBkb25lIH0KICBlbmQKZW5kCg------art_10969_18553347.1139764193888
Content-Type: application/x-ruby; name="benchmark.rb"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="benchmark.rb"
X-Attachment-Id: f_ejlm5yh2

cmVxdWlyZSAiYmVuY2htYXJrIgpyZXF1aXJlICJjYWxsY2NfZ2VuZXJhdG9yIgpyZXF1aXJlICJm
YXN0ZXJfZ2VuZXJhdG9yIgoKdGVzdHMgPSAxMDAKZW51bSAgPSAoMS4uMTAwMCkudG9fYQoKcHV0
cwpwdXRzICIjIyMgQ29uc3RydWN0aW9uICMjIyIKcHV0cwoKQmVuY2htYXJrLmJtYm0gZG8gfHh8
CiAgeC5yZXBvcnQoIk9sZCBjYWxsY2MgR2VuZXJhdG9yIikgZG8KICAgIHRlc3RzLnRpbWVzIHsg
Q2FsbENDR2VuZXJhdG9yLm5ldyhlbnVtKSB9CiAgZW5kCiAgeC5yZXBvcnQoImx1a2Z1Z2wncyBG
YXN0ZXJHZW5lcmF0b3IiKSBkbwogICAgdGVzdHMudGltZXMgeyBGYXN0ZXJHZW5lcmF0b3IubmV3
KGVudW0pIH0KICBlbmQKZW5kCgpwdXRzCnB1dHMgIiMjIyBuZXh0KCkgIyMjIgpwdXRzCgpCZW5j
aG1hc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