且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JNI与JNA性能

更新时间:2023-12-03 23:23:46

JNA比JNI慢得多,但更容易。如果性能不是问题,请使用JNA。

JNA is much slower than JNI, but much easier. If performance is not an issue use JNA.

使用直接缓冲区的优点是最关键的操作不使用JNI或JNA,因此更快。他们使用内在的意思,当它们变成单一的机器代码指令。

Using direct buffers have the advantage that the most critical operations don't use JNI or JNA and are thus faster. They use intrinsic when means they get turned into single machine code instructions.

如果Java代码明显比C慢,很可能代码没有被充分优化。通常GPU应该做所有的工作,所以如果Java有点慢,这不应该有太大的区别。

If Java code is significantly slower than C it is likely the code hasn't been optimised enough. Generally the GPU should be doing all the work so if Java is a bit slower this shouldn't make much difference.

例如。如果你花费99%的时间在GPU和Java花费两倍的总时间将是99 + 2%或慢1%。

e.g. if you spend 99% of the time in the GPU and Java takes twice as long the total will be 99+2% or 1% slower.