Skip to content

Instantly share code, notes, and snippets.

@matthewrudy
Created March 21, 2012 08:41
Show Gist options
  • Save matthewrudy/2145644 to your computer and use it in GitHub Desktop.
Save matthewrudy/2145644 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.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