Sounds like boxing/unboxing overhead, in that case! What if you tried that with an array of native ints?
On Thu, Jun 4, 2009 at 3:47 PM, Aaron Steele <[email protected]> wrote: > > So item 46 in Effective Java says that there shouldn't be a > performance penalty using the nice for loops. But the following test > in Eclipse on my machine (MacBook Pro, Intel Core Duo, 2.16 GHz) shows > a performance penalty. > > Given an ArrayList called ints with 1 million Integers, this takes 31 > milliseconds: > for (int i = 0, size = ints.size(); i < size; i++) > ints.get(i).intValue(); > > And this takes 76 milliseconds: > for (Integer i : ints) > i.intValue(); > > What am I missing? Probably just some super naive testing on my part. :) > -- Alex Rudnick swe, gwt, atl --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
