diff options
author | Kenta Murata <mrkn@mrkn.jp> | 2021-01-01 04:13:12 +0900 |
---|---|---|
committer | Kenta Murata <mrkn@mrkn.jp> | 2021-01-02 00:54:09 +0900 |
commit | 448a67cd812d0be0a7f1cc871daa598c3b846143 (patch) | |
tree | 95c627713f6b2129787d60731d57f0f26c0e8d04 /test/bigdecimal/test_bigdecimal.rb | |
parent | 4730efdd80f40119f8a397fe1b4b7ba88a0ce3d3 (diff) |
[ruby/bigdecimal] Implement special conversions for 64-bit integers
This change improves the conversion speed from small integers.
```
Comparison:
big_n9
master: 4003688.9 i/s
bigdecimal 3.0.0: 1270551.0 i/s - 3.15x slower
big_n19
master: 5410096.4 i/s
bigdecimal 3.0.0: 1000250.3 i/s - 5.41x slower
```
https://github.com/ruby/bigdecimal/commit/3429bd7e6f
Diffstat (limited to 'test/bigdecimal/test_bigdecimal.rb')
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index 91cf7288e9..c2591dea25 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -1,6 +1,7 @@ # frozen_string_literal: false require_relative "testbase" require 'bigdecimal/math' +require 'rbconfig/sizeof' class TestBigDecimal < Test::Unit::TestCase include TestBigDecimalBase @@ -104,10 +105,26 @@ class TestBigDecimal < Test::Unit::TestCase end def test_BigDecimal_with_integer + assert_equal(BigDecimal("0"), BigDecimal(0)) assert_equal(BigDecimal("1"), BigDecimal(1)) assert_equal(BigDecimal("-1"), BigDecimal(-1)) assert_equal(BigDecimal((2**100).to_s), BigDecimal(2**100)) assert_equal(BigDecimal((-2**100).to_s), BigDecimal(-2**100)) + + assert_equal(BigDecimal(RbConfig::LIMITS["FIXNUM_MIN"].to_s), + BigDecimal(RbConfig::LIMITS["FIXNUM_MIN"])) + + assert_equal(BigDecimal(RbConfig::LIMITS["FIXNUM_MAX"].to_s), + BigDecimal(RbConfig::LIMITS["FIXNUM_MAX"])) + + assert_equal(BigDecimal(RbConfig::LIMITS["INT64_MIN"].to_s), + BigDecimal(RbConfig::LIMITS["INT64_MIN"])) + + assert_equal(BigDecimal(RbConfig::LIMITS["INT64_MAX"].to_s), + BigDecimal(RbConfig::LIMITS["INT64_MAX"])) + + assert_equal(BigDecimal(RbConfig::LIMITS["UINT64_MAX"].to_s), + BigDecimal(RbConfig::LIMITS["UINT64_MAX"])) end def test_BigDecimal_with_rational |