faster Math.exp() via JNI?

前端 未结 15 564
时光取名叫无心
时光取名叫无心 2021-01-11 22:43

I need to calculate Math.exp() from java very frequently, is it possible to get a native version to run faster than java\'s Math.exp()

15条回答
  •  执笔经年
    2021-01-11 23:46

    +1 to writing your own exp() implementation. That is, if this is really a bottle-neck in your application. If you can deal with a little inaccuracy, there are a number of extremely efficient exponent estimation algorithms out there, some of them dating back centuries. As I understand it, Java's exp() implementation is fairly slow, even for algorithms which must return "exact" results.

    Oh, and don't be afraid to write that exp() implementation in pure-Java. JNI has a lot of overhead, and the JVM is able to optimize bytecode at runtime sometimes even beyond what C/C++ is able to achieve.

提交回复
热议问题