Created
August 25, 2015 14:19
-
-
Save k-tsj/3992cdea44bcfbe253bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby -v -rstringio -rbenchmark -e 'N=1_000_000;Benchmark.bm(5){|x| x.report("String#<<"){s="";N.times{s<<"a"}}; x.report("Array#<<+join"){a=[];N.times{a<<"a"};a.join}; x.report("StringIO#<<"){i=StringIO.new;N.times{i<<"a"};i.to_s}};' | |
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux] | |
user system total real | |
String#<< 0.150000 0.000000 0.150000 ( 0.149649) | |
Array#<<+join 0.200000 0.030000 0.230000 ( 0.231170) | |
StringIO#<< 0.250000 0.010000 0.260000 ( 0.255604) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment