From: Zach Dennis Date: 2005-10-18T08:58:31+09:00 Subject: Re: How to get non-unique elements from an array? Ryan Leavengood wrote: > On 10/17/05, Ryan Leavengood wrote: > >>The results: >> >>Small array, lots of iterations: >> user system total real >>markvh 0.391000 0.000000 0.391000 ( 0.391000) >>martin 0.390000 0.000000 0.390000 ( 0.484000) >> >>Big array, one iteration: >> user system total real >>markvh 0.015000 0.000000 0.015000 ( 0.016000) >>martin 0.000000 0.000000 0.000000 ( 0.000000) >> >>Overall Martin's was the best. As he suspected, David's was quite >>slow. Sam's as well. > > > On second thought, Mark's may have been the best overall. Either way, > both Mark's and Martin's are good algorithms. Many of the others were > good as well. > Mine isn't the shortest, but it's the fastest I've seen thus far! Twice as fast as the next closest! Why does everyone leave me out of benchmark, ;) ---my code t=[]; a.delete_if{ |e| r=(not t.include? e); t.push(e); r } ---end my code > "c:\ruby\bin\ruby.exe" find_non-uniques.rb -d user system total real delete 0.218000 0.000000 0.218000 ( 0.218000) <---- MINE!!! index 0.500000 0.000000 0.500000 ( 0.547000) grep 0.500000 0.000000 0.500000 ( 0.516000) scan 1.078000 0.000000 1.078000 ( 1.172000) inject 0.656000 0.000000 0.656000 ( 0.672000) gsub 1.250000 0.000000 1.250000 ( 1.250000) include 0.672000 0.000000 0.672000 ( 0.687000) Zach