Skip to content

Instantly share code, notes, and snippets.

@lcowell

lcowell/chain.rb Secret

Created May 30, 2013 02:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lcowell/3a63edecad51177857ec to your computer and use it in GitHub Desktop.
Save lcowell/3a63edecad51177857ec to your computer and use it in GitHub Desktop.
trailing dot vs. next line dot
require 'benchmark'
class Chainer
def punt
self
end
end
def trailer
eval(trailer_code)
end
def trailer_code
1000.times.inject("@chainer") {|code, _| code << ".\npunt"}
end
def next_line
eval(next_line_code)
end
def next_line_code
1000.times.inject("@chainer") {|code, _| code << "\n.punt"}
end
count = 10000
@chainer = Chainer.new
Benchmark.bmbm do |x|
x.report("next list") { 100.times { next_line } }
x.report("trailing dot") { 100.times { trailer } }
end
@lcowell
Copy link
Author

lcowell commented May 30, 2013

Rehearsal ------------------------------------------------
next list 0.110000 0.000000 0.110000 ( 0.111465)
trailing dot 0.110000 0.000000 0.110000 ( 0.109684)
--------------------------------------- total: 0.220000sec

               user     system      total        real

next list 0.110000 0.000000 0.110000 ( 0.111176)
trailing dot 0.110000 0.000000 0.110000 ( 0.107380)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment