Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Forked from fxn/gist:7572692
Last active December 28, 2015 22:49

Revisions

  1. tenderlove revised this gist Nov 21, 2013. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -22,9 +22,10 @@ def self.x
    end

    __END__
    [aaron@higgins git]$ ruby gistfile1.rb
    [aaron@higgins git]$ ruby -v gistfile1.rb
    ruby 2.1.0dev (2013-11-16 trunk 43688) [x86_64-darwin12.5.0]
    user system total real
    constant 0.890000 0.000000 0.890000 ( 0.892681)
    literal 1.200000 0.000000 1.200000 ( 1.202642)
    frozen 0.520000 0.000000 0.520000 ( 0.516941)
    constant 0.870000 0.000000 0.870000 ( 0.878663)
    literal 1.210000 0.000000 1.210000 ( 1.206898)
    frozen 0.510000 0.000000 0.510000 ( 0.509119)
    [aaron@higgins git]$
  2. tenderlove revised this gist Nov 21, 2013. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -18,10 +18,13 @@ def self.x
    Benchmark.bm do |x|
    x.report("constant") { TIMES.times { ::M::N::A::B.x }}
    x.report("literal") { TIMES.times { '' }}
    x.report("frozen") { TIMES.times { ''.freeze }}
    end

    __END__
    fxn@yeager:~/tmp $ ruby foo.rb
    [aaron@higgins git]$ ruby gistfile1.rb
    user system total real
    constant 0.970000 0.000000 0.970000 ( 0.974618)
    literal 1.170000 0.010000 1.180000 ( 1.173427)
    constant 0.890000 0.000000 0.890000 ( 0.892681)
    literal 1.200000 0.000000 1.200000 ( 1.202642)
    frozen 0.520000 0.000000 0.520000 ( 0.516941)
    [aaron@higgins git]$
  3. @fxn fxn revised this gist Nov 20, 2013. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -18,4 +18,10 @@ def self.x
    Benchmark.bm do |x|
    x.report("constant") { TIMES.times { ::M::N::A::B.x }}
    x.report("literal") { TIMES.times { '' }}
    end
    end

    __END__
    fxn@yeager:~/tmp $ ruby foo.rb
    user system total real
    constant 0.970000 0.000000 0.970000 ( 0.974618)
    literal 1.170000 0.010000 1.180000 ( 1.173427)
  4. @fxn fxn created this gist Nov 20, 2013.
    21 changes: 21 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    require 'benchmark'

    TIMES = 10_000_000

    module M
    X = ''
    module N
    module A
    module B
    def self.x
    X
    end
    end
    end
    end
    end

    Benchmark.bm do |x|
    x.report("constant") { TIMES.times { ::M::N::A::B.x }}
    x.report("literal") { TIMES.times { '' }}
    end