Author: Gareth McCaughan
Date: 16:25:48 04/10/03
Go up one level in this thread
Robert Hyatt wrote: >before: > >if (wtm == 1) > score+=bonus1 >else > score+=bonus2; > >You could turn that into: > >score+=wtm*bonus1 + (wtm^1)*bonus2; > >the new code does more work, but has no branch to mispredict. Possibly better, because integer multiplication can be slow: score += bonus2 + ((wtm-1)&(bonus1-bonus2)) Here are some rather meaningless timings for executing various versions of this statement in a loop. There's some overhead, and the purpose of the first line in the table (which is of course not equivalent to the others) is to give some idea of how much overhead there is. Times are in seconds, but I'm deliberately not saying how many iterations or what sort of machine (except that it's an Athlon) because it's only the relative results that mean anything. 0.228 | score += wtm; 0.464 | score += bonus2 + ((wtm-1)&(bonus1-bonus2)); 0.529 | score += wtm?bonus1:bonus2; 0.532 | score += bonus2 + wtm*(bonus1-bonus2); 0.951 | score += wtm*bonus1 + (wtm^1)*bonus2; -- g
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.