|
46 | 46 |
|
47 | 47 | - [General](#general)
|
48 | 48 | - [Array](#array)
|
| 49 | +- [BigDecimal](#bigdecimal) |
49 | 50 | - [Date](#date)
|
50 | 51 | - [Enumerable](#enumerable)
|
51 | 52 | - [Hash](#hash)
|
@@ -655,6 +656,34 @@ Comparison:
|
655 | 656 | inject block: 14063.1 i/s - 1.35x slower
|
656 | 657 | ```
|
657 | 658 |
|
| 659 | +### BigDecimal |
| 660 | + |
| 661 | +##### `BigDecimal('1')` vs `BigDecimal('1.0')` vs `'1'.to_d` vs `'1.0'.to_d` vs `BigDecimal(1)` vs `1.to_d` vs `BigDecimal(1.0, 2)` vs `1.0.to_d` [code](code/bigdecimal/string-vs-numeric.rb) |
| 662 | + |
| 663 | +``` |
| 664 | +$ ruby -v code/bigdecimal/string-vs-numeric.rb |
| 665 | +ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin18] |
| 666 | +Calculating ------------------------------------- |
| 667 | + integer string new 2.497M (± 2.0%) i/s - 12.645M in 5.066385s |
| 668 | + float string new 2.414M (± 2.0%) i/s - 12.182M in 5.048473s |
| 669 | + integer string to_d 2.402M (± 1.8%) i/s - 12.010M in 5.001784s |
| 670 | + float string to_d 2.318M (± 1.8%) i/s - 11.663M in 5.032429s |
| 671 | + integer new 1.601M (± 1.2%) i/s - 8.022M in 5.010201s |
| 672 | + integer to_d 1.563M (± 1.8%) i/s - 7.817M in 5.001726s |
| 673 | + float to_d 529.413k (± 3.6%) i/s - 2.671M in 5.051477s |
| 674 | + float new 517.635k (± 4.5%) i/s - 2.604M in 5.042605s |
| 675 | +
|
| 676 | +Comparison: |
| 677 | + integer string new: 2496860.3 i/s |
| 678 | + float string new: 2414122.8 i/s - same-ish: difference falls within error |
| 679 | + integer string to_d: 2401929.3 i/s - 1.04x slower |
| 680 | + float string to_d: 2318272.7 i/s - 1.08x slower |
| 681 | + integer new: 1601402.4 i/s - 1.56x slower |
| 682 | + integer to_d: 1563335.6 i/s - 1.60x slower |
| 683 | + float to_d: 529412.7 i/s - 4.72x slower |
| 684 | + float new: 517634.5 i/s - 4.82x slower |
| 685 | +``` |
| 686 | + |
658 | 687 | ### Date
|
659 | 688 |
|
660 | 689 | ##### `Date.iso8601` vs `Date.parse` [code](code/date/iso8601-vs-parse.rb)
|
|
0 commit comments