Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@workmad3
Last active March 7, 2016 17:45
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/fb2f6f5b3459858a5e7f to your computer and use it in GitHub Desktop.
Save workmad3/fb2f6f5b3459858a5e7f to your computer and use it in GitHub Desktop.
user system total real
Length: 10, encoding: US-ASCII 0.000000 0.000000 0.000000 ( 0.002861)
Length: 100, encoding: US-ASCII 0.010000 0.000000 0.010000 ( 0.003694)
Length: 1000, encoding: US-ASCII 0.000000 0.000000 0.000000 ( 0.003162)
Length: 10000, encoding: US-ASCII 0.000000 0.000000 0.000000 ( 0.003325)
Length: 100000, encoding: US-ASCII 0.010000 0.000000 0.010000 ( 0.003654)
Length: 1000000, encoding: US-ASCII 0.000000 0.000000 0.000000 ( 0.004246)
Length: 10000000, encoding: US-ASCII 0.010000 0.010000 0.020000 ( 0.010525)
user system total real
Length: 10, encoding: US-ASCII 0.010000 0.000000 0.010000 ( 0.003674)
Length: 100, encoding: US-ASCII 0.000000 0.000000 0.000000 ( 0.003118)
Length: 1000, encoding: US-ASCII 0.010000 0.000000 0.010000 ( 0.003761)
Length: 10000, encoding: US-ASCII 0.010000 0.000000 0.010000 ( 0.011070)
Length: 100000, encoding: US-ASCII 0.060000 0.000000 0.060000 ( 0.062892)
Length: 1000000, encoding: US-ASCII 0.710000 0.010000 0.720000 ( 0.735236)
Length: 10000000, encoding: US-ASCII 7.660000 0.050000 7.710000 ( 7.824110)
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,
10_000_000 => " " * 10_000_000
}
strings.each {|k,v| strings[k] = v.encode "ASCII" }
reps = 1000
Benchmark.bm do |x|
strings.each do |length, string|
x.report("Length: #{length}, encoding: #{string.encoding}") 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