Join GitHub today
Use direct bytebuffers #1
A coworker referred me to your blog post (http://imranrashid.com/posts/profiling-bytebuffers/). I commented there about the possibility of using direct bytebuffers for increased performance, still I was a bit curious myself.
Here are the result of the original code:
And using direct bytebuffers:
Endianness didn't since to influence the results that much, but I consistently got better results using native byteorder by a small margin (across 5 runs).
Direct byte buffers are also pretty good if you're interacting with C code (through JNI), since you can avoid copying buffers.
Thanks for sending this! It was a great suggestion, the performance improvement is pretty significant. Do you know if this is just for reading, or is writing to direct byte buffers also faster? More experiments to try ...
One thing surprised me about your results, though. It seems for you, directly calling
I'm not going to apply this PR, because I've made a bunch of other changes to the code, and I want to run the heap & direct byte buffers side-by-side, but I really appreciate you doing this!