broschb
broschb

Reputation:

autoboxing and performance

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?

Upvotes: 2

Views: 2024

Answers (3)

Niniki
Niniki

Reputation: 810

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

Upvotes: 3

Jon Skeet
Jon Skeet

Reputation: 1500375

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.

Upvotes: 2

Midhat
Midhat

Reputation: 17810

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

Upvotes: 0

Related Questions