Skip to content

Instantly share code, notes, and snippets.

@dentedtriangle
Forked from matthewrudy/benchmark.rb
Created March 21, 2012 08:46
Show Gist options
  • Save dentedtriangle/2145656 to your computer and use it in GitHub Desktop.
Save dentedtriangle/2145656 to your computer and use it in GitHub Desktop.
Testing the <23 string issue
require 'benchmark'
ITERATIONS = 1000000
Benchmark.bm(10) do |bench|
0.upto(40) do |n|
bench.report("chars: #{n}") do
string = "n"*n
ITERATIONS.times do
string + 'x'
end
end
end
end
user system total real
chars: 0 0.290000 0.000000 0.290000 ( 0.285873)
chars: 1 0.320000 0.000000 0.320000 ( 0.316728)
chars: 2 0.290000 0.000000 0.290000 ( 0.292130)
chars: 3 0.290000 0.000000 0.290000 ( 0.293374)
chars: 4 0.310000 0.000000 0.310000 ( 0.306900)
chars: 5 0.300000 0.000000 0.300000 ( 0.297575)
chars: 6 0.310000 0.000000 0.310000 ( 0.314241)
chars: 7 0.300000 0.000000 0.300000 ( 0.300243)
chars: 8 0.280000 0.000000 0.280000 ( 0.286060)
chars: 9 0.310000 0.000000 0.310000 ( 0.309694)
chars: 10 0.300000 0.000000 0.300000 ( 0.300977)
chars: 11 0.330000 0.000000 0.330000 ( 0.327538)
chars: 12 0.300000 0.000000 0.300000 ( 0.302438)
chars: 13 0.320000 0.010000 0.330000 ( 0.312763)
chars: 14 0.280000 0.000000 0.280000 ( 0.288715)
chars: 15 0.300000 0.000000 0.300000 ( 0.294411)
chars: 16 0.300000 0.000000 0.300000 ( 0.303953)
chars: 17 0.310000 0.000000 0.310000 ( 0.305969)
chars: 18 0.300000 0.000000 0.300000 ( 0.308357)
chars: 19 0.310000 0.000000 0.310000 ( 0.303445)
chars: 20 0.310000 0.000000 0.310000 ( 0.314546)
chars: 21 0.310000 0.000000 0.310000 ( 0.304749)
chars: 22 0.300000 0.000000 0.300000 ( 0.307125)
chars: 23 0.470000 0.000000 0.470000 ( 0.470054)
chars: 24 0.500000 0.000000 0.500000 ( 0.501440)
chars: 25 0.530000 0.000000 0.530000 ( 0.524160)
chars: 26 0.510000 0.000000 0.510000 ( 0.512369)
chars: 27 0.490000 0.000000 0.490000 ( 0.495345)
chars: 28 0.490000 0.000000 0.490000 ( 0.489927)
chars: 29 0.520000 0.000000 0.520000 ( 0.522215)
chars: 30 0.500000 0.000000 0.500000 ( 0.501139)
chars: 31 0.490000 0.010000 0.500000 ( 0.491002)
chars: 32 0.500000 0.000000 0.500000 ( 0.497039)
chars: 33 0.520000 0.000000 0.520000 ( 0.522955)
chars: 34 0.490000 0.000000 0.490000 ( 0.485230)
chars: 35 0.480000 0.000000 0.480000 ( 0.482624)
chars: 36 0.480000 0.000000 0.480000 ( 0.477754)
chars: 37 0.510000 0.000000 0.510000 ( 0.514367)
chars: 38 0.500000 0.000000 0.500000 ( 0.506686)
chars: 39 0.570000 0.000000 0.570000 ( 0.572416)
chars: 40 0.560000 0.000000 0.560000 ( 0.563307)
user system total real
chars: 0 0.370000 0.000000 0.370000 ( 0.366730)
chars: 1 0.380000 0.000000 0.380000 ( 0.382128)
chars: 2 0.390000 0.000000 0.390000 ( 0.387196)
chars: 3 0.370000 0.000000 0.370000 ( 0.374867)
chars: 4 0.370000 0.000000 0.370000 ( 0.370998)
chars: 5 0.370000 0.000000 0.370000 ( 0.366505)
chars: 6 0.360000 0.000000 0.360000 ( 0.364901)
chars: 7 0.380000 0.000000 0.380000 ( 0.376964)
chars: 8 0.360000 0.000000 0.360000 ( 0.361423)
chars: 9 0.360000 0.000000 0.360000 ( 0.362585)
chars: 10 0.370000 0.000000 0.370000 ( 0.364726)
chars: 11 0.370000 0.000000 0.370000 ( 0.365690)
chars: 12 0.370000 0.000000 0.370000 ( 0.374387)
chars: 13 0.360000 0.000000 0.360000 ( 0.362398)
chars: 14 0.370000 0.000000 0.370000 ( 0.365708)
chars: 15 0.360000 0.000000 0.360000 ( 0.365309)
chars: 16 0.370000 0.000000 0.370000 ( 0.364021)
chars: 17 0.360000 0.000000 0.360000 ( 0.366792)
chars: 18 0.370000 0.000000 0.370000 ( 0.369290)
chars: 19 0.370000 0.000000 0.370000 ( 0.370876)
chars: 20 0.380000 0.000000 0.380000 ( 0.375445)
chars: 21 0.380000 0.000000 0.380000 ( 0.379652)
chars: 22 0.380000 0.000000 0.380000 ( 0.382292)
chars: 23 0.570000 0.000000 0.570000 ( 0.563633)
chars: 24 0.550000 0.000000 0.550000 ( 0.552596)
chars: 25 0.540000 0.000000 0.540000 ( 0.545093)
chars: 26 0.560000 0.000000 0.560000 ( 0.560197)
chars: 27 0.590000 0.000000 0.590000 ( 0.591256)
chars: 28 0.580000 0.000000 0.580000 ( 0.572981)
chars: 29 0.580000 0.000000 0.580000 ( 0.580868)
chars: 30 0.570000 0.000000 0.570000 ( 0.570096)
chars: 31 0.560000 0.000000 0.560000 ( 0.560095)
chars: 32 0.540000 0.000000 0.540000 ( 0.547976)
chars: 33 0.550000 0.000000 0.550000 ( 0.548256)
chars: 34 0.560000 0.010000 0.570000 ( 0.556874)
chars: 35 0.570000 0.000000 0.570000 ( 0.575082)
chars: 36 0.560000 0.000000 0.560000 ( 0.560576)
chars: 37 0.560000 0.000000 0.560000 ( 0.558877)
chars: 38 0.560000 0.000000 0.560000 ( 0.562131)
chars: 39 0.580000 0.000000 0.580000 ( 0.581959)
chars: 40 0.580000 0.000000 0.580000 ( 0.575950)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment