-
-
Save lcowell/3a63edecad51177857ec to your computer and use it in GitHub Desktop.
trailing dot vs. next line dot
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' | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rehearsal ------------------------------------------------
next list 0.110000 0.000000 0.110000 ( 0.111465)
trailing dot 0.110000 0.000000 0.110000 ( 0.109684)
--------------------------------------- total: 0.220000sec
next list 0.110000 0.000000 0.110000 ( 0.111176)
trailing dot 0.110000 0.000000 0.110000 ( 0.107380)