Re: Timings for optimised poll(2)

Peter Leif Rasmussen (peter@udgaard.isgtec.com)
Sat, 23 Aug 1997 21:07:44 -0400


Hi Richard,

You write:
>
>I've appended my latest version test programme. Compile with -O2. This
>contains a *realistic* scanning loop. It takes 1.5 milliseconds on a
>Pentium 100.
>
And just for fun I compiled it and ran it on a 486DX2/66MHz, a 486SLC2/50MHz
and a 386SX/20MHz, and my numbers said:

486DX2/66MHz: 4200 us (linux 2.0.30)
486SLC2/50MHz: 10000 us (linux 2.1.51)
386SX/20MHz: 24400 us (linux 2.0.29)

Without having access to any Pentium computer, I find it difficult to believe
that you got 1.5 us with your test program?! If you did, could you give a point
of view as to why you think the numbers are so different?

Can anybody else?

Just to recap, the program is the following that should be saved to a file,
eg. my_file.c and compiled with:

gcc -o my_bench -O2 my_file.c

and then run with no parameters.

#include <stdio.h>
#include <string.h>
#include <sys/poll.h>
#include <sys/time.h>
#include <unistd.h>

#define MAX_FDS 10000

/* Structure to manage descriptors */
struct managed_fd_type
{
int fd;
void *info;
void (*func) (void *info);
};

void main ()
{
int count, num_ready;
long time_taken;
struct timeval time1, time2;
struct pollfd *pollfd_ptr;
struct managed_fd_type *cbk_ptr;
struct pollfd ufds[MAX_FDS];
struct managed_fd_type cbk_array[MAX_FDS];

/* Ensure no descriptors are actually ready */
memset (ufds, 0, sizeof ufds);
/* Pretend a single descriptor is ready */
num_ready = 1;
gettimeofday (&time1, NULL);
for (count = 0, pollfd_ptr = ufds, cbk_ptr = cbk_array;
(num_ready > 0) && (count < MAX_FDS);
++count, ++pollfd_ptr, ++cbk_ptr)
{
if (pollfd_ptr->revents == 0) continue;
/* Dummy code: will not be executed */
--num_ready;
/* Call the callback */
(*cbk_ptr->func) (cbk_ptr->info);
}
gettimeofday (&time2, NULL);
time_taken = (time2.tv_sec - time1.tv_sec) * 1000000;
time_taken += time2.tv_usec - time1.tv_usec;
fprintf (stderr, "real time taken: %ld us\n", time_taken);
} /* End Function main */

Thanks for your time,

Peter

--
main(){char*s="O_>>^PQAHBbPQAHBbPOOH^^PAAHBJPAAHBbPA_H>BB";int i,j,k,l,m,n;
for(j=0;j<7;j++)for(l=0;m=l-6+j,i=m/6,n=j*6+i,k=1<<m%6,l<41-j;l++)
putchar(l<6-j?' ':l==40-j?'\n':k&&s[n]&k?'*':' ');}