Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: random book moves/ random generator

Author: Andrew Dados

Date: 08:47:59 01/14/00

Go up one level in this thread


On January 14, 2000 at 03:27:24, Tom Kerrigan wrote:

>I just ran the program below with Visual C++ 5.0 and Windows 98. It runs for 10
>seconds and counts how many times GetTickCount() changes. In 10 seconds, it
>changed 2001 times, indicating that it changes every 5 ms. This is fine and
>good, but it does not explain how I can get the following analysis, also using
>GetTickCount():
>
>position 002
>Position: 8/7p/5k2/5p2/p1p2P2/Pr1pPK2/1P1R3P/8 b - - 0 1
>Solution(s): Rxb2
>ply        time       nodes   score  pv
> 1.       0.008          24    0.20  Ke6
> 2+       0.013         156    0.70  Ke6 e4
> 2.       0.015         232    0.94  c3 bxc3 ...
> 3.       0.017         341    0.94  c3 bxc3 ...
> 4.       0.023         868    0.91  c3 bxc3 ...
> 5.       0.029        2024    0.92  c3 bxc3 ...
> 6.       0.050        5822    0.82  c3 bxc3 ...
> 7.       0.073       12050    0.93  c3 bxc3 ...
>
>-Tom
>
>
>/* begin GetTickCount() test program */
>#include <stdio.h>
>#include <windows.h>
>
>void main()
>{
>	int t, stop, old, ticks = 0;
>
>	old = GetTickCount();
>	stop = old + 10000;
>	for (;;) {
>		t = GetTickCount();
>		if (t != old) {
>			++ticks;
>			if (t > stop)
>				break;
>			old = t;
>		}
>	}
>	printf("ticks: %d\n", ticks);
>	getc(stdin);
>}

 Well all that code actually explains is that sleep(0) has some minimal time
slice, that's it. I was bugged with GetTickCount for a while, and can confirm,
that while under win 3 it does use 'old dos' 18.2 frequency, win 95/98 gives
accuracy around 1/1000. Btw.. Microsoft advised long time ago to use timer from
multimedia module for more accurate timing.

   For nanosecond accuracy you can use RDTSC asm instruction to read internal
64bit chip tick counter, which is great for profiling even shortest code
parts/calls. (That for Pentium and AMD K6, not sure about other processors)
Under windoze you need to enable it though with sequence, like:
asm
mov eax,cr4
or eax,32         {Enable TSD bit}
mov cr4,eax
end;
otherwise it will give you protection error.

I am sure RDTSC instruction, which loads eax:edx with 'ticks from reset' number
can be also used in random generator and is way faster then any system call...

-Andrew-



This page took 0.02 seconds to execute

Last modified: Thu, 07 Jul 11 08:48:38 -0700

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