Skip to content

Instantly share code, notes, and snippets.

@JoshTGreenwood
Created October 31, 2012 00:34
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 JoshTGreenwood/3984074 to your computer and use it in GitHub Desktop.
Save JoshTGreenwood/3984074 to your computer and use it in GitHub Desktop.
Benchmark strip vs. chomp in ruby
require 'benchmark'
Benchmark.bmbm do |x|
x.report("Stripping /n with String.strip") { 100_000.times {"filename.rb\n".strip} }
x.report("Stripping /n with String.chomp") { 100_000.times {"filename.rb\n".chomp} }
end
Rehearsal ------------------------------------------------------------------
Stripping /n with String.strip 0.040000 0.000000 0.040000 ( 0.035811)
Stripping /n with String.chomp 0.030000 0.000000 0.030000 ( 0.033354)
--------------------------------------------------------- total: 0.070000sec
user system total real
Stripping /n with String.strip 0.040000 0.000000 0.040000 ( 0.035512)
Stripping /n with String.chomp 0.030000 0.000000 0.030000 ( 0.034136)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment