diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-03 06:19:17 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-03 06:19:17 +0000 |
commit | 673ff731c17bbbae4d672c8514d4991382179981 (patch) | |
tree | 0334a10da2445307ee048cbae6158463fa0b98df /numeric.c | |
parent | 670725b08784e7467ffbd4b40c9a7c3cd9ca813e (diff) |
complex.c: Optimize Complex#* and Complex#**
Optimize f_mul for the core numeric class components.
This change improves the computation time of Complex#* and Complex#**.
```
$ make benchmark ITEM=complex_float_ COMPARE_RUBY=/Users/mrkn/.rbenv/versions/2.6.0/bin/ruby
generating known_errors.inc
known_errors.inc unchanged
/Users/mrkn/src/github.com/ruby/ruby/revision.h unchanged
/Users/mrkn/.rbenv/shims/ruby --disable=gems -rrubygems -I/Users/mrkn/src/github.com/ruby/ruby/benchmark/lib /Users/mrkn/src/github.com/ruby/ruby/benchmark/benchmark-driver/exe/benchmark-driver \
--executables="compare-ruby::/Users/mrkn/.rbenv/versions/2.6.0/bin/ruby -I.ext/common --disable-gem" \
--executables="built-ruby::./miniruby -I/Users/mrkn/src/github.com/ruby/ruby/lib -I. -I.ext/common -r/Users/mrkn/src/github.com/ruby/ruby/prelude --disable-gem" \
$(find /Users/mrkn/src/github.com/ruby/ruby/benchmark -maxdepth 1 -name '*complex_float_*.yml' -o -name '*complex_float_*.rb' | sort)
Calculating -------------------------------------
compare-ruby built-ruby
complex_float_add 6.558M 13.012M i/s - 1.000M times in 0.152480s 0.076850s
complex_float_div 576.821k 567.969k i/s - 1.000M times in 1.733640s 1.760660s
complex_float_mul 1.690M 2.628M i/s - 1.000M times in 0.591786s 0.380579s
complex_float_new 1.350M 1.268M i/s - 1.000M times in 0.740669s 0.788762s
complex_float_power 1.571M 1.835M i/s - 1.000M times in 0.636507s 0.544909s
complex_float_sub 8.635M 8.779M i/s - 1.000M times in 0.115814s 0.113906s
Comparison:
complex_float_add
built-ruby: 13012361.7 i/s
compare-ruby: 6558237.1 i/s - 1.98x slower
complex_float_div
compare-ruby: 576821.0 i/s
built-ruby: 567968.8 i/s - 1.02x slower
complex_float_mul
built-ruby: 2627575.4 i/s
compare-ruby: 1689800.0 i/s - 1.55x slower
complex_float_new
compare-ruby: 1350130.8 i/s
built-ruby: 1267809.6 i/s - 1.06x slower
complex_float_power
built-ruby: 1835168.8 i/s
compare-ruby: 1571074.6 i/s - 1.17x slower
complex_float_sub
built-ruby: 8779168.8 i/s
compare-ruby: 8634534.7 i/s - 1.02x slower
```
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -1066,8 +1066,8 @@ flo_minus(VALUE x, VALUE y) * Returns a new Float which is the product of +float+ and +other+. */ -static VALUE -flo_mul(VALUE x, VALUE y) +VALUE +rb_float_mul(VALUE x, VALUE y) { if (RB_TYPE_P(y, T_FIXNUM)) { return DBL2NUM(RFLOAT_VALUE(x) * (double)FIX2LONG(y)); @@ -5676,7 +5676,7 @@ Init_Numeric(void) rb_define_method(rb_cFloat, "-@", rb_float_uminus, 0); rb_define_method(rb_cFloat, "+", rb_float_plus, 1); rb_define_method(rb_cFloat, "-", flo_minus, 1); - rb_define_method(rb_cFloat, "*", flo_mul, 1); + rb_define_method(rb_cFloat, "*", rb_float_mul, 1); rb_define_method(rb_cFloat, "/", flo_div, 1); rb_define_method(rb_cFloat, "quo", flo_quo, 1); rb_define_method(rb_cFloat, "fdiv", flo_quo, 1); |