Author: Tony Werten
Date: 08:01:20 02/27/03
Go up one level in this thread
On February 27, 2003 at 07:44:19, Uri Blass wrote:
>On February 27, 2003 at 05:23:25, Tony Werten wrote:
>
>>On February 26, 2003 at 14:04:16, Uri Blass wrote:
>>
>>>I had the following code in my program
>>>
>>>do
>>>{
>>>...
>>>if (info[target]==EMPTA)
>>> target+=8;
>>>else
>>> target=64;
>>>}
>>>while (target<64)
>>
>>Less branches:
>>
>>do
>>{
>>...
>> tmp:=(info[target]!=EMPTY); // maybe typecast to int ?
>> target+=(tmp*256)+8;
>>} while (target<64);
>>
>>if (target>256) target=64;
>>
>>
>>But I'm not sure if this works in C. (In pascal compares are garantied to return
>>0 or 1 )
>
>It works in C(except the fact that I need to use a varaible for tmp)
>
>I even do not need the last if (target>256) target==64 because target is not
>used after the loop but I am not sure if it makes me faster.
>
>I have many similiar loops and by comparing times by changing one loop
>I find that it is even slightly slower.
>
>I used a global varaible for tmp because if I use a local caraible that I need
>to define at the beginning of the function then it means that I need to change
>all the similiar functions in order to practically use it.
Using a global variable will make it slower. IIRC they wil not be loaded in a
register but stay in main memory. This would mean you get the slowdown of
loading it in cache.
Using it as a local variable will normally not slow you down, except if the
function doesn't have any other local variables because now a stack frame will
need to be set up.
Tony
>
>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.