Select timing, please test this program (was: Signals in Gtk+)
- From: Sascha Ziemann <szi aibon ping de>
- To: gtk-list redhat com
- Subject: Select timing, please test this program (was: Signals in Gtk+)
- Date: 15 Sep 1998 10:34:11 +0200
Tim Janik <timj@gtk.org> writes:
| since you use system calls like select() or alarm() for your timers
| anyways, the highest accuracy to gain is 20ms or 50Hz on intel and
| 10ms or 100Hz on alpha, iirc.
The Intel value is correct, but I have no idea why. Does anybody know?
I got the following results:
Linux Pentium II 333:
---------------------
starting test 1 with 5000 iterations ... done
starting test 2 with 5000 iterations ... done
results for: Linux olivia 2.0.35 #13 Tue Aug 18 09:25:29 MEST 1998 i686 unknown
select without timeout: f1 = 154985.75 Hz d1 = 0.006452 ms
select without reading: f2 = 49.66 Hz d2 = 20.135937 ms
Can please some people test the program on other systems? I would like
to know how this problem is handled there.
This program calculates the minimum delay for select:
/* Time-stamp: <1998-09-15 10:16:47 szi>
**
** select speed test
**
** please try this program on your system, and send me your results
** with a short note about the CPU.
**
** Sascha Ziemann <szi@aibon.ping.de> */
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/types.h>
#include <unistd.h>
double
get_time (void)
{
struct timeval tv;
struct timezone tz;
gettimeofday (&tv, &tz);
return tv.tv_sec + 1e-6 * tv.tv_usec;
}
void
fatal_error (char *msg)
{
fprintf (stderr, "%s\n", msg);
exit (1);
}
#define ITERATIONS 5000
void main (void)
{
double t0;
double t1;
double f1;
double f2;
unsigned int i;
int fd;
fd_set fds;
struct timeval tv;
unsigned char data;
setvbuf (stdout, NULL, _IONBF, 0);
/* select without timeout */
printf ("starting test 1 with %d iterations ... ", ITERATIONS);
fd = open ("/dev/zero", O_RDONLY);
t0 = get_time ();
for (i=0; i<ITERATIONS; i++) {
FD_ZERO(&fds);
FD_SET(fd, &fds);
if (select (fd+1, &fds, NULL, NULL, NULL) != 1)
fatal_error ("select 1 failed");
read (fd, &data, 1);
}
t1 = get_time ();
f1 = ITERATIONS / (t1-t0);
close (fd);
printf ("done\n");
/* select without reading */
printf ("starting test 2 with %d iterations ... ", ITERATIONS);
t0 = get_time ();
for (i=0; i<ITERATIONS; i++) {
tv.tv_sec = 0;
tv.tv_usec = 1;
if (select (0, NULL, NULL, NULL, &tv) != 0)
fatal_error ("select 2 failed");
}
t1 = get_time ();
f2 = ITERATIONS / (t1-t0);
printf ("done\n");
/* report */
printf ("results for: ");
system ("uname -a");
printf ("select without timeout: f1 = %10.2f Hz d1 = %10.6f ms\n",
f1, 1000/f1);
printf ("select without reading: f2 = %10.2f Hz d2 = %10.6f ms\n",
f2, 1000/f2);
}
--
/* In the beginning was the Word: */
typedef long SCM;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]