diff options
author | Kenta Murata <[email protected]> | 2021-01-12 22:58:17 +0900 |
---|---|---|
committer | Kenta Murata <[email protected]> | 2021-01-13 02:11:18 +0900 |
commit | 4ba3a4491e15ed50f26c8f7a602fb4ef5452085a (patch) | |
tree | 1acc0f040522a8db6bc9a73dc996afa9c7dbfd7f /ext/bigdecimal/missing.c | |
parent | 2175c2c957a711f1c48f42d38db202bf52c8bc6f (diff) |
[ruby/bigdecimal] Optimize rb_float_convert_to_BigDecimal by using dtoa
This improve the conversion speed several times faster than before.
```
RUBYLIB= BUNDLER_ORIG_RUBYLIB= /home/mrkn/.rbenv/versions/3.0.0/bin/ruby -v -S benchmark-driver /home/mrkn/src/github.com/ruby/bigdecimal/benchmark/from_float.yml
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
Calculating -------------------------------------
bigdecimal 3.0.0 master
flt_e0 156.400k 783.356k i/s - 100.000k times in 0.639388s 0.127656s
flt_ep10 158.640k 777.978k i/s - 100.000k times in 0.630359s 0.128538s
flt_ep100 101.676k 504.259k i/s - 100.000k times in 0.983512s 0.198311s
flt_em10 103.439k 726.339k i/s - 100.000k times in 0.966751s 0.137677s
flt_em100 79.675k 651.446k i/s - 100.000k times in 1.255095s 0.153505s
Comparison:
flt_e0
master: 783355.6 i/s
bigdecimal 3.0.0: 156399.5 i/s - 5.01x slower
flt_ep10
master: 777977.6 i/s
bigdecimal 3.0.0: 158639.7 i/s - 4.90x slower
flt_ep100
master: 504259.4 i/s
bigdecimal 3.0.0: 101676.5 i/s - 4.96x slower
flt_em10
master: 726338.6 i/s
bigdecimal 3.0.0: 103439.2 i/s - 7.02x slower
flt_em100
master: 651446.3 i/s
bigdecimal 3.0.0: 79675.3 i/s - 8.18x slower
```
https://github.com/ruby/bigdecimal/commit/5bdaedd530
https://github.com/ruby/bigdecimal/commit/9bfff57f90
https://github.com/ruby/bigdecimal/commit/d071a0abbb
Diffstat (limited to 'ext/bigdecimal/missing.c')
-rw-r--r-- | ext/bigdecimal/missing.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/ext/bigdecimal/missing.c b/ext/bigdecimal/missing.c new file mode 100644 index 0000000000..b0bc6eea4e --- /dev/null +++ b/ext/bigdecimal/missing.c @@ -0,0 +1,17 @@ +#include <ruby/ruby.h> + +#ifdef HAVE_RUBY_ATOMIC_H +# include <ruby/atomic.h> +#endif + +#ifdef RUBY_ATOMIC_PTR_CAS +# define ATOMIC_PTR_CAS(var, old, new) RUBY_ATOMIC_PTR_CAS(var, old, new) +#endif + +#undef strtod +#define strtod BigDecimal_strtod +#undef dtoa +#define dtoa BigDecimal_dtoa +#undef hdtoa +#define hdtoa BigDecimal_hdtoa +#include "missing/dtoa.c" |