Created
January 3, 2013 12:47
-
-
Save carlosantoniodasilva/4443224 to your computer and use it in GitHub Desktop.
BigDecimal performance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment