tags:

views:

328

answers:

3

I have an application where I perform hundreds of thousands of calculations. Currently all of our values are Doubles. I am utilizing JFormula engine for most of the calculations, and have noticed the api takes a double parameter, so there is some autoboxing taking place when I pass in a Double. I have read some articles, and created some simple tests, and do notice a performance hit, but am still trying to figure out it the time it takes to go through my code and fix this, will be worth any performance improvements. I am wondering if anyone else has had any experience with something similar and performance gains by using primitives?

A: 

What you can try is to make simple benchmarks with and without autoboxing. run them through a time-profiler (visualvm recommended). Find the time difference and scale it to your program to find approximate time hit in your program

Midhat
+2  A: 

As well as the other suggestions (which are good - profiling and benchmarking are very important) I'd say that if JFormula is doing anything significant within each method call then the boxing/unboxing when making the call is likely to be insignificant. Unboxing in particular is fast as it doesn't require any memory allocation - just copying the existing value from the box, really.

In short: certainly do the tests, but I wouldn't expect the hit to be significant.

Jon Skeet
+3  A: 

It is not appropriate to use autoboxing and unboxing for scientific computing, or other performance-sensitive numerical code. -- Sun FAQ

Niniki
I don't believe this is an issue for him. He is only using the wrappers to get the values to the front door. From JFormula on I would assume they are primitives or BigDecimals.
carson