--005045013ed9892622048b9ba174
Content-Type: text/plain; charset=ISO-8859-1

I've done this using the existing test of Queue, modifying it a little
bit (see attached file for the code):

panaggio@phoenix:/tmp$ ./c-queue/bin/ruby queue_benchmark.rb
     user     system      total        real
100  0.270000   0.030000   0.300000 (  0.393703)
1000  3.270000   0.160000   3.430000 (  3.987008)
10000 32.890000   1.910000  34.800000 ( 39.984390)
panaggio@phoenix:/tmp$ ./ruby-queue/bin/ruby queue_benchmark.rb
     user     system      total        real
100  1.280000   0.110000   1.390000 (  1.652816)
1000 13.370000   0.700000  14.070000 ( 16.071673)
10000129.410000   7.680000 137.090000 (160.303117)
panaggio@phoenix:/tmp$

My implementation is almost 4 times faster than the existing one.
Maybe it's enough, maybe it's not. Let me know if it isn't, so that I
can make any extra tuning, if needed.

Just to get it clear: c-queue was generated from queue's branch code
and ruby-queue was generated from trunk's code, both from my fork.

The times on any other machine may be much lower, as my notebook is really old.

>> It is not (for me at least), if you call the "top" Ruby api (which is
>> directly (or almost) bound to Ruby methods (eg: rb_ary_new()), the
>> gain is insignificant. (I imagine you only bypass parsing the Ruby
>> code)
>
> Replacing ruby's dynamic method dispatch with c function calls should
> make a pretty big difference. Executing native instructions instead of
> bytecodes should also help, tho less so I would think.

This little benchmark just shows what Caleb said. By implementing it
in C already, it get measurably faster.

--005045013ed9892622048b9ba174
Content-Type: application/x-ruby; name="queue_benchmark.rb"
Content-Disposition: attachment; filename="queue_benchmark.rb"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_gbqxo8b70

cmVxdWlyZSAiYmVuY2htYXJrIgpyZXF1aXJlICJ0aHJlYWQiCgogIGRlZiBncmluZChudW1fdGhy
ZWFkcywgbnVtX29iamVjdHMsIG51bV9pdGVyYXRpb25zLCBrbGFzcywgKmFyZ3MpCiAgICBmcm9t
X3dvcmtlcnMgPSBrbGFzcy5uZXcoKmFyZ3MpCiAgICB0b193b3JrZXJzID0ga2xhc3MubmV3KCph
cmdzKQoKICAgIHdvcmtlcnMgPSAoMS4ubnVtX3RocmVhZHMpLm1hcCB7CiAgICAgIFRocmVhZC5u
ZXcgewogICAgICAgIHdoaWxlIG9iamVjdCA9IHRvX3dvcmtlcnMucG9wCiAgICAgICAgICBmcm9t
X3dvcmtlcnMucHVzaCBvYmplY3QKICAgICAgICBlbmQKICAgICAgfQogICAgfQoKICAgIFRocmVh
ZC5uZXcgewogICAgICBudW1faXRlcmF0aW9ucy50aW1lcyB7CiAgICAgICAgbnVtX29iamVjdHMu
dGltZXMgeyB0b193b3JrZXJzLnB1c2ggOTkgfQogICAgICAgIG51bV9vYmplY3RzLnRpbWVzIHsg
ZnJvbV93b3JrZXJzLnBvcCB9CiAgICAgIH0KICAgIH0uam9pbgogIAogICAgbnVtX3RocmVhZHMu
dGltZXMgeyB0b193b3JrZXJzLnB1c2ggbmlsIH0KICAgIHdvcmtlcnMuZWFjaCB7IHx0fCB0Lmpv
aW4gfQogIGVuZAoKbnVtX3RocmVhZHMgPSA1Cm51bV9vYmplY3RzID0gMTAwMApudW1faXRlcmF0
aW9ucyA9IFsxMDAsMTAwMCwxMDAwMF0Ka2xhc3MgPSBRdWV1ZQoKQmVuY2htYXJrLmJtIGRvIHx4
fAogIG51bV9pdGVyYXRpb25zLmVhY2ggZG8gfG51bV9pdGVyfAogICAgeC5yZXBvcnQobnVtX2l0
ZXIudG9fcyl7Z3JpbmQobnVtX3RocmVhZHMsIG51bV9vYmplY3RzLCBudW1faXRlciwga2xhc3Mp
fQogIGVuZAplbmQK
--005045013ed9892622048b9ba174--