[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
On the performance of octave_usleep/gnulib::nanosleep on Win32
From: |
John W. Eaton |
Subject: |
On the performance of octave_usleep/gnulib::nanosleep on Win32 |
Date: |
Mon, 21 Nov 2011 01:23:34 -0500 |
On 20-Nov-2011, Michael Goffioul wrote:
| While implementing the waitfor function, I need to have a loop that
| will do something similar to the readline event-hook system: sleep for
| ~100ms then execute the graphics event loop. Ideally, this loop should
| be as less CPU-consuming as possible (and it should be, as the loop
| will spend most of the time sleeping). However, when testing it on
| Win32 platform, I noticed a significant steady CPU usage of about ~5%,
| which was surprizing. So I digged a bit and found out that it's due to
| octave_usleep implementation (and consequently to gnulib::nanosleep, I
| suppose).
|
| I tested this little example:
|
| #include <octave/config.h>
| #include <octave/cutils.h>
| #define WIN32_LEAN_AND_MEAN
| #include <windows.h>
| #include <stdio.h>
|
| int main (int argc, char **argv)
| {
| printf ("testing octave_usleep...\n");
| for (int i = 0; i < 100; i++)
| octave_usleep (100000);
| printf ("testing Win32 Sleep...\n");
| for (int i = 0; i < 100; i++)
| Sleep (100);
| return 0;
| }
|
| When running this example, I get 5% CPU usage during octave_usleep
| loop, while 0% during the Win32 Sleep loop. This is rather annoying
| and I don't want to leave this performance penalty on Windows
| platform. I'm willing to use the Win32 Sleep function on Windows, and
| the octave_usleep on other platforms, probably using some #ifdef's. Is
| there any objection about that?
Yes, since part of the reason for gnulib is to avoid the need for
#ifdefs like that, I think the gnulib code should be fixed instead.
What does it do on Windows systems that is worse than Sleep. Is there
some reason it can't call Sleep?
jwe