CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Guest

    Speed Control finer than milliseconds?

    It is really possible to control the execution speed on various computers using the Sleep API. But can someone go even better than this, like nano-, picoseconds, etc. Any cheeky technique.


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Speed Control finer than milliseconds?

    Don't know for sure, but the api is called with the parameter 'dwMilliseconds as Long'.
    Try sending a value < 1, like 0.1
    It's worth a try


    Tom Cannaerts
    [email protected]

    The best way to escape a problem, is to solve it.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Speed Control finer than milliseconds?

    But a 'long' is still a 'whole' number.

    The CCRP project team (http://www.mvps.org/ccrp) provide a 'high-resolution' timer object that allows you to capture 1ms events, but as for any lower than that - I wouldn't have thought the average PC was upto the job.


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  4. #4
    Join Date
    Dec 1999
    Location
    Islamabad, Pakistan
    Posts
    12

    Re: Speed Control finer than milliseconds?

    Why shouldn't a PC do the job. There are lots and lots of MHz, i.e., millions of pulses per second...
    There must be a way!


  5. #5
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: Speed Control finer than milliseconds?

    All these "sleep" to a 0.001 second...all that is crap, timers are really inaccurate, but altough SLEEP function is much more accurate then using TIMER keyword, sleep is still probably will never be "perfect". Even thought current Intel CPU can support up to 2 billion operations per sec, windows cuts that power maybe like 50%, and VB is "slow" language itself, so the result is slippery. To tell the truth, I don't like the windows by it's speed, because it's really slow and it slows down other programs, but it's easy-to-use!!! For ex. to play games over internet you don't need CABLE modem (like DSL or T1) to have optimal performance, you need it because you play games throught windows, where windows makes it really slow transfering of bytes, so it sucks!!
    WINDOWS SUCKS!! (if you think from programming point of view)


  6. #6
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Speed Control finer than milliseconds?

    The API call GetProcessTimes theoretically allows time slices to be as small as 100 nanoseconds (but no PC will allow this low a resolution that I know of).
    The declarations are:

    Type FILETIME
    dwLowDateTime as Long
    dwHighDateTime as Long
    End Type
    Declare Function GetProcessTimes Lib "kernel32" Alias "GetProcessTimes" (byval hProcess as Long, lpCreationTime as FILETIME, lpExitTime as FILETIME, lpKernelTime as FILETIME, lpUserTime as FILETIME) as Long




    You will have to experiment to see how low a resolution you can get in practice.

    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured