JNI 性能

发布于 2024-08-07 10:32:41 字数 188 浏览 10 评论 0原文

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

我对 JNI 或 C 缺乏经验。

另外,我们的主要标准之一是性能。使用 JNI 时性能会受到多大影响?

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?

I have little experience with JNI or C.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谢绝鈎搭 2024-08-14 10:32:41

函数调用边界很“慢”,因此如果您对本机例程进行多次调用,那么性能将会受到影响。

一个可能从迁移到 JNI 中受益的例子(我强调可能,因为 Java 对于许多用途来说都足够快)将是一个例行公事对大位图进行某种图像处理。但是为每个像素调用 JNI 例程比在纯 Java 循环中执行要慢得多。

坦率地说,将数据从一种格式提取到另一种格式最好用 Python 等“脚本”语言来完成,并且永远不会受到 CPU 的限制。相反,磁盘速度将比任何语言解释器慢得多。

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

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.

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.

久随 2024-08-14 10:32:41

在我看来,既然你对 C 的经验很少,你最好的选择是使用 Java 来完成它。 JNI 确实没有那么糟糕。

Looks to me that since you have little experience with C, your best choice is to do it from withing Java.. JNI is really not that bad.

倒数 2024-08-14 10:32:41

除了C接口之外,我对HDF接口一无所知,所以我无法真正为你进行比较。

我想指出的是,这是所有其他接口都使用的 API,因此,如果您发现需要寻求最大性能,那么 C API 将是最好的。

还有一个问题是 API 的哪些部分可供您使用。例如,我最初是从 C++ 接口开始的。一些 API 仍然只能在 C API 中使用。当您使用 C & 时这不是问题。 C++,但如果您无法使用所需的 API,则可能会出现问题。

话虽如此,您确实需要充分了解 C 的对象模型:例如。使用指针、句柄等

I'm not familiar at all with the HDF interfaces other than the C one, so I cannot really compare for you.

I would point out that this is the API which all other interfaces use, so if you're finding that you need to eek out the maximum performance then the C API is going to be the best.

There is also a question about what parts of the API are available to you. For example I originally started with the C++ interface. Some APIs were still only available in the C API. This is not a problem when you're using C & C++ but it may be a problem if an API you need is not available to you.

Having said that, you do need to have your head screwed on in terms of the object model of C: eg. use of pointers, handles etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文