|
-
Jun 3rd, 2000, 06:24 PM
#1
Thread Starter
transcendental analytic
Ok, i did some tests on all timer methods, and here's the results. The querryperformance counter show the accurate rate of the loop of all updating procedures. All values shows next update in milliseconds.
The test shows that gettickcount is not accurate in ms as expected
Timer control results (Using getticount counter ~53ms)
8321936
8321991
8322102
8322156
8322211
8322265
8322322
8322376
8322431
8322486
8322542
8322594
8322652
8322707
8322762
8322816
8322872
8322926
8322981
8323037
8323092
8323146
8323206
8323255
8323301
8323311
8323347
8323366
Timer function results (Normal 50-60 ms)
49549990
49550040
49550090
49550150
49550200
49550260
49550310
49550370
49550420
49550480
49550530
49550590
49550640
49550700
49550750
49550810
49550860
49550920
49550970
49551030
49551080
49551140
49551190
49551250
49551300
49551360
49553830
49553880
49553940
Gettickcount results (Normal 4 - 6ms of 1 - 8)
8871806
8871810
8871815
8871818
8871820
8871825
8871826
8871834
8871835
8871840
8871846
8871850
8871855
8871861
8871865
8871870
8871876
8871882
8871886
8871890
8871895
8871900
8871905
8871910
8871916
8871920
8871925
8871930
8871936
8871940
QuerryPerformancecounter results (Results depends on cpu speed)
9146519,1681054
9146520,19644982
9146521,34631824
9146522,40315795
9146523,42731189
9146524,4833135
9146525,5183627
9146526,63722154
9146527,67897551
9146528,69977707
9146529,7264453
9146530,74892305
9146531,98176302
9146533,01765031
9146534,04515664
9146535,07433916
9146536,11441694
9146537,13102801
9146538,190382
9146539,22710739
9146540,2596423
9146541,96097823
9146543,12258
9146544,16517206
9146545,19938316
9146547,9801874
9146549,06887477
9146550,11230493
9146554,89615984
9146556,09463786
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 3rd, 2000, 07:49 PM
#2
PowerPoster
MultiMedia Timer
Hi Kedaman, I just read this from the Visual Basic
Programmer Journal article, With the MultiMedia Timer API
function, you can create your own Timer that fully code
base and it does give you the accuratecy up to 1ms.
All you need just write some code with the following API function.
Code:
Private Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
Private Declare Function timeEndPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
Private Declare Function timeGetDevCaps Lib "winmm.dll" (lpTimeCaps As TIMECAPS, ByVal uSize As Long) As Long
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long
Private Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As Long
For more information about this API function, you can always refer to the MSDN library ot just download the sample code at Visual Basic Progrmmer Journal with the Locator+ number VB0004. 
Currently I just play arround with this API function, It really cool.
-
Jun 3rd, 2000, 08:22 PM
#3
Thread Starter
transcendental analytic
Thanks! I'll do some new tests
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 4th, 2000, 02:04 AM
#4
Thread Starter
transcendental analytic
I got the wrong results with getticount in my last tests as the tests didn't update as well because of the timer, now these are correct results: Note the small difference with gettickcount(*) and timergettime(-).
Code:
All results are in µs
TIMER FUNCTION GETTICKCOUNT TIMEGETTIME QUERRYPERFORMANCE
77236610000 1601632000 1601632000 1601391142
77236610000 1601632000 1601632000 1601391245
77236610000 1601632000 1601632000 1601391306
77236610000 1601632000 1601632000 1601391365
77236610000 1601632000 1601633000 1601391434 -
77236610000 1601633000 1601633000 1601391494 *
77236610000 1601633000 1601633000 1601391554
77236610000 1601633000 1601633000 1601391613
77236610000 1601633000 1601633000 1601391670
77236610000 1601633000 1601633000 1601391728
77236610000 1601633000 1601633000 1601391787
77236610000 1601633000 1601633000 1601391845
77236610000 1601633000 1601633000 1601391903
77236610000 1601633000 1601633000 1601391961
77236610000 1601633000 1601633000 1601392019 +
77236610000 1601633000 1601633000 1601392078
77236610000 1601633000 1601633000 1601392136
77236610000 1601633000 1601633000 1601392193
77236610000 1601633000 1601633000 1601392251
77236610000 1601633000 1601633000 1601392310
77236610000 1601633000 1601633000 1601392368
77236610000 1601633000 1601634000 1601392427 -
77236610000 1601634000 1601634000 1601392484 *
77236610000 1601634000 1601634000 1601392543
77236610000 1601634000 1601634000 1601392602
77236610000 1601634000 1601634000 1601392659
77236610000 1601634000 1601634000 1601392717
77236610000 1601634000 1601634000 1601392775
77236610000 1601634000 1601634000 1601392834
77236610000 1601634000 1601634000 1601392891
77236610000 1601634000 1601634000 1601392949
77236610000 1601634000 1601634000 1601393008 +
77236610000 1601634000 1601634000 1601393065
77236610000 1601634000 1601634000 1601393124
77236610000 1601634000 1601634000 1601393181
77236610000 1601634000 1601634000 1601393239
77236610000 1601634000 1601634000 1601393296
77236610000 1601634000 1601634000 1601393355
77236610000 1601634000 1601635000 1601393415 -
77236610000 1601635000 1601635000 1601393472*
77236610000 1601635000 1601635000 1601393531
77236610000 1601635000 1601635000 1601393588
77236610000 1601635000 1601635000 1601393647
77236610000 1601635000 1601635000 1601393706
77236610000 1601635000 1601635000 1601393765
77236610000 1601635000 1601635000 1601393823
77236610000 1601635000 1601635000 1601393881
77236610000 1601635000 1601635000 1601393939+
77236610000 1601635000 1601635000 1601394004
77236610000 1601635000 1601635000 1601394063
77236610000 1601635000 1601635000 1601394120
77236610000 1601635000 1601635000 1601394178
77236610000 1601635000 1601635000 1601394237
77236610000 1601635000 1601635000 1601394296
77236610000 1601635000 1601635000 1601394364
77236610000 1601635000 1601636000 1601394423 -
77236610000 1601636000 1601636000 1601394481 *
77236610000 1601636000 1601636000 1601394539
77236610000 1601636000 1601636000 1601394595
77236610000 1601636000 1601636000 1601394654
77236610000 1601636000 1601636000 1601394712
77236610000 1601636000 1601636000 1601394770
77236610000 1601636000 1601636000 1601394828
77236610000 1601636000 1601636000 1601394885
77236610000 1601636000 1601636000 1601394943
77236610000 1601636000 1601636000 1601395001+
77236610000 1601636000 1601636000 1601395059
77236610000 1601636000 1601636000 1601395117
77236610000 1601636000 1601636000 1601395175
77236610000 1601636000 1601636000 1601395232
77236610000 1601636000 1601636000 1601395289
77236610000 1601636000 1601636000 1601395348
77236610000 1601636000 1601637000 1601395408 -
77236610000 1601637000 1601637000 1601395467 *
77236610000 1601637000 1601637000 1601395525
77236610000 1601637000 1601637000 1601395583
77236610000 1601637000 1601637000 1601395641
77236610000 1601637000 1601637000 1601395700
77236610000 1601637000 1601637000 1601395757
77236610000 1601637000 1601637000 1601395817
77236610000 1601637000 1601637000 1601395874
77236610000 1601637000 1601637000 1601395931
77236610000 1601637000 1601637000 1601395990
77236610000 1601637000 1601637000 1601396048 +
77236610000 1601637000 1601637000 1601396106
77236610000 1601637000 1601637000 1601396164
77236610000 1601637000 1601637000 1601396222
77236610000 1601637000 1601637000 1601396280
77236610000 1601637000 1601637000 1601396338
77236610000 1601637000 1601638000 1601396397 -
77236610000 1601638000 1601638000 1601396454 *
77236610000 1601638000 1601638000 1601396513
77236610000 1601638000 1601638000 1601396571
77236610000 1601638000 1601638000 1601396629
77236610000 1601638000 1601638000 1601396687
77236610000 1601638000 1601638000 1601396744
77236610000 1601638000 1601638000 1601396802
77236610000 1601638000 1601638000 1601396860
77236610000 1601638000 1601638000 1601396918
77236610000 1601638000 1601638000 1601396976
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 4th, 2000, 04:22 AM
#5
So in conclusion, the QuerryPerformancecounter is the best one to use???
-
Jun 4th, 2000, 05:48 AM
#6
Thread Starter
transcendental analytic
That's right Meg, Querryperformance is the best
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 4th, 2000, 06:11 AM
#7
Frenzied Member
what exactlywas the point of all those numbers?
-
Jun 4th, 2000, 06:23 AM
#8
Thread Starter
transcendental analytic
The point is... that all methods return different stuff, they are all converted to µs so it's easy to compare
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 4th, 2000, 06:43 AM
#9
Hmmm...If I make a cntrol usng Queryperformancecounter, than it'll be much faster than the regular VB timer?? Why didn't Microsoft think of this when they made VB?
-
Jun 4th, 2000, 07:54 AM
#10
Member
CCRP Timer?
Hi, those were interesting results.
Know anything about the CCRP High Performance Timer Objects, available free at http://www.mvps.org/CCRP? I've been using that for a while and it seems pretty accurate.
-
Jun 4th, 2000, 10:32 AM
#11
PowerPoster
Disagree with your test result.
Hi Kedaman, I was disagree with you test result, because i did the same Timer Function omparison as well and I found that the MultiMedia Timer API function really can go up to 1ms accuratecy.
Although the QueryPerformanceCounter and QueryPerformanceFrequency can go up to 1ms precision as well, but the refresh interval just a bit longer than the Multimedis Timer API.
Below just a summerize from the result that I get.
- SetTimer API - Accuratecy up to 10ms
- GetTickCount API - Accuratecy up to 10ms
- QueryPerformanceCounter API - Accuratecy up to 1ms
- MultiMedia Timer API - Accuratecy up to 1ms
- Timer Function - Accuratecy up to 1s
So, it is better to use the MultiMedia Timer API function. If and only if your program really need that precision. Else you can go for the QueryPerformanceCounter or GetTickCount API function.
Below is those API function that I used in my test procedure:
[code]
'SetTimer API
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
'GetTickCount Timer
Private Declare Function GetTickCount Lib "kernel32" () As Long
'QueryPerformaceCounter Timer
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
'MultiMedia Timer
Public Declare Function timeKillEvent Lib "winmm.dll" (ByVal uId As Long) As Long
Private Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As Long
Private Const TIME_ONESHOT = 0 ' program timer for single event
Private Const TIME_PERIODIC = 1 ' program for continuous periodic event
Private Const TIME_CALLBACK_FUNCTION = 0
Here is part of my test result for using various timer function and API to count for 3 second.
Code:
SetTimer GetTickCount QueryPerformance MultiMedia Timer Timer Function
------------------------------------------------------------------------------
11071159 11067824 11065 11061875 39788
11071169 11067824 11065 11061875 39788
11071179 11067824 11065 11061875 39788
11071189 11067824 11065 11061875 39788
11071199 11067824 11065 11061886 39788
11071209 11067824 11065 11061886 39788
11071219 11067824 11065 11061886 39788
11071229 11067824 11065 11061887 39788
11071239 11067824 11065 11061887 39788
11071249 11067824 11065 11061887 39788
11071259 11067824 11065 11061887 39788
11071269 11067824 11065 11061888 39788
11071279 11067824 11065 11061888 39788
11071289 11067824 11065 11061888 39788
11071299 11067824 11065 11061888 39788
11071309 11067824 11065 11061889 39788
11071319 11067824 11065 11061889 39788
11071329 11067824 11065 11061890 39788
11071339 11067824 11065 11061890 39788
11071349 11067824 11065 11061890 39788
11071359 11067824 11065 11061890 39788
11071369 11067824 11065 11061891 39788
11071379 11067824 11065 11061891 39788
11071389 11067824 11065 11061892 39788
11071399 11067834 11065 11061892 39788
11071409 11067834 11065 11061893 39788
11071419 11067834 11065 11061893 39788
11071429 11067834 11065 11061893 39788
11071439 11067834 11065 11061894 39788
11071449 11067834 11065 11061895 39788
11071459 11067834 11065 11061896 39788
11071469 11067834 11065 11061897 39788
11071479 11067834 11065 11061898 39788
11071489 11067834 11065 11061899 39788
11071499 11067834 11065 11061900 39788
11071509 11067834 11065 11061901 39788
11071520 11067834 11065 11061902 39788
11071530 11067834 11065 11061903 39788
11071540 11067834 11065 11061904 39788
11071550 11067854 11065 11061905 39788
11071560 11067854 11065 11061906 39788
11071570 11067854 11065 11061907 39788
11071580 11067854 11065 11061908 39788
11071590 11067864 11065 11061909 39788
11071600 11067864 11065 11061910 39788
11071610 11067864 11065 11061911 39788
11071620 11067864 11065 11061912 39788
11071630 11067864 11065 11061913 39788
11071640 11067864 11065 11061914 39788
11071650 11067864 11065 11061915 39788
11071660 11067864 11065 11061916 39788
11071670 11067864 11065 11061917 39788
11071680 11067864 11065 11061918 39788
11071690 11067864 11065 11061919 39788
11071700 11067864 11065 11061920 39788
11071710 11067864 11065 11061921 39788
11071720 11067864 11065 11061922 39788
11071730 11067864 11065 11061923 39788
11071740 11067874 11065 11061924 39788
11071750 11067874 11065 11061925 39788
11071760 11067874 11065 11061926 39788
11071770 11067874 11065 11061927 39788
11071780 11067874 11065 11061928 39788
11071790 11067874 11065 11061929 39788
11071800 11067874 11065 11061930 39788
11071810 11067874 11065 11061931 39788
11071820 11067874 11065 11061932 39788
11071830 11067874 11065 11061933 39788
11071840 11067874 11065 11061934 39788
11071850 11067874 11065 11061935 39788
11071860 11067874 11065 11061946 39788
11071870 11067884 11065 11061947 39788
11071880 11067884 11065 11061948 39788
11071890 11067884 11065 11061948 39788
11071900 11067884 11065 11061949 39788
11071910 11067884 11065 11061949 39788
11071920 11067884 11065 11061950 39788
11071930 11067884 11065 11061951 39788
11071940 11067884 11065 11061951 39788
11071950 11067884 11065 11061952 39788
11071960 11067904 11065 11061953 39788
11071970 11067904 11065 11061953 39788
11071980 11067904 11065 11061954 39788
11071990 11067904 11065 11061954 39788
11072000 11067904 11065 11061955 39788
11072010 11067904 11065 11061956 39788
11072020 11067914 11065 11061957 39788
11072030 11067914 11065 11061957 39788
11072040 11067914 11065 11061958 39788
11072050 11067914 11065 11061958 39788
11072060 11067914 11065 11061959 39788
11072070 11067914 11065 11061960 39788
11072080 11067914 11065 11061961 39788
11072090 11067914 11065 11061961 39788
11072100 11067914 11065 11061962 39788
11072110 11067914 11065 11061962 39788
11072120 11067914 11065 11061963 39788
11072130 11067914 11065 11061964 39788
11072140 11067924 11065 11061965 39788
11072150 11067924 11065 11061965 39788
11072160 11067924 11065 11061966 39788
11072170 11067924 11065 11061967 39788
11072180 11067924 11065 11061968 39788
11072190 11067924 11065 11061969 39788
11072200 11067924 11065 11061970 39788
11072210 11067924 11065 11061971 39788
11072221 11067924 11065 11061972 39788
11072231 11067924 11065 11061973 39788
11072241 11067924 11065 11061974 39788
11072251 11067924 11065 11061975 39788
11072261 11067934 11065 11061976 39788
11072271 11067934 11065 11061977 39788
11072281 11067934 11065 11061978 39788
11072291 11067934 11065 11061979 39788
11072301 11067934 11065 11061980 39788
11072311 11067934 11065 11061981 39788
11072321 11067934 11065 11061982 39788
11072331 11067934 11065 11061983 39788
11072341 11067934 11065 11061984 39788
11072351 11067934 11065 11061985 39788
11072361 11067934 11065 11061986 39788
11072371 11067954 11065 11061990 39788
11072381 11067954 11065 11061991 39788
11072391 11067954 11065 11061991 39788
11072401 11067954 11065 11061992 39788
11072411 11067954 11065 11061993 39788
11072421 11067954 11065 11061994 39788
11072431 11067954 11065 11061995 39788
11072441 11067964 11065 11061995 39788
11072451 11067964 11065 11061996 39788
11072461 11067964 11065 11061997 39788
11072471 11067964 11065 11061998 39788
11072481 11067964 11065 11061999 39788
11072491 11067964 11065 11062000 39788
11072501 11067964 11065 11062000 39788
11072511 11067964 11065 11062001 39788
11072521 11067964 11065 11062002 39788
11072531 11067964 11065 11062003 39788
11072541 11067964 11065 11062004 39788
11072551 11067964 11065 11062005 39789
11072561 11067974 11065 11062006 39789
11072571 11067974 11065 11062007 39789
11072581 11067974 11065 11062008 39789
11072591 11067974 11065 11062009 39789
11072601 11067974 11065 11062010 39789
11072611 11067974 11065 11062011 39789
11072621 11067974 11065 11062013 39789
11072631 11067974 11065 11062013 39789
11072641 11067974 11065 11062014 39789
11072651 11067974 11065 11062015 39789
11072661 11067984 11065 11062016 39789
11072671 11067984 11065 11062017 39789
11072681 11067984 11065 11062018 39789
11072691 11067984 11065 11062019 39789
11072701 11067984 11065 11062020 39789
11072711 11067984 11065 11062021 39789
11072721 11067984 11065 11062022 39789
11072731 11067984 11065 11062023 39789
11072741 11067984 11065 11062024 39789
11072751 11067984 11065 11062025 39789
11072761 11067994 11065 11062026 39789
11072771 11067994 11065 11062027 39789
11072781 11067994 11065 11062028 39789
11072791 11068004 11065 11062029 39789
11072801 11068004 11065 11062030 39789
11072811 11068004 11065 11062031 39789
11072821 11068004 11065 11062032 39789
11072831 11068004 11065 11062033 39789
11072841 11068004 11065 11062034 39789
11072851 11068004 11065 11062035 39789
11072861 11068004 11065 11062037 39789
11072871 11068004 11065 11062037 39789
11072881 11068004 11065 11062039 39789
11072891 11068014 11065 11062039 39789
11072901 11068014 11065 11062041 39789
11072912 11068014 11065 11062042 39789
11072922 11068014 11065 11062043 39789
11072932 11068014 11065 11062044 39789
11072942 11068014 11065 11062045 39789
11072952 11068014 11065 11062046 39789
11072962 11068014 11065 11062047 39789
11072972 11068014 11065 11062048 39789
11072982 11068024 11065 11062049 39789
11072992 11068024 11065 11062050 39789
11073002 11068024 11065 11062051 39789
11073012 11068024 11065 11062052 39789
11073022 11068024 11065 11062053 39789
11073032 11068024 11065 11062054 39789
11073042 11068024 11065 11062055 39789
11073052 11068024 11065 11062056 39789
11073062 11068024 11065 11062057 39789
11073072 11068034 11065 11062058 39789
11073082 11068034 11065 11062059 39789
11073092 11068034 11065 11062060 39789
11073102 11068034 11065 11062061 39789
11073112 11068034 11065 11062062 39789
11073122 11068034 11065 11062063 39789
11073132 11068034 11065 11062064 39789
11073142 11068034 11065 11062065 39789
11073152 11068034 11065 11062066 39789
11073162 11068034 11066 11062067 39789
11073172 11068045 11066 11062068 39789
11073182 11068045 11066 11062069 39789
11073192 11068045 11066 11062070 39789
11073202 11068045 11066 11062071 39789
11073212 11068045 11066 11062072 39789
11073222 11068045 11066 11062074 39789
11073232 11068055 11066 11062074 39789
11073242 11068055 11066 11062076 39789
11073252 11068055 11066 11062077 39789
11073262 11068055 11066 11062078 39789
11073272 11068055 11066 11062079 39789
11073282 11068055 11066 11062080 39789
11073292 11068055 11066 11062081 39789
11073302 11068055 11066 11062083 39789
11073312 11068055 11066 11062083 39789
11073322 11068065 11066 11062085 39789
11073332 11068065 11066 11062087 39789
11073342 11068065 11066 11062088 39789
11073352 11068065 11066 11062089 39789
11073362 11068065 11066 11062091 39789
11073372 11068065 11066 11062092 39789
11073382 11068065 11066 11062093 39789
11073392 11068065 11066 11062094 39789
11073402 11068075 11066 11062095 39789
11073412 11068075 11066 11062096 39789
11073422 11068075 11066 11062098 39789
11073432 11068075 11066 11062098 39789
11073442 11068075 11066 11062100 39789
11073452 11068075 11066 11062101 39789
11073462 11068075 11066 11062102 39789
11073472 11068075 11066 11062103 39789
11073482 11068075 11066 11062107 39789
11073492 11068085 11066 11062108 39789
11073502 11068085 11066 11062110 39789
11073512 11068085 11066 11062111 39789
11073522 11068085 11066 11062112 39789
11073532 11068085 11066 11062113 39789
11073542 11068085 11066 11062115 39789
11073552 11068085 11066 11062116 39789
11073562 11068085 11066 11062117 39789
11073572 11068095 11066 11062118 39789
11073582 11068095 11066 11062119 39789
11073592 11068095 11066 11062120 39789
11073602 11068095 11066 11062122 39789
11073613 11068095 11066 11062123 39789
11073623 11068095 11066 11062124 39789
11073633 11068095 11066 11062125 39789
11073643 11068105 11066 11062127 39789
11073653 11068105 11066 11062128 39789
11073663 11068105 11066 11062129 39789
11073673 11068105 11066 11062130 39789
11073683 11068105 11066 11062132 39789
11073693 11068105 11066 11062133 39789
11073703 11068105 11066 11062135 39789
11073713 11068105 11066 11062137 39789
11073723 11068115 11066 11062138 39789
11073733 11068115 11066 11062139 39789
11073743 11068115 11066 11062141 39789
11073753 11068115 11066 11062142 39789
11073763 11068115 11066 11062143 39789
11073773 11068125 11066 11062144 39789
11073783 11068125 11066 11062146 39789
11073793 11068125 11066 11062147 39789
11073803 11068125 11066 11062148 39789
11073813 11068125 11066 11062149 39789
11073823 11068125 11066 11062151 39789
11073833 11068125 11066 11062152 39789
11073843 11068135 11066 11062153 39789
11073853 11068135 11066 11062154 39789
11073863 11068135 11066 11062156 39789
11073873 11068135 11066 11062157 39789
11073883 11068135 11066 11062159 39789
11073893 11068135 11066 11062160 39789
11073903 11068135 11066 11062161 39789
11073913 11068135 11066 11062162 39789
11073923 11068145 11066 11062164 39789
11073933 11068145 11066 11062165 39789
11073943 11068145 11066 11062167 39789
11073953 11068145 11066 11062168 39789
11073963 11068145 11066 11062169 39789
11073973 11068145 11066 11062170 39789
11073983 11068155 11066 11062172 39789
11073993 11068155 11066 11062173 39789
11074003 11068155 11066 11062175 39789
11074013 11068155 11066 11062176 39789
11074023 11068155 11066 11062177 39789
11074033 11068155 11066 11062178 39789
11074043 11068155 11066 11062180 39789
11074053 11068155 11066 11062181 39789
11074063 11068165 11066 11062183 39789
11074073 11068165 11066 11062185 39789
11074083 11068165 11066 11062187 39789
11074093 11068165 11066 11062188 39789
11074103 11068165 11066 11062190 39789
11074113 11068165 11066 11062191 39789
11074123 11068175 11066 11062192 39789
11074133 11068175 11066 11062194 39789
11074143 11068175 11066 11062195 39789
11074153 11068175 11066 11062196 39789
-
Jun 4th, 2000, 12:17 PM
#12
Fanatic Member
Kedaman,
On the weekend I worked on that performace program I mentioned in the "Inline Function" thread.
When I get a bit more done I'll post the code, so far the results are very interesting.
The Results so far look like this
FASTEST
Module Sub
Form Sub
Module Function
Foreign Form Sub
Class Sub
Form Function
Foreign Form Function
Class Function
SLOWEST
With Class functions taking 10x the time of a Module Sub.
And Form Subs taking 5 times a Module Sub
Foreign form Subs and functions are calling subs and functions from other open forms in the same app, they are are pretty close to class subs and forms in speed (not surprisingly)
I'm working on the Data Types comparison still and I'll have the code up this week, so people can suggest improvements. (with reports and graphs)
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jun 4th, 2000, 05:40 PM
#13
Thread Starter
transcendental analytic
Chris, there must be something fundamentally wrong with your testing methods
SetTimer API - Accuratecy up to 10ms
GetTickCount API - Accuratecy up to 10ms
QueryPerformanceCounter API - Accuratecy up to 1ms
MultiMedia Timer API - Accuratecy up to 1ms
Timer Function - Accuratecy up to 1s
Here are the correct results:
SetTimer API - Accuratecy up to 50-60ms (same as timer control)
GetTickCount API - Accuratecy up to 1ms
QueryPerformanceCounter API - Accuratecy up to 1µs = 0.001 ms(depending on machine)
MultiMedia Timer API - Accuratecy up to 1ms
Timer Function - Accuratecy up to 53 ms
If what you think timer returns a value in seconds, must be accurate in 1s, you're wrong, timer updates with it's decimals each ~53 second. Gettickcount is 1ms, no doubt now. Querryperformance: use CDBL to convert the division between the currency values to a floating point or you wont get a correct value. Settimer is the same as timer control.
Paul
HEhe, i know exactly why the class is slowest, but i thought that (foreign) form and class would be on the same place as they are both classes. But Module faster than function in the same form? Hmm, can you show me the results`?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 4th, 2000, 05:49 PM
#14
PowerPoster
MSDN Library
hi, kedaman, I don't think my test result got problem, because I just double check with MSDN library and the result does the same with mine:
Code:
HOWTO: Use QueryPerformanceCounter to Time Code
ID: Q172338
--------------------------------------------------------------------------------
The information in this article applies to:
Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions for Windows, version 5.0
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0
Microsoft Access versions 7.0, 97
Microsoft Excel for Windows 95, version 7.0
Microsoft Excel 97 for Windows
Microsoft Word for Windows
--------------------------------------------------------------------------------
SUMMARY
When timing code to identify performance bottlenecks, you want to use the highest resolution timer the system has to offer. This article describes how to use the QueryPerformanceCounter function to time application code.
MORE INFORMATION
Several timers of differing accuracy are offered by the operating system:
Code:
Function Units Resolution
---------------------------------------------------------------------------
Now, Time, Timer seconds 1 second
GetTickCount milliseconds approx. 10 ms
TimeGetTime milliseconds approx. 10 ms
QueryPerformanceCounter QueryPerformanceFrequency same
If your system supports a high-resolution counter, you can use QueryPerformanceCounter and QueryPerformanceFrequency to do high-resolution timings.
The following sample code compares the various counters:
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
Step-by-Step Procedures
Enter the following code into a Module. If you enter it into a class, form, or report module, make the declarations Private.
Option Explicit
Declare Function QueryPerformanceCounter Lib "Kernel32" _
(X As Currency) As Boolean
Declare Function QueryPerformanceFrequency Lib "Kernel32" _
(X As Currency) As Boolean
Declare Function GetTickCount Lib "Kernel32" () As Long
Declare Function timeGetTime Lib "winmm.dll" () As Long
Sub Test_Timers()
Dim Ctr1 As Currency, Ctr2 As Currency, Freq As Currency
Dim Count1 As Long, Count2 As Long, Loops As Long
'
' Time QueryPerformanceCounter
'
If QueryPerformanceCounter(Ctr1) Then
QueryPerformanceCounter Ctr2
Debug.Print "Start Value: "; Format$(Ctr1, "0.0000")
Debug.Print "End Value: "; Format$(Ctr2, "0.0000")
QueryPerformanceFrequency Freq
Debug.Print "QueryPerformanceCounter minimum resolution: 1/" & _
Freq * 10000; " sec"
Debug.Print "API Overhead: "; (Ctr2 - Ctr1) / Freq; "seconds"
Else
Debug.Print "High-resolution counter not supported."
End If
'
' Time GetTickCount
'
Debug.Print
Loops = 0
Count1 = GetTickCount()
Do
Count2 = GetTickCount()
Loops = Loops + 1
Loop Until Count1 <> Count2
Debug.Print "GetTickCount minimum resolution: "; _
(Count2 - Count1); "ms"
Debug.Print "Took"; Loops; "loops"
'
' Time timeGetTime
'
Debug.Print
Loops = 0
Count1 = timeGetTime()
Do
Count2 = timeGetTime()
Loops = Loops + 1
Loop Until Count1 <> Count2
Debug.Print "timeGetTime minimum resolution: "; _
(Count2 - Count1); "ms"
Debug.Print "Took"; Loops; "loops"
End Sub
Run the function from the Debug/Immediate window. Your output should appear similar to the following:
Start Value: 3516284.3498
End Value: 3516284.3521
QueryPerformanceCounter minimum resolution: 1/1193182 sec
API Overhead: 1.92761875388667E-05 seconds
GetTickCount minimum resolution: 10 ms
Took 650 loops
timeGetTime minimum resolution: 10 ms
Took 1565 loops
Multiple statements execute before either GetTickCount or timeGetTime record a change. The actual number of loops will vary depending on the background tasks the operating system is executing.
On the other hand, QueryPerformanceCounter changes value between successive API calls, indicating its usefulness in high-resolution timing. The resolution in this case is on the order of a microsecond. Because the resolution is system-dependent, there are no standard units that it measures. You have to divide the difference by the QueryPerformanceFrequency to determine the number of seconds elapsed. In the case above, the overhead for just calling the API is about 19 microseconds. This would have to be subtracted when timing other code as follows:
Private Sub Time_Addition()
Dim Ctr1 As Currency, Ctr2 As Currency, Freq As Currency
Dim Overhead As Currency, A As Long, I As Long
QueryPerformanceFrequency Freq
QueryPerformanceCounter Ctr1
QueryPerformanceCounter Ctr2
Overhead = Ctr2 - Ctr1 ' determine API overhead
QueryPerformanceCounter Ctr1 ' time loop
For I = 1 To 100
A = A + I
Next I
QueryPerformanceCounter Ctr2
Debug.Print "("; Ctr1; "-"; Ctr2; "-"; Overhead; ") /"; Freq
Debug.Print "100 additions took";
Debug.Print (Ctr2 - Ctr1 - Overhead) / Freq; "seconds"
End Sub
Sample output:
( 3630876.6256 - 3630876.6388 - 0.0013 ) / 119.3182
100 additions took 9.97333181358753E-05 seconds
NOTE: Because currency variables are used, the values returned are 10000 times smaller than the actual counters. Because the calculation of seconds involves a division operation, this factor is cancelled out.
REFERENCES
Microsoft Developer Network; topics: timeGetTime GetTickCount QueryPerformanceCounter QueryPerformanceFrequency
Additional query words:
Keywords : kbprg kbVBp400 kbVBp500 kbhowto VB4WIN VBKBWinAPI vbwin
Version : WINDOWS:4.0,5.0,7.0,97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: October 11, 1999
?1999 Microsoft Corporation. All rights reserved. Terms of Use.
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
-
Jun 4th, 2000, 05:54 PM
#15
Fanatic Member
I'll send you them when I get home from work tonight (in about 4 hrs)
to be sure of the results I have added a config form so you can set the number of loops and the number of times to run that number of loops and average the data.
Usually about 2,000,000 loops run 10 times to each sub or function type (8 types) and the results averaged for each type.
A module was a long way ahead of the competition, although in real time, even a class function is pretty quich, ie, you'd have to be doing encryption, or compression or bruteforcing a decision to need the time difference.
I'll send you the project tonight, the data-types bit is only 1/4 coded but the function/subs section is done and it graphs well.
I used GetTickCount for the timing but to be honest, it wasn't really necessary.
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jun 4th, 2000, 05:56 PM
#16
Fanatic Member
I read documents on the net last week that had test resuld for Timer as 55-60milisecs
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jun 4th, 2000, 06:05 PM
#17
PowerPoster
SetTimer API
But there was a parameter under the SetTimer API function call uElapse wich can take value upto 1ms.
I did set this value, but when I run the test, it return the tickcount to me is about 10ms different.
Code:
SetTimer
The SetTimer function creates a timer with the specified time-out value.
UINT_PTR SetTimer(
HWND hWnd, // handle to window
UINT_PTR nIDEvent, // timer identifier
UINT uElapse, // time-out value
TIMERPROC lpTimerFunc // timer procedure
);
Parameters
hWnd
[in] Handle to the window to be associated with the timer. This window must be owned by the calling thread. If this parameter is NULL, no window is associated with the timer and the nIDEvent parameter is ignored.
nIDEvent
[in] Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored. If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer.
uElapse
[in] Specifies the time-out value, in milliseconds.
lpTimerFunc
[in] Pointer to the function to be notified when the time-out value elapses. For more information about the function, see TimerProc.
If lpTimerFunc is NULL, the system posts a WM_TIMER message to the application queue. The hwnd member of the message's MSG structure contains the value of the hWnd parameter.
-
Jun 4th, 2000, 06:15 PM
#18
Thread Starter
transcendental analytic
Well, chris that's what's wrong, that's exactly what is wrong, my first test was done in the debug window, and the timing got totally wrong with both gettickcount and querryperformance. My new results shows that querryperformance updates as fast as your computer allow it, which is on mine about 1µs.
If it is microsoft that have taught you that i have to prove them wrong also:
NOTE: Because currency variables are used, the values returned are 10000 times smaller than the actual counters. Because the calculation of seconds involves a division operation, this factor is cancelled out.
Code:
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
Dim start@, finish@, freq@
QueryPerformanceCounter start
'..timeinterval
QueryPerformanceCounter finish
QueryPerformanceFrequency freq
Interval = CDbl(finish - start) / CDbl(freq)
Try this out as It will do the division between two floating points!
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 4th, 2000, 06:52 PM
#19
Hyperactive Member
Class v Module
Unless I'm really crap at reading, there was no indication as to why a class function was slower than a module function. I'd really like to know why . . .
I learn an unbelievable amount of stuff in these forums, but I think that it principally helps me learn more on my own ... springboard stylee!
-
Jun 4th, 2000, 07:06 PM
#20
Fanatic Member
Calls to objects and classes in VB comes with a certain overhead. More so in VB than in other languages there is a cost for OO implementation. Most of the ducumentation I've read suggests that classes in VB needs a bit more work, both in implemented functionality and performance.
The tests I ran show that while they're slower than module code, they're still pretty fast, (definately worth using).
So to summerise:
Modules are faster than forms which are slighly faster than classes
and
Subs are quite a bit faster than functions.
That surprised be, I expected them to be about the same.
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jun 4th, 2000, 07:23 PM
#21
Thread Starter
transcendental analytic
Paul, could you do a table of tests, on arguments passed to functions and subs, and also properties, Integer, Long, Single, Double, Currency, String and Variant is enough.
That would be great.
Also, how can a form be faster than a classmodule? That's one thing i don't get.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 4th, 2000, 07:30 PM
#22
Fanatic Member
Well, I'm outa here in a few minutes so when you get the project you can test it yourself.
maybe there is a bug in my code, or a flaw in the idea for the design
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jun 4th, 2000, 07:44 PM
#23
Thread Starter
transcendental analytic
Here's my code for the second tests, if you can find a flaw in it, i'm happy to know...
Code:
Sub main()
Dim a@(100, 3), n&
For n = 0 To 100
DoEvents
a(n, 0) = Timer * 1000000
a(n, 1) = GetTickCount * 1000
a(n, 2) = timeGetTime * 1000
QueryPerformanceCounter d@
QueryPerformanceCounter b@
QueryPerformanceFrequency c@
a(n, 3) = Int(CDbl(b@) / CDbl(c@) * 1000000)
Next n
For n = 0 To 100
Debug.Print a(n, 0), a(n, 1), a(n, 2), a(n, 3)
Next n
End Sub
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 4th, 2000, 08:07 PM
#24
Thread Starter
transcendental analytic
Chris, how do I use the timeSetEvent and timeKillEvent? I keep crashing Vb when I use those. I need an event to be fired in each 5'th ms. As i can't do that with settimer and killtimer
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 4th, 2000, 09:20 PM
#25
Fanatic Member
Kedaman, (And anyone interested)
Here's the project zipped
http://www.ozemail.com.au/~devore/Perform.zip
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jun 5th, 2000, 06:25 AM
#26
Maybe we should send these results to vbapi.com and they can post up these new substitutes for the Timer Control.
-
Jun 5th, 2000, 07:20 AM
#27
PowerPoster
QueryPerformanceCounter & QueryPerformanceFrequency API
Hi! Kedaman, I just refer back the book that I've bought (Visual Basic With Win32 API By Jason Bock (Wrox Publisher) and I found that my test program did have some problem in the QueryPerformanceCounter and QueryPerformanceFrequency API function.
According to that book, he said that the QueryperformanceCounter and QueryPerformanceFrequency can have the precision upto nanosecond which you did mention before and you're rite. 
For my testing, I did each API function seperately instead of all together.
Here is my SetTimer and KillTimer API function call hope I did made any mistake in the test routine. 
Code:
Option Explicit
Private T1&, T2&, dl&
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public Sub load_SetTimer()
SetTimer frmMain.hwnd, 0, 1, AddressOf TimerProc
T1 = GetTickCount
frmMain.cmdAction(0).Enabled = False
End Sub
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
If T2 - T1 < 3000 Then
T2 = GetTickCount
frmMain.txtOutput(0).Text = frmMain.txtOutput(0).Text & T2 & vbCrLf
Else
KillTimer frmMain.hwnd, 0
End If
End Sub
and this the test routine for the timeSetEvents and timeKillEvents
[code]
Public Declare Function timeKillEvent Lib "winmm.dll" (ByVal uId As Long) As Long
Private Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As Long
Private Const TIME_PERIODIC = 1 ' program for continuous periodic event
Private Const TIME_CALLBACK_FUNCTION = 0
Public mTimerID&
Public Sub load_MultiMediaTimer()
mTimerID = timeSetEvent(1, 0, AddressOf OnTimer, 0, TIME_CALLBACK_FUNCTION Or TIME_PERIODIC)
T1 = timeGetTime
End Sub
Private Sub OnTimer(ByVal uId As Long, ByVal uMsg As Long, ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long)
If T2 - T1 < 3000 Then
T2 = timeGetTime
frmMain.txtOutput(3).Text = frmMain.txtOutput(3).Text & T2 & vbCrLf
Else
timeKillEvent mTimerID
End If
End Sub
-
Jun 5th, 2000, 04:21 PM
#28
Thread Starter
transcendental analytic
Thanks Chris, i'm going to test the new events
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|