Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created March 7, 2016 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save workmad3/0d27fb0b38c507bb4299 to your computer and use it in GitHub Desktop.
Save workmad3/0d27fb0b38c507bb4299 to your computer and use it in GitHub Desktop.
require 'benchmark'
p ["Encodings: ", Encoding.default_external, Encoding.default_internal]
strings = {
10 => " " * 10,
100 => " " * 100,
1000 => " " * 1000,
10_000 => " " * 10_000,
100_000 => " " * 100_000,
1_000_000 => " " * 1_000_000
}
reps = 1000
Benchmark.bm do |x|
strings.each do |length, string|
x.report("Length: #{length}") do
reps.times do
(-10..-1).each do |i|
string[i] = "x"
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment