Created
August 3, 2012 20:45
-
-
Save havenwood/3251347 to your computer and use it in GitHub Desktop.
Shaughnessy String Creation Benchmarks Across VMs
This file contains 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
#!/usr/bin/env ruby | |
require 'benchmark' | |
def run str, bench | |
bench.report "#{str.length + 1} chars" do | |
1_000_000.times do | |
new_string = str + 'x' | |
end | |
end | |
end | |
Benchmark.bm do |bench| | |
run '12345678901234567890', bench | |
run '123456789012345678901', bench | |
run '1234567890123456789012', bench | |
run '12345678901234567890123', bench | |
run '123456789012345678901234', bench | |
run '1234567890123456789012345', bench | |
end | |
#=> | |
=begin | |
Ruby 1.9.3-p194 | |
user system total real | |
21 chars 0.200000 0.000000 0.200000 ( 0.201233) | |
22 chars 0.200000 0.000000 0.200000 ( 0.201134) | |
23 chars 0.200000 0.000000 0.200000 ( 0.201519) | |
24 chars 0.350000 0.000000 0.350000 ( 0.346913) | |
25 chars 0.340000 0.000000 0.340000 ( 0.341198) | |
26 chars 0.340000 0.000000 0.340000 ( 0.343886) | |
Jruby 1.7.0-preview1 | |
user system total real | |
21 chars 0.480000 0.020000 0.500000 ( 0.238000) | |
22 chars 0.150000 0.010000 0.160000 ( 0.108000) | |
23 chars 0.110000 0.000000 0.110000 ( 0.103000) | |
24 chars 0.110000 0.010000 0.120000 ( 0.109000) | |
25 chars 0.110000 0.010000 0.120000 ( 0.104000) | |
26 chars 0.100000 0.010000 0.110000 ( 0.103000) | |
RBX 2.0.0-testing | |
user system total real | |
21 chars 1.868204 0.003903 1.872107 ( 1.715648) | |
22 chars 1.614931 0.000488 1.615419 ( 1.609778) | |
23 chars 1.494799 0.000220 1.495019 ( 1.494987) | |
24 chars 1.543366 0.000240 1.543606 ( 1.543594) | |
25 chars 1.498119 0.000201 1.498320 ( 1.498287) | |
26 chars 1.497441 0.000201 1.497642 ( 1.497627) | |
Maglev 1.0.0 | |
user system total real | |
21 chars 0.110000 0.000000 0.110000 ( 0.111422) | |
22 chars 0.110000 0.000000 0.110000 ( 0.110823) | |
23 chars 0.110000 0.000000 0.110000 ( 0.111872) | |
24 chars 0.110000 0.000000 0.110000 ( 0.112523) | |
25 chars 0.120000 0.000000 0.120000 ( 0.111724) | |
26 chars 0.110000 0.000000 0.110000 ( 0.113601) | |
MacRuby 0.12 | |
user system total real | |
21 chars 1.650000 0.040000 1.690000 ( 1.331783) | |
22 chars 1.660000 0.040000 1.700000 ( 1.349648) | |
23 chars 1.690000 0.040000 1.730000 ( 1.380626) | |
24 chars 1.790000 0.040000 1.830000 ( 1.482177) | |
25 chars 1.920000 0.050000 1.970000 ( 1.594381) | |
26 chars 1.930000 0.040000 1.970000 ( 1.618617) | |
http://patshaughnessy.net/2012/1/4/never-create-ruby-strings-longer-than-23-characters | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment