JNI表现 [英] JNI Performance

查看:68
本文介绍了JNI表现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的主程序是用Java编写的,但是从存储中提取数据的代码是用C编写的.我需要从提取的数据中构建一个HDF5文件.使用JNI调用C代码以获取数据,然后从Java构建HDF5文件还是从C代码构建HDF5,会更好吗?

Our main program is in java but the code that extracts our data from storage is written in C. I need to build an HDF5 file from extracted data. Would it be better to use JNI to call the C code to get the data and then build the HDF5 file from Java or to build the HDF5 from the C code?

我对JNI或C经验很少.

I have little experience with JNI or C.

我们的主要标准之一就是性能.使用JNI会对性能造成多少影响?

Also One of our main criteria is performance. How much of a performance hit is there when using JNI?

推荐答案

函数调用边界是缓慢的",因此,如果您对本机例程进行了多次调用,则性能会受到影响.

The function call boundary is "slow", so if you're doing many calls to your native routine, then performance will suffer.

通过迁移到JNI可能使可能受益的一类示例(我强调 may ,因为Java在许多方面都足够快)在大型位图上执行某种图像处理的例程.但是,为每个 pixel 调用JNI例程比在纯Java循环中执行JNI例程要慢得多.

An example of the kind of thing that may benefit from moving to JNI (I emphasize may, because Java is more than fast enough for many purposes) would be a routine to do some sort of image processing on a large bitmap. But to call a JNI routine for each pixel would be much, much slower than doing it within a loop in pure Java.

坦率地说,将数据从一种格式提取到另一种格式是最好用诸如Python之类的脚本"语言来完成的事情,并且永远不会受到CPU的束缚.而是,磁盘速度将变得比任何语言解释器都要慢.

Extracting data from one format to another is, frankly, the kind of thing best done in a "scripting" language like Python, and will never be bound by CPU. Rather, the disk speed is going to be way, way slower than any language interpreter.

这篇关于JNI表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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