Does this mean that Java Math.floor is extremely slow?

后端 未结 5 1643
花落未央
花落未央 2020-12-15 19:44

I don\'t Java much.

I am writing some optimized math code and I was shocked by my profiler results. My code collects values, interleaves the data and then chooses th

5条回答
  •  悲哀的现实
    2020-12-15 20:38

    You might want to give a try to FastMath.

    Here is a post about the performance of Math in Java vs. Javascript. There are a few good hints about why the default math lib is slow. They are discussing other operations than floor, but I guess their findings can be generalized. I found it interesting.

    EDIT

    According to this bug entry, floor has been implemented a pure java code in 7(b79), 6u21(b01) resulting in better performance. The code of floor in the JDK 6 is still a bit longer than the one in FastMath, but might not be responsible for such a perf. degradation. What JDK are you using? Could you try with a more recent version?

提交回复
热议问题