[ 
https://issues.apache.org/jira/browse/MATH-762?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13423848#comment-13423848
 ] 

Gilles commented on MATH-762:
-----------------------------

{{testRuns=1000}}
{noformat}
sin (calls per timed block: 10, timed blocks: 100, time unit: ms)
        name      time/call      std error total time      ratio      difference
FastMath_new 8.05372400e-03 5.69816722e-02 8.0537e+00 1.0000e+00  0.00000000e+00
    FastMath 2.35349100e-03 1.70452763e-04 2.3535e+00 2.9222e-01 -5.70023300e+00
cos (calls per timed block: 10, timed blocks: 100, time unit: ms)
        name      time/call      std error total time      ratio      difference
FastMath_new 3.01337100e-03 2.53826298e-04 3.0134e+00 1.0000e+00  0.00000000e+00
    FastMath 3.04312900e-03 4.42794828e-04 3.0431e+00 1.0099e+00  2.97580000e-02
tan (calls per timed block: 10, timed blocks: 100, time unit: ms)
        name      time/call      std error total time      ratio      difference
FastMath_new 3.67204900e-03 2.42267144e-04 3.6720e+00 1.0000e+00  0.00000000e+00
    FastMath 3.88932500e-03 2.01659705e-03 3.8893e+00 1.0592e+00  2.17276000e-01
{noformat}

{{testRuns=10000}}
{noformat}
sin (calls per timed block: 100, timed blocks: 100, time unit: ms)
        name      time/call      std error total time      ratio      difference
FastMath_new 1.61342360e-03 3.95663600e-03 1.6134e+01 1.0000e+00  0.00000000e+00
    FastMath 1.22423760e-03 5.60476091e-04 1.2242e+01 7.5878e-01 -3.89186000e+00
cos (calls per timed block: 100, timed blocks: 100, time unit: ms)
        name      time/call      std error total time      ratio      difference
FastMath_new 5.81420000e-04 1.33084649e-04 5.8142e+00 1.0000e+00  0.00000000e+00
    FastMath 6.30431900e-04 1.15944209e-04 6.3043e+00 1.0843e+00  4.90119000e-01
tan (calls per timed block: 100, timed blocks: 100, time unit: ms)
        name      time/call      std error total time      ratio      difference
FastMath_new 1.81382170e-03 4.60963049e-04 1.8138e+01 1.0000e+00  0.00000000e+00
    FastMath 1.80197360e-03 4.65295595e-04 1.8020e+01 9.9347e-01 -1.18481000e-01
{noformat}

{{testRuns=100000}}
{noformat}
sin (calls per timed block: 1000, timed blocks: 100, time unit: ms)
        name      time/call      std error total time      ratio      difference
FastMath_new 2.66746730e-04 6.36093486e-04 2.6675e+01 1.0000e+00  0.00000000e+00
    FastMath 2.86870660e-04 3.40789599e-04 2.8687e+01 1.0754e+00  2.01239300e+00
cos (calls per timed block: 1000, timed blocks: 100, time unit: ms)
        name      time/call      std error total time      ratio      difference
FastMath_new 1.87070890e-04 1.29019495e-04 1.8707e+01 1.0000e+00  0.00000000e+00
    FastMath 2.51731510e-04 2.71590133e-04 2.5173e+01 1.3456e+00  6.46606200e+00
tan (calls per timed block: 1000, timed blocks: 100, time unit: ms)
        name      time/call      std error total time      ratio      difference
FastMath_new 2.99618920e-04 5.05795382e-04 2.9962e+01 1.0000e+00  0.00000000e+00
    FastMath 3.22126510e-04 4.71998805e-04 3.2213e+01 1.0751e+00  2.25075900e+00
{noformat}

{{testRuns=50000000}}
{noformat}
sin (calls per timed block: 500000, timed blocks: 100, time unit: ms)
        name      time/call      std error total time      ratio      difference
FastMath_new 5.66187773e-05 1.78328440e-05 2.8309e+03 1.0000e+00  0.00000000e+00
    FastMath 5.91035189e-05 1.45378078e-05 2.9552e+03 1.0439e+00  1.24237079e+02
cos (calls per timed block: 500000, timed blocks: 100, time unit: ms)
        name      time/call      std error total time      ratio      difference
FastMath_new 6.47608957e-05 1.32088454e-05 3.2380e+03 1.0000e+00  0.00000000e+00
    FastMath 7.34983542e-05 1.23033647e-05 3.6749e+03 1.1349e+00  4.36872925e+02
tan (calls per timed block: 500000, timed blocks: 100, time unit: ms)
        name      time/call      std error total time      ratio      difference
FastMath_new 1.64122148e-04 2.93410172e-05 8.2061e+03 1.0000e+00  0.00000000e+00
    FastMath 1.69261660e-04 2.93783760e-05 8.4631e+03 1.0313e+00  2.56975633e+02
{noformat}

In the above tables, the "FastMath_new" indicates a code where the inlining of 
the "Cody/Waite reduction" has been replaced by an inner class that performs 
these duplicate statements.

On my machine, only when the number of calls is small (so as to make the 
benchmark virtually meaningless) does the inlining actually improve the 
performance. Otherwise it is generally _less_ efficient.

When the number of calls is small, we are talking about absolute differences in 
execution time of around 0.06 ({{tan}}) to 6 ({{sin}}) _microseconds_ per call.

Thus, I propose to apply this change (as an improvement in code cleanliness).

                
> Duplicate code in "FastMath"
> ----------------------------
>
>                 Key: MATH-762
>                 URL: https://issues.apache.org/jira/browse/MATH-762
>             Project: Commons Math
>          Issue Type: Improvement
>            Reporter: Gilles
>            Priority: Minor
>              Labels: performance
>             Fix For: 3.1
>
>
> Several methods contain the same loop, marked
> {code}
> /* Inline the Cody/Waite reduction for performance */
> {code}
> It should be tested whether this claim is true with modern JIT compilation.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to