Home > Uncategorized > More on Autoboxing

More on Autoboxing

March 17th, 2008 deevis

I recently did a benchmark on Autoboxing where I determined that Autoboxing cost about 15 nanoseconds. Well, then I got to thinking that I’d written that test to work with int/Integer datatypes. But what about the other types? Today I add Boolean, Float, Double and Long into the mix.

To cut to the chase, I’ll first tell you the cost of Autoboxing these types.

Boolean: 1/1 nanoseconds

Integer: 15/17 nanoseconds

Float: 19/19 nanoseconds

Double: 22/24 nanoseconds

Long: 30/40 nanoseconds

The two numbers are the results for Half and Full Boxing. Half Boxing is going one way from either primitive to Object or Object to primitive. Full Boxing is a full round trip going primitive to Object and back to primitive. So, for the Long results it takes 30 nanoseconds to Half Box (one way) while it takes 40 nanoseconds to Full Box ( round trip ).

So, the underlying datatype’s size seems to directly impact the cost of the Autoboxing. I’ll be doing more tests with other types shortly. Here are the charts from the Boolean and Long trials.

Boolean Autoboxing Results

Integer Autoboxing Results

Float Autoboxing Results

Double Autoboxing Results

Long Autoboxing Results

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • StumbleUpon
  • Technorati
  • TwitThis
Categories: Uncategorized Tags:
Comments are closed.