Testing Function Speeds

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Testing Function Speeds

Postby Richard Allbert » 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.

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
Richard Allbert
 
Posts: 105
Joined: 27 Sep 2004, 11:56
Location: Aschaffenburg, Germany

Re: Testing Function Speeds

Postby Dann Corbit » 14 Jul 2005, 21:53

Test it with the real code, in place.

The little loop tests like this don't show what it is going to do in your program.

The best way to do this sort of thing is really:
1. Profile to find out where it needs to be faster. Otherwise, you might spend 1000 hours writing the world's fastest "open book" function only to find out that it is 1000 times faster than the old version but has totally zero effect on game play
2. Once you know where the bottlenecks are, attack them from the worst problem to the smallest problem.
3. Replace the algorithm with one having better O(f(n)) complexity if possible.
Goto 1:
Dann Corbit
 

Re: Testing Function Speeds

Postby Richard Allbert » 14 Jul 2005, 22:18

Thank you for the reply.

When you say profile... do you mean the following..

Loops = 1000000
Position = Start position

Action 1.

Genearate all legal moves once for each loop.

Time = 1.516s

Action 2.

Generate - Make and Takeback each move - Next loop

Time = 24.406s

Action 3.

Generate - Make - Evaluate - TakeBack each move - next loop

Time = 95.984s

Action 5.

Generate - Evaluate*20 - next loop

Time = 72.078s



.. and this is my starting profile?

Thanks,

Richard
Richard Allbert
 
Posts: 105
Joined: 27 Sep 2004, 11:56
Location: Aschaffenburg, Germany

Re: Testing Function Speeds

Postby Dann Corbit » 15 Jul 2005, 02:01

When I say profile, I mean use a profiler on your actual application.

Microsoft C++ has one, but it is hidden in the WIn32 SDK.

Intel has a dandy one called Vtune.

GCC has one called gprof.

If you do not profile the real routines you plan to use, and in the actual place that you intend to use them, then you will not know where effort needs to be spent to speed things up.

http://www.tarma.com/articles/index.htm ... 997nov.htm
http://www.johnpanzer.com/aci_cuj/
A nice free one for AMD chips:
http://developer.amd.com/downloads.aspx
You can always use gcc + gprof which works just about anywhere.
Dann Corbit
 

Re: Testing Function Speeds

Postby Richard Allbert » 15 Jul 2005, 07:04

OK,

Thank you again.
Richard Allbert
 
Posts: 105
Joined: 27 Sep 2004, 11:56
Location: Aschaffenburg, Germany

Re: Testing Function Speeds

Postby mathmoi » 15 Jul 2005, 15:06

Dann Corbit wrote:When I say profile, I mean use a profiler on your actual application.

Microsoft C++ has one, but it is hidden in the WIn32 SDK.

Intel has a dandy one called Vtune.

GCC has one called gprof.

If you do not profile the real routines you plan to use, and in the actual place that you intend to use them, then you will not know where effort needs to be spent to speed things up.

http://www.tarma.com/articles/index.htm ... 997nov.htm
http://www.johnpanzer.com/aci_cuj/
A nice free one for AMD chips:
http://developer.amd.com/downloads.aspx
You can always use gcc + gprof which works just about anywhere.


I'd like to add that there is one from compuware (DevPartner Profiler Community Edition : http://www.compuware.com/products/devpa ... r&sf=1&p=0). It's free (under some condition I think) and integrate itself into Visual Studio .Net. I never used any other profiler so I can not compare. I can only say this one seem easier to use than the others.

Mathieu Pag
mathmoi
 
Posts: 37
Joined: 30 Mar 2005, 21:23

Re: Testing Function Speeds

Postby Richard Allbert » 15 Jul 2005, 19:40

Again, thanks - it is downloading now.

I use the Bloodshed Dev-C++ compiler, and there is profiling support with it - I was amazed by the results.

Richard
Richard Allbert
 
Posts: 105
Joined: 27 Sep 2004, 11:56
Location: Aschaffenburg, Germany


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 28 guests