D
daniel.w.gelder
I have a stack class for a certain purpose which never needs to store
more than a few dozen doubles and was written like this:
static final double[] doubleStack = new double[128];
static int doubleStackIndex = 0;
// pushes and pops doubles.
public final static void pushDouble(double d)
{
doubleStack[(doubleStackIndex++) & 127] = d;
}
public final static double popDouble()
{
return doubleStack[(--doubleStackIndex) & 127];
}
I noticed that making doubleStack final and putting the & in the
expression gives a consistent 13% speed boost in the code:
for (int i = 0; i < 1000000; i++)
{ pushDouble(10); popDouble(); }
So that's one way to make arrays faster. Are there any other ones
anyone knows about? I'm about to write a very optimized program and
could use any tricks.
Enjoy
Dan
more than a few dozen doubles and was written like this:
static final double[] doubleStack = new double[128];
static int doubleStackIndex = 0;
// pushes and pops doubles.
public final static void pushDouble(double d)
{
doubleStack[(doubleStackIndex++) & 127] = d;
}
public final static double popDouble()
{
return doubleStack[(--doubleStackIndex) & 127];
}
I noticed that making doubleStack final and putting the & in the
expression gives a consistent 13% speed boost in the code:
for (int i = 0; i < 1000000; i++)
{ pushDouble(10); popDouble(); }
So that's one way to make arrays faster. Are there any other ones
anyone knows about? I'm about to write a very optimized program and
could use any tricks.
Enjoy
Dan