Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

String management Ruby 1.9.3 version #9

Merged
merged 2 commits into from

2 participants

@rafaellima

Hi,

I'm sending you the file bm_str_chars.rb with a benchmark that show the big difference between the ruby 1.9.3 to the other ones about the management of strings.

@rdp
Collaborator

looks good to me

@rdp rdp merged commit b9d7c8e into acangiano:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 11, 2012
  1. @rafaellima
  2. @rafaellima

    Message about the RVM

    rafaellima authored
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 0 deletions.
  1. +25 −0 benchmarks/micro-benchmarks/bm_str_chars.rb
View
25 benchmarks/micro-benchmarks/bm_str_chars.rb
@@ -0,0 +1,25 @@
+# That ruby code is gonna show you that the Ruby version 1.9.3 manage strings in a different way.
+# If you have one string with 23 or less characteres, it would be a way faster than a string with 24 or more.
+# All the credits to Pat Shaughnessy, http://patshaughnessy.net/2012/1/4/never-create-ruby-strings-longer-than-23-characters
+# DON'T FORGET TO CHANGE THE RUBY VERSION TO 1.9.3 Ex:RVM $ rvm use 1.9.3
+
+require 'benchmark'
+
+ITERATIONS = 2000000
+
+def run(str, bench)
+ bench.report("#{str.length + 1} chars") do
+ ITERATIONS.times do
+ new_string = str + 'x'
+ end
+ end
+end
+
+Benchmark.bm do |bench|
+ run("01234567890123456789", bench)
+ run("012345678901234567890", bench)
+ run("0123456789012345678901", bench)
+ run("01234567890123456789012", bench)
+ run("012345678901234567890123", bench)
+ run("0123456789012345678901234", bench)
+end
Something went wrong with that request. Please try again.