Skip to content

Instantly share code, notes, and snippets.

@ascendbruce
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save ascendbruce/abb001a76d9a24e15465 to your computer and use it in GitHub Desktop.

Select an option

Save ascendbruce/abb001a76d9a24e15465 to your computer and use it in GitHub Desktop.

Revisions

  1. ascendbruce revised this gist Aug 1, 2014. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions result
    Original file line number Diff line number Diff line change
    @@ -1,25 +1,25 @@
    # Rehearsal 不算入
    user system total real
    unless blank? (actually present) 0.700000 0.000000 0.700000 ( 0.703966)
    unless blank? (actually blank) 1.390000 0.000000 1.390000 ( 1.399121)
    unless blank? (actually blank) 1.390000 0.000000 1.390000 ( 1.399121)
    if present? (actually present) 0.790000 0.000000 0.790000 ( 0.795483)
    if present? (actually blank) 1.410000 0.000000 1.410000 ( 1.406053)
    if present? (actually blank) 1.410000 0.000000 1.410000 ( 1.406053)

    user system total real
    unless blank? (actually present) 0.740000 0.000000 0.740000 ( 0.741436)
    unless blank? (actually blank) 1.400000 0.000000 1.400000 ( 1.407183)
    unless blank? (actually blank) 1.400000 0.000000 1.400000 ( 1.407183)
    if present? (actually present) 0.780000 0.000000 0.780000 ( 0.775220)
    if present? (actually blank) 1.420000 0.010000 1.430000 ( 1.431337)
    if present? (actually blank) 1.420000 0.010000 1.430000 ( 1.431337)

    # if/unless 上下對調
    user system total real
    if present? (actually present) 0.750000 0.000000 0.750000 ( 0.745319)
    if present? (actually blank) 1.430000 0.000000 1.430000 ( 1.436408)
    if present? (actually blank) 1.430000 0.000000 1.430000 ( 1.436408)
    unless blank? (actually present) 0.660000 0.000000 0.660000 ( 0.659880)
    unless blank? (actually blank) 1.290000 0.000000 1.290000 ( 1.295552)
    unless blank? (actually blank) 1.290000 0.000000 1.290000 ( 1.295552)

    user system total real
    if present? (actually present) 0.730000 0.010000 0.740000 ( 0.739630)
    if present? (actually blank) 1.440000 0.000000 1.440000 ( 1.433405)
    if present? (actually blank) 1.440000 0.000000 1.440000 ( 1.433405)
    unless blank? (actually present) 0.650000 0.000000 0.650000 ( 0.654705)
    unless blank? (actually blank) 1.370000 0.000000 1.370000 ( 1.368957)
    unless blank? (actually blank) 1.370000 0.000000 1.370000 ( 1.368957)
  2. ascendbruce revised this gist Aug 1, 2014. 2 changed files with 25 additions and 26 deletions.
    11 changes: 6 additions & 5 deletions if_unless_bmbm.rb
    Original file line number Diff line number Diff line change
    @@ -5,32 +5,33 @@

    Benchmark.bmbm do |x|

    x.report("if present? (actually blank)") do
    x.report("if present? (actually present)") do
    TIMES.times do
    if "1".present?
    end
    end
    end

    x.report("if present? (actually present)") do
    x.report("if present? (actually blank)") do
    TIMES.times do
    if "".present?
    end
    end
    end

    x.report("unless blank? (actually blank)") do
    x.report("unless blank? (actually present)") do
    TIMES.times do
    unless "1".blank?
    end
    end
    end

    x.report("unless blank? (actually present)") do
    x.report("unless blank? (actually blank)") do
    TIMES.times do
    unless "".blank?
    end
    end
    end

    end

    40 changes: 19 additions & 21 deletions result
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,25 @@
    # Rehearsal 不算入

    user system total real
    unless blank? (actually blank) 0.700000 0.000000 0.700000 ( 0.703966)
    unless blank? (actually present) 1.390000 0.000000 1.390000 ( 1.399121)
    if present? (actually blank) 0.790000 0.000000 0.790000 ( 0.795483)
    if present? (actually present) 1.410000 0.000000 1.410000 ( 1.406053)

    unless blank? (actually present) 0.700000 0.000000 0.700000 ( 0.703966)
    unless blank? (actually blank) 1.390000 0.000000 1.390000 ( 1.399121)
    if present? (actually present) 0.790000 0.000000 0.790000 ( 0.795483)
    if present? (actually blank) 1.410000 0.000000 1.410000 ( 1.406053)
    user system total real
    unless blank? (actually blank) 0.740000 0.000000 0.740000 ( 0.741436)
    unless blank? (actually present) 1.400000 0.000000 1.400000 ( 1.407183)
    if present? (actually blank) 0.780000 0.000000 0.780000 ( 0.775220)
    if present? (actually present) 1.420000 0.010000 1.430000 ( 1.431337)

    unless blank? (actually present) 0.740000 0.000000 0.740000 ( 0.741436)
    unless blank? (actually blank) 1.400000 0.000000 1.400000 ( 1.407183)
    if present? (actually present) 0.780000 0.000000 0.780000 ( 0.775220)
    if present? (actually blank) 1.420000 0.010000 1.430000 ( 1.431337)
    # if/unless 上下對調

    user system total real
    if present? (actually blank) 0.750000 0.000000 0.750000 ( 0.745319)
    if present? (actually present) 1.430000 0.000000 1.430000 ( 1.436408)
    unless blank? (actually blank) 0.660000 0.000000 0.660000 ( 0.659880)
    unless blank? (actually present) 1.290000 0.000000 1.290000 ( 1.295552)

    if present? (actually present) 0.750000 0.000000 0.750000 ( 0.745319)
    if present? (actually blank) 1.430000 0.000000 1.430000 ( 1.436408)
    unless blank? (actually present) 0.660000 0.000000 0.660000 ( 0.659880)
    unless blank? (actually blank) 1.290000 0.000000 1.290000 ( 1.295552)
    user system total real
    if present? (actually blank) 0.730000 0.010000 0.740000 ( 0.739630)
    if present? (actually present) 1.440000 0.000000 1.440000 ( 1.433405)
    unless blank? (actually blank) 0.650000 0.000000 0.650000 ( 0.654705)
    unless blank? (actually present) 1.370000 0.000000 1.370000 ( 1.368957)
    if present? (actually present) 0.730000 0.010000 0.740000 ( 0.739630)
    if present? (actually blank) 1.440000 0.000000 1.440000 ( 1.433405)
    unless blank? (actually present) 0.650000 0.000000 0.650000 ( 0.654705)
    unless blank? (actually blank) 1.370000 0.000000 1.370000 ( 1.368957)
  3. ascendbruce revised this gist Aug 1, 2014. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions result
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Rehearsal 不算入

    user system total real
    unless blank? (actually blank) 0.700000 0.000000 0.700000 ( 0.703966)
    unless blank? (actually present) 1.390000 0.000000 1.390000 ( 1.399121)
    @@ -10,6 +12,8 @@ unless blank? (actually present) 1.400000 0.000000 1.400000 ( 1.407183)
    if present? (actually blank) 0.780000 0.000000 0.780000 ( 0.775220)
    if present? (actually present) 1.420000 0.010000 1.430000 ( 1.431337)

    # if/unless 上下對調

    user system total real
    if present? (actually blank) 0.750000 0.000000 0.750000 ( 0.745319)
    if present? (actually present) 1.430000 0.000000 1.430000 ( 1.436408)
  4. ascendbruce created this gist Aug 1, 2014.
    36 changes: 36 additions & 0 deletions if_unless_bmbm.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    require 'benchmark'
    require "active_support/core_ext/object/blank"

    TIMES = 1000000

    Benchmark.bmbm do |x|

    x.report("if present? (actually blank)") do
    TIMES.times do
    if "1".present?
    end
    end
    end

    x.report("if present? (actually present)") do
    TIMES.times do
    if "".present?
    end
    end
    end

    x.report("unless blank? (actually blank)") do
    TIMES.times do
    unless "1".blank?
    end
    end
    end

    x.report("unless blank? (actually present)") do
    TIMES.times do
    unless "".blank?
    end
    end
    end

    end
    23 changes: 23 additions & 0 deletions result
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    user system total real
    unless blank? (actually blank) 0.700000 0.000000 0.700000 ( 0.703966)
    unless blank? (actually present) 1.390000 0.000000 1.390000 ( 1.399121)
    if present? (actually blank) 0.790000 0.000000 0.790000 ( 0.795483)
    if present? (actually present) 1.410000 0.000000 1.410000 ( 1.406053)

    user system total real
    unless blank? (actually blank) 0.740000 0.000000 0.740000 ( 0.741436)
    unless blank? (actually present) 1.400000 0.000000 1.400000 ( 1.407183)
    if present? (actually blank) 0.780000 0.000000 0.780000 ( 0.775220)
    if present? (actually present) 1.420000 0.010000 1.430000 ( 1.431337)

    user system total real
    if present? (actually blank) 0.750000 0.000000 0.750000 ( 0.745319)
    if present? (actually present) 1.430000 0.000000 1.430000 ( 1.436408)
    unless blank? (actually blank) 0.660000 0.000000 0.660000 ( 0.659880)
    unless blank? (actually present) 1.290000 0.000000 1.290000 ( 1.295552)

    user system total real
    if present? (actually blank) 0.730000 0.010000 0.740000 ( 0.739630)
    if present? (actually present) 1.440000 0.000000 1.440000 ( 1.433405)
    unless blank? (actually blank) 0.650000 0.000000 0.650000 ( 0.654705)
    unless blank? (actually present) 1.370000 0.000000 1.370000 ( 1.368957)