From: Matt Mower Date: 2005-04-30T22:43:50+09:00 Subject: Re: Performance of SyncEnumerator As if often the case, pressing send made me think "why don't i just find out?" On 4/30/05, Matt Mower wrote: > > The profiler shows the bad boys are: > > % cumulative self self total > time seconds seconds calls ms/call ms/call name > 33.99 9.92 9.92 37772 0.26 0.26 Kernel.callcc > 12.69 13.62 3.70 6118 0.61 9.94 Generator#next > 10.91 16.81 3.18 12768 0.25 4.79 Generator#end? > 9.97 19.72 2.91 6118 0.48 1.67 Generator#yield > 8.68 22.25 2.53 3345 0.76 16.39 Array#map > 6.84 24.24 2.00 266 7.50 200.63 Proc#call > Re-implementing as: def euclidean_distance2( vector ) sum = 0 each_with_index { |value,index| sum += ( ( value - vector[index] ) ** 2 ) } Math.sqrt( sum ) end results in a profile of: % cumulative self self total time seconds seconds calls ms/call ms/call name 40.16 1.59 1.59 300 5.31 23.34 Array#each 10.68 2.02 0.42 1978 0.21 0.33 Fixnum#** 5.95 2.25 0.24 2165 0.11 0.14 ART::Cluster#size 4.76 2.44 0.19 4143 0.05 0.05 Fixnum#+ 4.71 2.63 0.19 3245 0.06 0.06 Array#[] 3.12 2.75 0.12 1978 0.06 0.06 Fixnum#>= 2.77 2.86 0.11 1978 0.06 0.06 Fixnum#power! Total run-time is reduced from 29.19s to 3.97s (86% reduction). I guess the moral of this story (for me) is that SyncEnumerator is neat but shouldn't be used where performance is important. Regards, Matt -- Matt Mower :: http://matt.blogs.it/