Timer resolution

Questions regarding syntax

Timer resolution

Postby eve » Tue Sep 14, 2010 8:38 am

Gentleman,

I'am sniffling around KBasic for a few days now. Purpose is to port a rather big VB6 application to KBasic.
Something I could not find is the resolution of the timer.

Is it possible with KBasic to mesure incoming events to the ms exactly ? (In VB6 I had to use third party functions.)

Erik
eve
 
Posts: 5
Joined: Tue Sep 14, 2010 8:29 am

Re: Timer resolution

Postby berndnoetscher » Tue Sep 14, 2010 11:54 am

Qt says:
The QTimer's accuracy depends on the underlying operating system and hardware. Most platforms support an accuracy of 1 millisecond.
berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: Timer resolution

Postby pappawinni » Tue Sep 14, 2010 6:12 pm

Hi Erik,

I tested a bit under Windows 7 (Pentium Dual-Core CPU 2.0 GHz)
Seems here I get a timer resolution of about 1/60 second.
There seems to be a posiblity to change but this means changing a windows overall setting - which means switching processes more often.

/Winni

4
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany

Re: Timer resolution

Postby pappawinni » Thu Sep 16, 2010 6:24 pm

Below an example for Output of Windows System time

Part of the results normal on my system :
2010-9-16 4 18:14:29.328
2010-9-16 4 18:14:29.328
2010-9-16 4 18:14:29.343
2010-9-16 4 18:14:29.343
2010-9-16 4 18:14:29.343
2010-9-16 4 18:14:29.343
2010-9-16 4 18:14:29.343
2010-9-16 4 18:14:29.343
2010-9-16 4 18:14:29.343
2010-9-16 4 18:14:29.359
There you see the reason why a timer resolution is about 1/60 second.
Windows obviosly switched to the applications process in 15 to 16 milliseconds.
Again. There are Windows functions to (temporarily) speed up the process switching.
timeBeginPeriod() and timeEndPeriod()

By using that the result improves:
2010-9-16 4 20:38:40.740
2010-9-16 4 20:38:40.741
2010-9-16 4 20:38:40.745
2010-9-16 4 20:38:40.746
2010-9-16 4 20:38:40.749
2010-9-16 4 20:38:40.751
2010-9-16 4 20:38:40.754
2010-9-16 4 20:38:40.755
But anyway - I think - the result will be depend on how many processes running.

Code: Select all
Type SYSTEMTIME
  wYear As short
  wMonth As short
  wDayOfWeek As short
  wDay As short
  wHour As short
  wMinute As short
  wSecond As short
  wMilliseconds As short
End Type


Declare Sub GetSystemTime Lib "kernel32.dll" (lpSystemTime As SYSTEMTIME)
Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod As integer) As integer
Declare Function timeEndPeriod Lib "winmm.dll" (ByVal uPeriod As integer) As integer
/*
see the difference with and without
timeBeginPeriod(1)
timeEndPeriod(1)

http://gpwiki.org/index.php/VB:Timers
*/


Sub Main()
  Dim I As Integer
  Dim strC as string
  Dim stmT1 as SYSTEMTIME
 
 
  timeBeginPeriod(1)
  log "Increased Frequence"
 
  For I = 1 to 20
    GetSystemTime(stmT1)
    log ( stmT1.wYear & "-" & stmT1.wMonth & "-" & stmT1.wDay & " " & stmT1.wDayOfWeek & " " & _
          stmT1.wHour & ":" & stmT1.wMinute & ":" & stmT1.wSecond & "." & stmT1.wMilliseconds )
  next
 
  timeEndPeriod(1)
  log "Normal Frequence"
 
  For I = 1 to 20
    GetSystemTime(stmT1)
    log ( stmT1.wYear & "-" & stmT1.wMonth & "-" & stmT1.wDay & " " & stmT1.wDayOfWeek & " " & _
          stmT1.wHour & ":" & stmT1.wMinute & ":" & stmT1.wSecond & "." & stmT1.wMilliseconds )
  next
 

 
  ? "Press any key to continue.."
  do
    strC = inkey
  loop while strC = ""
end sub

Main()


3
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany

Re: Timer resolution

Postby eve » Sat Oct 02, 2010 9:31 am

Hi Pappawini,

I read a little bit more about timers and timing in KBasic. It seems that CurrentTime() returns the time since computer-start-up in ms.

Now CurrentTime() is a Long. I get a error : due to limitations in C my computer cannot work with Longs ?????

Erik
eve
 
Posts: 5
Joined: Tue Sep 14, 2010 8:29 am

Re: Timer resolution

Postby Slowdown » Sat Oct 02, 2010 4:49 pm

Hi Erik,

Your computer can work with 'Longs' KBasic doesn't and in this case you don't need it.
Code: Select all
  Dim StartTime as Integer
 
  StartTime = Timer
  print StartTime

Will do the job and StartTime is declared as Integer.
In KBasic CurrentTime() isn't used for for time functions.
You can look at,
Time, Time$
Timer
Now (returns present Date and Time)
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: Timer resolution

Postby eve » Sat Oct 02, 2010 6:12 pm

Hi Slowdown,

Thank you for replying.
Your suggestion is OK, but I need defintely a precise time measurement with a ms resolution...
In BASIC 2008 I found functions that go to ns : but since I have bad experience with the portability...
I was hoping to find a solution in KBasic.

Erik
eve
 
Posts: 5
Joined: Tue Sep 14, 2010 8:29 am

Re: Timer resolution

Postby Slowdown » Sun Oct 03, 2010 7:08 am

Hi Erik,
I understand what you mean.
Just a suggestion, perhaps not the solution.
Attachments
Timer.zip
(1.12 KiB) Downloaded 118 times
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: Timer resolution

Postby eve » Sun Oct 03, 2010 8:27 am

Hi Slowdown,

Thank you for the suggestion. But that is no solution.

ccRPtimer contains the usable functions in VB6.

Erik
eve
 
Posts: 5
Joined: Tue Sep 14, 2010 8:29 am

Re: Timer resolution

Postby pappawinni » Sun Oct 03, 2010 6:07 pm

Hi eve

sorry to say that but..
under windows... if not having special hard and software ...
i think a resolution of ns is bullshit.
...or ok.. you can have the resolution but NOT the precission.
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany

Next

Return to Coding Questions

cron