-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'benchmark/ips' | ||
require 'bigdecimal' | ||
require 'bigdecimal/util' | ||
|
||
def fastest | ||
BigDecimal('1') | ||
end | ||
|
||
def fastest2 | ||
BigDecimal('1.0') | ||
end | ||
|
||
def fast | ||
'1'.to_d | ||
end | ||
|
||
def fast2 | ||
'1.0'.to_d | ||
end | ||
|
||
def slow | ||
BigDecimal(1) | ||
end | ||
|
||
def slow2 | ||
1.to_d | ||
end | ||
|
||
def slowest | ||
BigDecimal(1.0, 2) | ||
end | ||
|
||
def slowest2 | ||
1.0.to_d | ||
end | ||
|
||
|
||
Benchmark.ips do |x| | ||
x.report('float to_d') { slowest2 } | ||
x.report('float new') { slowest } | ||
x.report('integer to_d') { slow2 } | ||
x.report('integer new') { slow } | ||
x.report('float string to_d') { fast2 } | ||
x.report('integer string to_d') { fast } | ||
x.report('float string new') { fastest2 } | ||
x.report('integer string new') { fastest } | ||
x.compare! | ||
end |