Skip to content

Instantly share code, notes, and snippets.

@carlosantoniodasilva
Created January 3, 2013 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosantoniodasilva/4443224 to your computer and use it in GitHub Desktop.
Save carlosantoniodasilva/4443224 to your computer and use it in GitHub Desktop.
BigDecimal performance
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