|Spare Time Labs 2.0|
PIC CDC ACM
Fun with HC08
Java Goes Native
Gas Fired Furnace
Down Memory Lane
Benchmarking JNA method callsA year or so ago when I was optimizing my PureJavaComm library I made a micro benchmark to evaluate some details of JNA method calling overhead. Some resent discussion on the email@example.com mailing list prompted me to dig out that benchmark and write this page to document my findings.
You can find the complete benchmark code here.
To run it you need a Unix-like operating system, I don't think it will run without modifications on Windows, but I think the results and conclusions from my Mac OS X are valid for Windows and Linux too.
The benchmark calls three different standard POSIX C-library functions,
The code also measures the speed of calling
The total time to execute each call for 10.000 times are recorded and averaged per call.
To prime the Java Hot Spot JIT compiler the tests are repeated ad nouseam and only after a couple of minutes I sampled the output.
Here is a representative sample of the results:
From left to right the results, in microseconds, for standard JNA calls are:
and then the same using 'direct' call method.
The standard deviation of the results are in the ball park of 2%.
Dividing the standard call times with the direct call times gives us a measure of how much speed up we get from direct calls:
So we can say that for these types of calls (simple 'primitive' types supported by the direct call method) the speed up is roughly ten fold.
Comparing the execution times with data on Java-heap or C-heap we see that
Note that his sort of comparisong is full of pitfalls and is not directly appicable to all use cases but I thought sharing these simple measurments would help people to quantify their statements instead of just charaterizings this and thas as fast or slow.
For me the take-away from this exercise was that for PureJavaComm the standard calls were fast enough in a fast computer and did not warant even the relatively simple and easy task of converting to the direct call method. On the otherhand for the Linux backend running a the low powered RaspberryPI it was well worth the effort and made the difference between usable and useless.
That's all folks, Kusti