octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

On the performance of octave_usleep/gnulib::nanosleep on Win32


From: Michael Goffioul
Subject: On the performance of octave_usleep/gnulib::nanosleep on Win32
Date: Sun, 20 Nov 2011 21:31:49 +0000

Hi,

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?

Michael.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]