From: Bill Kelly Date: 2005-07-16T08:30:21+09:00 Subject: Re: [QUIZ] Sampling (#39) From: "Mauricio Fern�ndez" > > On Sat, Jul 16, 2005 at 06:30:15AM +0900, Ezra Zygmuntowicz wrote: > > > > On Jul 15, 2005, at 1:27 PM, jason r tibbetts wrote: > > >I /really/ want to know how this is possible. Multi-processor > > >solution? > > > > > Nope This is running on a single 1.6Ghz G5 tower with about 15 other > > programs running including photoshop and dreamweaver. And my solution > > is only 9 lines of code ;-) Here's some more results with a little > > more time shaved off: > > ezra:~/Sites/______raill_stuff ez$ time ./sample.rb 5_000_000 > > 1_000_000_000 > big_sample.txt > > > > real 0m39.860s > > user 0m34.343s > > sys 0m1.370s > > My first take is also 9L long. > > Timed on a 1536.849MHz K7 with only a couple processes awake, out of 150+. > > batsman@tux-chan:/tmp$ time ruby sample.rb 5_000_000 1_000_000_000 > big_sample.txt > > real 0m33.880s > user 0m32.750s > sys 0m0.610s This is on a 2.4GHz Celeron, otherwise idle... The solution is 10L (including two lines for retrieving the command line arguments, which could be one line...) $ time ruby sample.rb 5_000_000 1_000_000_000 > big_sample.txt real 0m34.022s user 0m33.290s sys 0m0.590s $ wc -l big_sample.txt 5000000 big_sample.txt $ head big_sample.txt 5 304 423 627 820 1173 1282 1575 1639 1897 $ tail big_sample.txt 999998156 999998353 999998481 999998737 999998991 999999041 999999367 999999475 999999630 999999996 Removing the puts that outputs each sample, but leaving the rest of the logic, the time is: real 0m11.793s user 0m11.790s sys 0m0.000s Regards, Bill