From: Douglas Seifert Date: 2011-11-28T02:51:32+09:00 Subject: Re: Is high-speed sorting impossible with Ruby? --f46d0447a121486a4904b2bb0930 Content-Type: text/plain; charset=ISO-8859-1 I've thrown various solutions up on github here: https://github.com/seifertd/sort-a-million Feel free to fork and add more. Below is the result of running all the solutions I have up there so far. My takeaway from all of this: stick with normal Ruby idioms (see the standard_ruby.rb solution) and you will get pretty close. The rest of the solutions are just optimizing for the specific problem and doing this kind of thing is only necessary when you really need the seconds. Also, compiled languages beat interpreted languages, but we all knew that, didn't we? We don't use Ruby for its performance after all. $ ./run_all.sh Generating input file time ruby count_occurences.rb < million.txt > million_sorted.txt real 0m1.242s user 0m1.148s sys 0m0.088s time ruby chunked_reads.rb < million.txt > million_sorted_2.txt real 0m3.484s user 0m2.703s sys 0m0.779s time ruby standard_ruby.rb < million.txt > million_sorted_3.txt real 0m1.260s user 0m1.156s sys 0m0.101s time ruby build_strings.rb < million.txt > million_sorted_4.txt real 0m4.431s user 0m3.834s sys 0m0.567s time ruby build_strings_2.rb < million.txt > million_sorted_5.txt real 0m1.135s user 0m1.039s sys 0m0.091s time sed -n "2,$p" million.txt | sort -n > million_bash.txt real 0m1.968s user 0m1.862s sys 0m0.094s CONFIRM --f46d0447a121486a4904b2bb0930--