From: Joost Diepenmaat Date: 2005-07-16T13:05:48+09:00 Subject: Re: [QUIZ] Sampling (#39) On Sat, Jul 16, 2005 at 12:41:23PM +0900, Joost Diepenmaat wrote: > On Sat, Jul 16, 2005 at 11:51:27AM +0900, James Edward Gray II wrote: > > On Jul 15, 2005, at 11:38 AM, jason r tibbetts wrote: > > > > >James, > > > > > >What are your machine's specs, just for comparison's sake? I don't > > >want to get too discouraged by my 5+ year-old Sun beater > > >workstation. :) > > > > Dual 2.0 Ghx G5. 2 Gigs of RAM. > > > > >I've also found that the printing of the results (in the form of an > > >array) is taking several minutes in and of itself. Since optimizing > > >the printout probably isn't the point of the quiz, can anyone > > >recommend something faster than arr.each{ | elem | p elem } > > > > IO is certainty a part of this quiz. The benchmark library is your > > friend... ;) > > One of the interesting findings for me was that > > puts array_of_strings > > is *very* much faster than > > puts array_of_integers > > Joost. And by the way: > time ./sample2 5_000_000 1_000_000_000 >big.txt real 2m5.395s user 1m39.892s sys 0m11.576s > head big.txt 141 441 854 876 968 1123 1276 1317 1557 1587 > tail big.txt 999998078 999998164 999998558 999998626 999998650 999998814 999998912 999999127 999999160 999999385 Slightly more than 2 minutes wallclock time. That means it's just fast enough to keep me from getting bored and killing the process :-) I managed to shave off about 8 minutes run time by trying a couple of different strategies with the IO and int -> string conversions. The "sample algorithm" itself is the second-dumbest I could think of - very easy to prove correct, though :-) system info: Single Intel(R) Celeron(R) CPU 2.40GHz w / 1GB of memory running Linux 2.6.11 Joost.