Sean Russell wrote:
> I was playing around with the SyncEnumerator from Ruby 1.8, and
> noticed that it was taking a long time to iterate over elements.
...
> Is there any reason why I shouldn't submit this as an RCR to replace
> SyncEnumerator?I wonder how an implementation using .zip with a block would compare? Or
would that not do the same thing?
#zip ends up being slower in construction (because we have to find the largest
array) and faster in iteration. It is also more elegant, and it is now my
preferred version.
139 % ruby synctest.rb
~/Work/Sync
Construction
SyncEnumerator1: 0.041632
SyncEnumerator2: 0.138032
Starting SyncEnumerator1
................................................................................................................................................................
26 shold be 26 :: Time: 0.132563
Starting SyncEnumerator2
................................................................................................................................................................
26 shold be 26 :: Time: 0.041874
Here's the test including the original SyncEnumerator; I had to scale down the
repetitions because the original is about three orders of magnitude slower
than either of the new versions:
152 % ruby synctest.rb
~/Work/Sync
Construction
SyncEnumerator: 0.245202
SyncEnumerator1: 0.000343
SyncEnumerator2: 0.001459
Starting SyncEnumerator
................................................................................
26 shold be 26 :: Time: 15.135305
Starting SyncEnumerator1
................................................................................
26 shold be 26 :: Time: 0.025891
Starting SyncEnumerator2
................................................................................
26 shold be 26 :: Time: 0.017458
I'm attaching the sources.
* mysync.rb defines SyncEnumerator1 and SyncEnumerator2; #2 is implemented
with #zip, and is the version I'm proposing replace the original
SyncEnumerator.
* mysynctest.rb contains unit tests for both version #1 and #2
* benchmark.rb contains the benchmarks above.
benchmark.rb (729 Bytes)
mysynctest.rb (1.45 KB)
mysync.rb (1.32 KB)
ยทยทยท
On Thursday 04 November 2004 07:28, Florian Gross wrote:
--
### SER
### Deutsch|Esperanto|Francaise|Linux|XML|Java|Ruby|Aikido
### http://www.germane-software.com/~ser jabber.com:ser ICQ:83578737
### GPG: http://www.germane-software.com/~ser/Security/ser_public.gpg