Issue #10785 has been updated by gogo tanaka.


I got your point, I sorry to cause you trouble.

But even now, `Float#to_f` is ignored. I think it's same for this or we need to call `#to_f` for all argument.

```rb
ruby -v -e 'p Math.log(1.0);class Float; def to_f; self+1.0;end;end;p Math.log(1.0)'
ruby 2.3.0dev (2015-01-26 trunk 49408) [universal.x86_64-darwin14]
0.0
-e:1: warning: method redefined; discarding old to_f
0.0
```

----------------------------------------
Feature #10785: [PATCH1/1] [ja/en] 特定のケースでMath.cを3倍速く / Make Math.c 3 times faster in a certain situation
https://bugs.ruby-lang.org/issues/10785#change-51276

* Author: gogo tanaka
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
English follows japanese. Because my english is not good ;(

拙い英語のため両言語で補足をします.

`FIXNUM_P(x)`が真を取る際には `(double)FIX2LONG(x)` で、その他の場合は `NUM2DBL(x)` でCの値にするようにしてみました.
速度についてですが、引数が`Fixnum`, `Bignum`オブジェクトである時に限り有意な差を確認することが出来ました.
またその他のケースに対する影響は気になるほどではないと考えています.
色々至らぬところがある気がするので、何かありました際にはお気軽にお申し付け下さい.

Hi, now I use `(double)FIX2LONG(x)` instead of `NUM2DBL(x)` when `FIXNUM_P(x)` is true.

I can found it make almost all Math's module_function faster about 3 times, 
only when arg(s) is `Fixnum` or `Bignum` object.

i feel like I make some mistakes, so please feel free to let me know.

1試行を抜粋

    $ cat bench.rb
```
require 'benchmark'

puts Benchmark.measure { 10000000.times { Math.cos(1) } }
puts Benchmark.measure { 10000000.times { Math.cos((1 << 100)) } }
puts Benchmark.measure { 10000000.times { Math.cos(1.0) } }
puts Benchmark.measure { 10000000.times { Math.cos(1/3r) } }
```

# before
```
  4.280000   0.060000   4.340000 (  4.690771)
  7.000000   0.090000   7.090000 (  7.240859)
  1.430000   0.020000   1.450000 (  1.644737)
  5.950000   0.100000   6.050000 (  6.236341)
```

# after
```
  1.340000   0.000000   1.340000 (  1.359663)
  3.770000   0.050000   3.820000 (  3.917417)
  1.370000   0.010000   1.380000 (  1.395028)
  6.080000   0.070000   6.150000 (  6.255340)
```

---Files--------------------------------
refactoring_math_c.patch (6.97 KB)


-- 
https://bugs.ruby-lang.org/