commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luc Maisonobe (Commented) (JIRA)" <>
Subject [jira] [Commented] (MATH-650) FastMath has static code which slows the first access to FastMath
Date Thu, 09 Feb 2012 14:52:08 GMT


Luc Maisonobe commented on MATH-650:

I finally succeeded in running on my tablet a slightly modified version of Gilles test (thanks
for putting this together Gilles). The test involves computing 1abs, 10 floor, 30 sin, 30
cos, 50 sqrt, 5 exp, 2 log which is representative of the small application we developed.
The results shown represent the time for all computation, using only FastMath methods. The
tests were run 10 times, with a fresh start each time.

Android tablet, Nvidia Tegra2 chipset at 1GHz, 1Gb memory, running Android 3.0.1:
* literal arrays:    mean  35.1 ms, standard deviation 0.658 ms
* resources loading: mean  55.2 ms, standard deviation 0.651 ms
* table computation: mean 155.4 ms, standard deviation 0.850 ms

Desktop computer, quadcore AMD phenom 9550 quadcore 64 bits at 2.2 GHz, 6 Gb memore, running
Debian Linux wheezy with OpenJDK 6 20.0b12:
* literal arrays:    mean  71.4 ms, standard deviation 0.449 ms
* resources loading: mean  70.3 ms, standard deviation 1.731 ms
* table computation: mean 132.9 ms, standard deviation 1.661 ms

These results show that on the Android platform, the gain from precomputed tables is much
larger than on the desktop. In fact, the test runs at least twice faster on Android than on
the desktop for precomputed table, and 17% slower when tables are computed at startup.

The difference between literal arrays and resources slightly favors literal arrays on the
Android platforms, but on desktop the difference is below standard deviation. In any case,
it is quite small (20 ms) and therefore not significant as it is a one time startup cost only.

So I would conclude that precomputing the tables is a worthwhile improvement.

Now considering how pre-computed tables should be set up, I have no clear cut opinion. I would
like to not have the tables in the source distribution and have them generated automatically
at build time. It seems to me maven does have both generate-source and generate-resource goals
in its lifecycle, but these goals are triggered only by specific plugins (antlr, build-helper,
...). These plugins are not suitable for our case which merely consist in compiling a first
standalone class, then run it to build either the java file or the resource file.

Any ideas about that ? 
> FastMath has static code which slows the first access to FastMath
> -----------------------------------------------------------------
>                 Key: MATH-650
>                 URL:
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: Nightly Builds
>         Environment: Android 2.3 (Dalvik VM with JIT)
>            Reporter: Alexis Robert
>            Priority: Minor
>             Fix For: 3.0
>         Attachments:,
> Working on an Android application using Orekit, I've discovered that a simple FastMath.floor()
takes about 4 to 5 secs on a 1GHz Nexus One phone (only the first time it's called). I've
launched the Android profiling tool (traceview) and the problem seems to be linked with the
static portion of FastMath code named "// Initialize tables"
> The timing resulted in :
> - FastMath.slowexp (40.8%)
> - FastMath.expint (39.2%)
>  \- FastMath.quadmult() (95.6% of expint)
> - FastMath.slowlog (18.2%)
> Hoping that would help
> Thanks!
> Alexis Robert

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message