Project

General

Profile

Actions

Feature #10785

closed

[PATCH1/1] [ja/en] 特定のケースでMath.cを3倍速く / Make Math.c 3 times faster in a certain situation

Added by gogotanaka (Kazuki Tanaka) about 9 years ago. Updated about 9 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:67822]

Description

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) refactoring_math_c.patch gogotanaka (Kazuki Tanaka), 01/27/2015 02:22 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0