Author: Mikael Bäckman
Date: 05:01:48 01/09/04
Go up one level in this thread
On January 09, 2004 at 06:46:00, Tord Romstad wrote: >By reading this forum, I've understood that "if" statements are considered >evil and that it is often a good idea to remove them if it is possible. Suppose >that I have code which looks like this: > >if(x) y += 20; > >Would it then be advantageous to rewrite the code like this? > >y += (!(!x))*20; > >In my evaluation function, I have a lot of conditionals which could be avoided >by >using tricks similar to the one above, but before doing it I would like to make >sure it is really a good idea. After all, the first form above is much more >readable. > >Tord There is only one sure way to know if it is worthwhile or not. That is to benchmark the program before and after the changes. I used to do this for my movegen, attacktablegen, eval, pawnstructure eval, etc. I was a bit obsessed with NPS, but I recently added SEE to my engine and lost 28% nps, but gained 1-2 plies. :-) I learned a lesson here. The eval in Chepla is small and simple, when I got rid of the ifs and joined a few functions together into an unreadable mess, I got a whopping 3% NPS increase! I use lazy-eval, so the optimized code wasn't even run in 80% of the eval calls. I'm now back to using my old and more readable eval code. :) /Mikael
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.