快Math.exp()通过JNI? [英] faster Math.exp() via JNI?

查看:157
本文介绍了快Math.exp()通过JNI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算 Math.exp()从Java非常频繁,是有可能得到本机的版本比运行速度更快的的Java Math.exp() ??

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()??

我尝试了JNI + C,但它比只是普通的的Java

I tried just jni + C, but it's slower than just plain java.

推荐答案

+1来编写自己的EXP()实现。也就是说,如果这是的真正的一个瓶颈在应用程序中。如果你能处理一点点不准确,有一些非常有效的指数估计算法在那里,他们中的一些可以追溯到几个世纪。据我了解,Java的EXP()的实现是相当缓慢的,即使它必须返回精确的结果算法。

+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.

哦,不要害怕写在纯Java的EXP()实现。 JNI有很大的开销,和JVM能够优化运行时字节code有时甚至超越了C / C ++是能实现的。

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.

这篇关于快Math.exp()通过JNI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆