Testing Function Speeds
Posted: 14 Jul 2005, 20:45
Hello,
I have been thinking about using lazy_eval in my program - using just piece square tables for evaluation.
I have also been adapting my engine to calculate the piece square scores during move generation, and updating the score when a move is made.
I have been trying to come up with a simple test to see the benefits of doing this, and came up with the code below.
The first set of loops is intended to mimic the 'normal' evaluation - loop through a int[64] array, adding the values.
The second is intended to mimic piecesq[from] - piecesq[dest] for each move generated (hence loops * 30) plus the value calculated in makemove...
I get the following result..
===================
Enter loops :2000000
looping through board:
Elapsed: 1.36 seconds
Incrementing..
Elapsed: 9.578 seconds
===================
Not worth doing lazy eval... ?? or is it... because, if I change some of the code to
The result is
==============================
Enter loops :2000000
looping through board:
Elapsed: 1.359 seconds
Incrementing..
Elapsed: 0.282 seconds
===============================
So there is a good time saving !
Which of the tests is most accurate? I am not a skilled programmer, so I imagine this approach is incorrect... does anyone have any advice for a more correct method?
Thanks,
Richard
I have been thinking about using lazy_eval in my program - using just piece square tables for evaluation.
I have also been adapting my engine to calculate the piece square scores during move generation, and updating the score when a move is made.
I have been trying to come up with a simple test to see the benefits of doing this, and came up with the code below.
- Code: Select all
int main()
{
for(;;)
{
int number = 0;
int loops;
cout<<"\nEnter loops :";
cin>>loops;
cout<<"\nlooping through board: "<<endl;
benchmark start;
for (int i = 0; i < loops; ++i)
{
for ( int z = 0; z< 64; ++z)
{
switch (piece[z])
{
case PAWN : number = score[z];break;
case KNIGHT : number = score[z];break;
case BISHOP : number = score[z];break;
case QUEEN : number = score[z];break;
case ROOK : number = score[z];break;
case KING : number = score[z];break;
default: break;
}
}
}
start.report();
int ran = 0;
cout<<"\n\nIncrementing.. "<<endl;
benchmark start2;
for (int i = 0; i < loops*30; ++i)
{
srand(time(NULL));
ran = (rand()%64);
ran2 = (rand()%64);
number = (score[ran] - score[ran2]);
}
start2.report();
char a;
cin>>a;
if (a == 'e') {break;}
else continue;
}
return 0;
}
The first set of loops is intended to mimic the 'normal' evaluation - loop through a int[64] array, adding the values.
The second is intended to mimic piecesq[from] - piecesq[dest] for each move generated (hence loops * 30) plus the value calculated in makemove...
I get the following result..
===================
Enter loops :2000000
looping through board:
Elapsed: 1.36 seconds
Incrementing..
Elapsed: 9.578 seconds
===================
Not worth doing lazy eval... ?? or is it... because, if I change some of the code to
- Code: Select all
cout<<"\n\nIncrementing.. "<<endl;
benchmark start2;
for (int i = 0; i < loops*30; ++i)
{
number = (score[12] - score[15]);
}
start2.report();
The result is
==============================
Enter loops :2000000
looping through board:
Elapsed: 1.359 seconds
Incrementing..
Elapsed: 0.282 seconds
===============================
So there is a good time saving !
Which of the tests is most accurate? I am not a skilled programmer, so I imagine this approach is incorrect... does anyone have any advice for a more correct method?
Thanks,
Richard