Thanks to visit codestin.com
Credit goes to gist.github.com

Skip to content

Instantly share code, notes, and snippets.

@lcowell

lcowell/chain.rb Secret

Created May 30, 2013 02:16
Show Gist options
  • Select an option

  • Save lcowell/3a63edecad51177857ec to your computer and use it in GitHub Desktop.

Select an option

Save lcowell/3a63edecad51177857ec to your computer and use it in GitHub Desktop.

Revisions

  1. lcowell created this gist May 30, 2013.
    31 changes: 31 additions & 0 deletions chain.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    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