Last active
March 7, 2016 17:45
-
-
Save workmad3/fb2f6f5b3459858a5e7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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