Created
March 12, 2013 18:29
-
-
Save madwork/5145526 to your computer and use it in GitHub Desktop.
String prepend FTW
This file contains 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' | |
require 'benchmark/ips' | |
Benchmark.ips do |x| | |
x.report("String::prepend") { "foo".prepend "tmp/" } | |
x.report("File.join") { File.join "tmp", "foo" } | |
end | |
puts | |
Benchmark.bm do |x| | |
x.report("String::prepend") { 1000000.times{"foo".prepend "tmp/"} } | |
x.report("File.join") { 1000000.times{File.join "tmp", "foo"} } | |
end |
This file contains 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
Calculating ------------------------------------- | |
String::prepend 86847 i/100ms | |
File.join 57009 i/100ms | |
------------------------------------------------- | |
String::prepend 2287790.4 (±7.2%) i/s - 11376957 in 5.005150s | |
File.join 1189393.1 (±3.0%) i/s - 5985945 in 5.037805s | |
user system total real | |
String::prepend 0.350000 0.000000 0.350000 ( 0.352643) | |
File.join 0.760000 0.000000 0.760000 ( 0.759962) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment