From: mail@... Date: 2015-01-27T02:17:35+00:00 Subject: [ruby-core:67822] [ruby-trunk - Feature #10785] [Open] [PATCH1/1] [ja/en] 特定のケースでMath.cを3倍速く / Make Math.c 3 times faster in a certain situation Issue #10785 has been reported by gogo tanaka. ---------------------------------------- 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 * 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. ������������������ $ 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) ``` -- https://bugs.ruby-lang.org/