I just made a wonderful discovery! The D version is in fact only 7 percent slower than C.
Earlier I mentioned the ONLY difference was the random number generator - well it turns out the random number generator was a big deal. The Mersenne twister is apparently far faster than the D library random number generator I was previously using. I could not believe the difference, So I wrote a tight loop to generate random numbers the same number of times the program does and compared the MT to the library routine. There was about a 5 second difference, almost the same as the difference in the run-times of the 2 versions. I still couldn't believe this, so did some sanity checks to make sure the random numbers were properly distributed. I basically generated a few million, put them in a file and did sort numbers.txt | uniq -c which counts how many times each number appeared - I used the randInt function to get numbers between 0 and 100. I was getting a very nice distribution - no easily detectable bugs that would cause the anomolies. Also, I was getting the very same average number of moves per game - a relatively good indication it's all working properly (and how I found a previous bug.) So it appears that D is perfectly usable as a very fast compiled programming language, at least as compared to gcc with all the optimizations I know to do. - Don On Thu, 2006-12-07 at 12:28 -0500, Don Dailey wrote: > In fact, I just wrapped this up into my Mersenne twister code - randInt > is now built in to the library and I eliminated the function call > overhead of calling rand() (or the mersenne equivalent.) Probably won't > make a noticeable difference, but since I'm porting it to D anyway, I > might as well fix this. > > - Don > > > On Thu, 2006-12-07 at 12:12 -0500, Don Dailey wrote: > > On Thu, 2006-12-07 at 16:05 +0100, Ćukasz Lew wrote: > > > ii = pm::rand () % empty_v_cnt; // TODO improve speed "%" > > > > > > Try this, I think it could be faster, not sure, but has the advantage > > that it's slightly more correct. > > > > // returns an integer between 0 and n-1 inclusive > > // > > unsigned long randint(unsigned long n) > > { > > unsigned long v = n; > > unsigned long r; > > > > v--; > > v |= v >> 1; > > v |= v >> 2; > > v |= v >> 4; > > v |= v >> 8; > > v |= v >> 16; > > > > do { r = rand(); } while ( (r & v) >= n ); > > > > return( r & v ); > > } > > > > > > > > - Don > > > > > > _______________________________________________ > > computer-go mailing list > > computer-go@computer-go.org > > http://www.computer-go.org/mailman/listinfo/computer-go/ > > _______________________________________________ > computer-go mailing list > computer-go@computer-go.org > http://www.computer-go.org/mailman/listinfo/computer-go/ _______________________________________________ computer-go mailing list computer-go@computer-go.org http://www.computer-go.org/mailman/listinfo/computer-go/