Is timing more precise in Windows or Linux?

Discussion in 'Programming' started by FPForum, Mar 6, 2023.

  1. #1
    We are trying to start our program at one specific time, to the millisecond (For example, 12:00:00.000)..Using VB.NET on Windows we have found that (apparently, due to preemptive multithreading) there is always a very small few millisecond difference (For example, we actually start our thread at 12:00:00.012 sometimes or 12:00:00.006 at times, or somewhere in that range of just a handful of milliseconds)..My question is, does anyone know if our timing would be more precise if we were to do this in PHP/Linux instead?

    From what I have read and been told, because of preemptive multithreading on Windows you will probably never be able to start your threads at exactly 12:00:00.000 on the dot every single time. There will always be a tiny bit of randomness lasting at least a couple of milliseconds. However, we really want it to be exact. Would PHP be the better solution here? Thanks!
     
    FPForum, Mar 6, 2023 IP
  2. JoopMoore

    JoopMoore Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    I would guess nope, start a task at exactly a specific msec isn't possible. You can't usually control what the hardware does, cpu could be busy, IO could be busy at a specific msec. In addition, the startup time of the task needs to be taken in account. Why do you actually need msec precision to run a task?
     
    JoopMoore, May 9, 2023 IP
  3. FPForum

    FPForum Notable Member

    Messages:
    4,172
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    225
    Digital Goods:
    2
    #3
    I was able to eventually figure this out..Just had to use a high precision timer.
     
    FPForum, May 9, 2023 IP
  4. Mark Elijah

    Mark Elijah Greenhorn

    Messages:
    145
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    18
    #4
    Linux has a slight advantage in timer precision. While both Windows (15ms) and Linux (1ms) have a base clock tick rate, Linux offers finer-grained timers for high-accuracy tasks. However, even with Linux, achieving millisecond perfect timing might be tricky due to factors like scheduling overhead. Exploring alternative approaches like dedicated time synchronization libraries might be necessary for your specific needs.
     
    Mark Elijah, May 14, 2024 IP
  5. Connor98

    Connor98 Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    1. Kernel Design and Scheduling
    Linux:

    • Preemptive Kernel: Linux supports a fully preemptive kernel, which can lead to better real-time performance and lower latency. This makes Linux more suitable for applications requiring high precision in timing.
    • Real-Time Patches: Linux offers real-time patches (PREEMPT-RT) that enhance its capabilities for real-time applications, further improving the timing precision.
    • Timer Resolution: The default timer resolution in Linux can be fine-tuned (typically 1ms or better), and with high-resolution timers, it can achieve sub-millisecond precision.
    Windows:

    • Preemptive Multitasking: Windows also uses a preemptive multitasking model, but it traditionally focuses more on general-purpose use rather than real-time precision.
    • Multimedia Timers: Windows provides multimedia timers for high-resolution timing, which can achieve millisecond precision, but it generally does not match the level of precision available in Linux with real-time patches.
    • Default Timer Resolution: The default timer resolution in Windows is typically around 15.6ms, though it can be adjusted using APIs like timeBeginPeriod.
    2. APIs and Timing Mechanisms
    Linux:

    • POSIX Timers: Linux supports POSIX timers, which provide high-resolution timing services.
    • clock_gettime: The clock_gettime function offers nanosecond precision, making it suitable for applications requiring very fine-grained timing.
    • Scheduler Tuning: Linux allows for detailed tuning of the scheduler and timing parameters, making it more adaptable for various timing-sensitive applications.
    Windows:

    • QueryPerformanceCounter: Windows provides the QueryPerformanceCounter function, which offers high-resolution performance counter capabilities, allowing for microsecond-level precision.
    • High-Resolution Timer APIs: Windows has APIs like CreateWaitableTimer and SetWaitableTimer for high-resolution timing, though they are typically used for specific applications.
    If you're interested, I found many cheap licenses on RoyalCDKeys. I highly recommend it. When formulating the response about the differences between Linux and Windows regarding this dilemma, I thought of recommending the site where I get cheap antivirus, Windows, Office, and many other things.

    3. Application Use Case

    Real-Time Applications:

    • Linux is generally preferred for real-time applications due to its better support for low-latency and high-precision timing through the PREEMPT-RT patches and configurable timer resolutions.
    General-Purpose Applications:

    • Windows is often sufficient for general-purpose applications that do not require extremely precise timing, and its APIs can be tuned for better performance when necessary.
     
    Connor98, Jun 6, 2024 IP