Thou shalt not try me. Mom 24:7
Jim Venolia wrote:Yeah, I know there is no memset() in Java, nor will there ever be.
I've got an 800x600 array I need to clear fairly often. The array is currently boolean, but it could be int. So by 'clear' I mean either 'set each entry to false', or 'set each entry to 0', doesn't matter to me.
What is the most efficient way to clear this array of either booleans or ints (or bytes, I suppose)?
Thou shalt not try me. Mom 24:7
Jim Venolia wrote:Looks like it saves approx. 10 ms no matter the array size. Running on a quad core with 8gig memory. As my array is 800x600 Array.fill() is 6 times faster, well worth the change.
Thou shalt not try me. Mom 24:7
Jim Venolia wrote:How right you are. I just duplicated the double loop test to re-run after the Array.fill(), the second double loop runs even faster than the Array.fill().
I'm not in the mood to wrap my tests in loops of loops at the moment, maybe later I'll look into it more.
Steve
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Thou shalt not try me. Mom 24:7
Jim Venolia wrote:It's Conway's Life, faster is always better
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jim Venolia wrote:It's Conway's Life, faster is always better
Consider Paul's rocket mass heater. |