Skip to content

Instantly share code, notes, and snippets.

@carlosantoniodasilva
Created January 3, 2013 12:47
Show Gist options
  • Select an option

  • Save carlosantoniodasilva/4443224 to your computer and use it in GitHub Desktop.

Select an option

Save carlosantoniodasilva/4443224 to your computer and use it in GitHub Desktop.

Revisions

  1. carlosantoniodasilva created this gist Jan 3, 2013.
    33 changes: 33 additions & 0 deletions bigdecimal-perf.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    require 'benchmark/ips'
    require 'bigdecimal'

    Benchmark.ips do |x|
    x.report("== true") {
    BigDecimal('3') == true
    }

    x.report("TrueClass") {
    TrueClass === BigDecimal('3')
    }

    x.report("== 0") {
    BigDecimal('3') == 0
    }

    x.report("Numeric") {
    Numeric === BigDecimal('3')
    }
    end

    =begin
    Calculating -------------------------------------
    == true 6427 i/100ms
    TrueClass 47297 i/100ms
    == 0 35923 i/100ms
    Numeric 55530 i/100ms
    -------------------------------------------------
    == true 75878.5 (±21.6%) i/s - 359912 in 5.004392s
    TrueClass 1249547.0 (±13.1%) i/s - 6148610 in 5.035964s
    == 0 666856.3 (±13.3%) i/s - 3268993 in 5.013789s
    Numeric 1269300.9 (±11.3%) i/s - 6274890 in 5.028458s
    =end