Skip to content

Instantly share code, notes, and snippets.

@jacobdam
Forked from JoshTGreenwood/bench.rb
Last active April 8, 2016 05:07

Revisions

  1. jacobdam revised this gist Apr 8, 2016. 1 changed file with 56 additions and 10 deletions.
    66 changes: 56 additions & 10 deletions results.txt
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,59 @@
    ruby bench.rb
    $rvm use 2.0.0 exec ruby bench.rb

    Rehearsal -------------------------------------------------------------
    Break 0.270000 0.000000 0.270000 ( 0.269271)
    Catch/Throw 0.360000 0.000000 0.360000 ( 0.366416)
    Raise/Rescue 1.260000 0.060000 1.320000 ( 1.310333)
    Raise/Rescue no backtrace 0.880000 0.000000 0.880000 ( 0.890402)
    ---------------------------------------------------- total: 2.830000sec

    user system total real
    Break 0.260000 0.000000 0.260000 ( 0.261591)
    Catch/Throw 0.360000 0.000000 0.360000 ( 0.365446)
    Raise/Rescue 1.210000 0.040000 1.250000 ( 1.245223)
    Raise/Rescue no backtrace 0.890000 0.000000 0.890000 ( 0.892867)

    $rvm use 2.1.8 exec ruby bench.rb

    Rehearsal -------------------------------------------------------------
    Break 0.260000 0.000000 0.260000 ( 0.266685)
    Catch/Throw 0.370000 0.000000 0.370000 ( 0.374992)
    Raise/Rescue 1.550000 0.030000 1.580000 ( 1.580658)
    Raise/Rescue no backtrace 1.000000 0.010000 1.010000 ( 1.001632)
    ---------------------------------------------------- total: 3.220000sec

    user system total real
    Break 0.260000 0.000000 0.260000 ( 0.262560)
    Catch/Throw 0.380000 0.000000 0.380000 ( 0.376881)
    Raise/Rescue 1.500000 0.020000 1.520000 ( 1.528191)
    Raise/Rescue no backtrace 0.990000 0.000000 0.990000 ( 0.986605)

    $rvm use 2.2.4 exec ruby bench.rb

    Rehearsal -------------------------------------------------------------
    Break 0.260000 0.000000 0.260000 ( 0.265079)
    Catch/Throw 0.370000 0.000000 0.370000 ( 0.370250)
    Raise/Rescue 1.390000 0.030000 1.420000 ( 1.421014)
    Raise/Rescue no backtrace 0.940000 0.000000 0.940000 ( 0.946083)
    ---------------------------------------------------- total: 2.990000sec

    user system total real
    Break 0.270000 0.000000 0.270000 ( 0.268345)
    Catch/Throw 0.370000 0.000000 0.370000 ( 0.370582)
    Raise/Rescue 1.350000 0.020000 1.370000 ( 1.372187)
    Raise/Rescue no backtrace 0.940000 0.010000 0.950000 ( 0.936232)

    $rvm use 2.3.0 exec ruby bench.rb

    Rehearsal -------------------------------------------------------------
    Break 0.000000 0.000000 0.000000 ( 0.000010)
    Catch/Throw 0.530000 0.220000 0.750000 ( 0.748960)
    Raise/Rescue 7.680000 0.450000 8.130000 ( 8.120991)
    Raise/Rescue no backtrace 1.490000 0.260000 1.750000 ( 1.757660)
    --------------------------------------------------- total: 10.630000sec
    Break 0.240000 0.000000 0.240000 ( 0.235450)
    Catch/Throw 0.320000 0.000000 0.320000 ( 0.322639)
    Raise/Rescue 1.070000 0.020000 1.090000 ( 1.093540)
    Raise/Rescue no backtrace 0.600000 0.000000 0.600000 ( 0.594695)
    ---------------------------------------------------- total: 2.250000sec

    user system total real
    Break 0.000000 0.000000 0.000000 ( 0.000004)
    Catch/Throw 0.520000 0.210000 0.730000 ( 0.736160)
    Raise/Rescue 7.150000 0.440000 7.590000 ( 7.605270)
    Raise/Rescue no backtrace 1.500000 0.260000 1.760000 ( 1.775553)
    Break 0.230000 0.000000 0.230000 ( 0.233382)
    Catch/Throw 0.320000 0.000000 0.320000 ( 0.321296)
    Raise/Rescue 1.060000 0.020000 1.080000 ( 1.069689)
    Raise/Rescue no backtrace 0.590000 0.000000 0.590000 ( 0.586801)
  2. jacobdam revised this gist Apr 8, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bench.rb
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@

    x.report('Break') do
    1_000_000.times do
    break
    loop { break }
    end
    end

  3. jacobdam revised this gist Jun 26, 2013. 2 changed files with 15 additions and 11 deletions.
    5 changes: 3 additions & 2 deletions bench.rb
    Original file line number Diff line number Diff line change
    @@ -27,13 +27,14 @@
    end

    x.report('Raise/Rescue no backtrace') do
    empty_backtrace = []
    1_000_000.times do
    begin
    raise StandardError, '', nil
    raise StandardError, '', empty_backtrace
    rescue
    # do nothing
    end
    end
    end

    end
    end
    21 changes: 12 additions & 9 deletions results.txt
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,13 @@
    Rehearsal ------------------------------------------------
    Break 0.000000 0.000000 0.000000 ( 0.000017)
    Catch/Throw 0.760000 0.300000 1.060000 ( 1.056713)
    Raise/Rescue 10.390000 0.590000 10.980000 ( 11.017974)
    -------------------------------------- total: 12.040000sec
    ruby bench.rb
    Rehearsal -------------------------------------------------------------
    Break 0.000000 0.000000 0.000000 ( 0.000010)
    Catch/Throw 0.530000 0.220000 0.750000 ( 0.748960)
    Raise/Rescue 7.680000 0.450000 8.130000 ( 8.120991)
    Raise/Rescue no backtrace 1.490000 0.260000 1.750000 ( 1.757660)
    --------------------------------------------------- total: 10.630000sec

    user system total real
    Break 0.000000 0.000000 0.000000 ( 0.000005)
    Catch/Throw 0.770000 0.290000 1.060000 ( 1.064175)
    Raise/Rescue 9.630000 0.580000 10.210000 ( 10.232384)
    user system total real
    Break 0.000000 0.000000 0.000000 ( 0.000004)
    Catch/Throw 0.520000 0.210000 0.730000 ( 0.736160)
    Raise/Rescue 7.150000 0.440000 7.590000 ( 7.605270)
    Raise/Rescue no backtrace 1.500000 0.260000 1.760000 ( 1.775553)
  4. jacobdam revised this gist Jun 26, 2013. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions bench.rb
    Original file line number Diff line number Diff line change
    @@ -25,5 +25,15 @@
    end
    end
    end

    x.report('Raise/Rescue no backtrace') do
    1_000_000.times do
    begin
    raise StandardError, '', nil
    rescue
    # do nothing
    end
    end
    end

    end
  5. @JoshTGreenwood JoshTGreenwood created this gist Nov 21, 2012.
    29 changes: 29 additions & 0 deletions bench.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    require 'benchmark'

    Benchmark.bmbm do |x|

    x.report('Break') do
    1_000_000.times do
    break
    end
    end

    x.report('Catch/Throw') do
    1_000_000.times do
    catch(:benchmarking) do
    throw(:benchmarking)
    end
    end
    end

    x.report('Raise/Rescue') do
    1_000_000.times do
    begin
    raise StandardError
    rescue
    # do nothing
    end
    end
    end

    end
    10 changes: 10 additions & 0 deletions results.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    Rehearsal ------------------------------------------------
    Break 0.000000 0.000000 0.000000 ( 0.000017)
    Catch/Throw 0.760000 0.300000 1.060000 ( 1.056713)
    Raise/Rescue 10.390000 0.590000 10.980000 ( 11.017974)
    -------------------------------------- total: 12.040000sec

    user system total real
    Break 0.000000 0.000000 0.000000 ( 0.000005)
    Catch/Throw 0.770000 0.290000 1.060000 ( 1.064175)
    Raise/Rescue 9.630000 0.580000 10.210000 ( 10.232384)