JNI Performance

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

I have little experience with JNI or C.

Also one of our main criteria is performance. How much of the performance is observed when using JNI?

+2
source share
3 answers

The border of the function call is "slow", so if you make many calls in your regular program, performance will suffer.

An example of what might benefit from switching to JNI (I emphasize maybe because Java is more than fast enough for many purposes) would be to do some image processing on a large bitmap. But calling a JNI procedure for each pixel would be much, much slower than doing it in a loop in pure Java.

Extracting data from one format to another is, frankly, what is best done in a scripting language such as Python, and will never be processor bound. Rather, disk speed will be a way, a path slower than any language interpreter.

+6
source

It seems to me that since you have little experience with C, your best bet is to do it with Java. JNI is really not that bad.

+1
source

I am not at all familiar with non-C HDF interfaces, so I cannot compare them.

I would point out that this is an API that uses all the other interfaces, so if you find that you need to extract maximum performance, then the C API will be the best.

There is also the question of which parts of the API are available to you. For example, I initially started with the C ++ interface. Some APIs are still only available in the C API. This is not a problem if you use C and C ++, but it can be a problem if you do not need an API.

Having said that, you need your head to be screwed in terms of the C object model: for example. use of pointers, pens, etc.

0
source