Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: question about optimizing code

Author: Uri Blass

Date: 04:37:52 07/07/03

Go up one level in this thread


On July 07, 2003 at 03:48:43, Tim Foden wrote:

>On July 06, 2003 at 23:25:00, Uri Blass wrote:
>
>>In movei I have a number between 0 and 255 and I want to do some functions for
>>every 1 that it has in its binary representation(number of functions to
>>implement is the same as the number of 1's in the number and there is a
>>different function based on the value of the 1)
>>
>>I do not like to call functions because functions use local varaibles and
>>generating a copy of the local varaibles only to forget them may take computer
>>time and I also do not use the functions more than once.
>>
>>I thought to use switch(see the code later in this post) but the problem is that
>>switch continue to do everything without break and I want to have switch that
>>does not continue to do everything but does not quit and simply forget about the
>>fact that I called switch.
>>
>>Here is the type of the code that I plan to have now.
>>I do not like all the if (number&2) or if (number&4) and the question is if I
>>can do it faster.
>>
>What's wrong with doing a loop with a switch inside, Uri?
>
>For example:
>
>while( number )
>{
>    i=smallestpower[number];
>    switch(i)
>    {
>       case 0:do list of commands
>              break;
>
>       case 1:do list of commands
>              break;
>
>       case 2:do list of commands
>              break;
>
>       case 3:do list of commands
>              break;
>
>       case 4:do list of commands
>              break;
>
>       case 5:do list of commands
>              break;
>
>       case 6:do list of commands
>              break;
>
>       case 7:do list of commands
>              break;
>    }
>
>    number ^= (1 << i);
>}
>
>Cheers, Tim.

I thought about this but the problem is that in case that the loop is done more
than once I waste time by checking case 0 again.

Maybe it is the best solution because often the loop is going to be done at most
once and I will calculate some statistic about it from the opening position.

Uri



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.