import java.util.function.IntBinaryOperator;// -XX:+CriticalJNINatives (obsolete, only for JDK17-, see https://bugs.openjdk.org/browse/JDK-8289302)// java -cp out TestJNIpublic class TestJNI {public static native int nativeAdd(int a, int b);public static native int nativeAddBack(int a, int b, IntBinaryOperator cb);static {System.loadLibrary("add"); // need add.dll}static final int LOOP_COUNT = 1_0000_0000;static void testJNI() {long t = System.nanoTime();int n = 0;for (int i = 0; i < LOOP_COUNT; i++)n += nativeAdd(n, i);t = (System.nanoTime() - t) / 1_000_000;System.out.println("testJNI_Direct : " + n + ", " + t + " ms");t = System.nanoTime();n = 0;for (int i = 0; i < LOOP_COUNT; i++)n += nativeAddBack(n, i, Integer::sum);t = (System.nanoTime() - t) / 1_000_000;System.out.println("testJNI_CallBack: " + n + ", " + t + " ms");}public static void main(String[] args) {for (int i = 0; i < 5; i++) {System.out.println("-------- " + i);testJNI();}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。