Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: SyncEnumerator
SER
11/9/2004 1:06:00 PM
On Thursday 04 November 2004 07:28, Florian Gross wrote:
> 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.
--
### SER
### Deutsch|Esperanto|Francaise|Linux|XML|Java|Ruby|Aikido
###
http://www.germane-softwar...
jabber.com:ser ICQ:83578737
### GPG:
http://www.germane-softwar...
/Security/ser_public.gpg
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: SyncEnumerator
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password