|
测试程序代码
- #include<hgl/hgl.h>
- #include<hgl/Other.H>
- #include<stdio.h>
- #include<stdlib.h>
-
- using namespace hgl;
- void GameMain(int,wchar_t **)
- {
- int n=10;
- uint32 start,end;
- uint32 rand_time,fast_time;
-
- wprintf(L"%8s %8s %s\n",L"rand",L"FastRand",L".75-1.25");
- wprintf(L"--------||--------||--------\n");
-
- while(n--)
- wprintf(L"%8X %8X %.3f\n",rand(),FastRand(),FastRand(0.75f,1.25f,0.001f));
-
- wprintf(L"--------||--------||--------\n");
-
- const int TEST_TIME=10000000;
-
- {
- n=TEST_TIME;
-
- start=GetTime();
- while(n--)
- rand();
- end=GetTime();
-
- wprintf(L"rand() time= %d\n",rand_time=end-start);
- }
-
- {
- n=TEST_TIME;
-
- start=GetTime();
- while(n--)
- FastRand();
- end=GetTime();
-
- wprintf(L"FastRand() time= %d\n",fast_time=end-start);
- }
-
- wprintf(L"pos=%f\n",float(rand_time)/float(fast_time));
- }
-
- 测试结果
-
- rand FastRand .75-1.25
- --------||--------||--------
- 425D F262A43 1.041
- 4B44 88AE98A9 0.877
- 7E01 E04B2B74 0.848
- 35A6 893E5AE2 1.091
- 2621 7C31B9AF 1.106
- 4F29 B861C5D4 1.059
- 55CC CDED8B91 0.813
- 2DF1 AAC0E987 0.902
- 5450 69B51CCA 1.196
- 5A26 B941797B 0.842
- --------||--------||--------
- rand() time= 1828
- FastRand() time= 236
- pos=7.745763
复制代码 |
|