Re: [RFC/PATCH] Nonotify - A simplistic way to determine directory content changes



On Tue, 2004-06-01 at 16:42, John McCutchan wrote:
> On Tue, Jun 01, 2004 at 02:57:16PM +0200, nf wrote:
> > This idle activity is negligable. One stat-call takes about 2
> > microseconds. Thus, if you watch 500 directories with "nonotify" you'll
> > need about 1 millisecond. This is 0.1% of your CPU time if you poll
> > every second.
> 
> This has already been said, but you are not measuring stat time,
> you are measuring system call time. Please provide a real benchmark of 
> nonotify.

Ok. Here is my nonotify benchmark:

first i created a list of all the directories in my /usr dir.

$ find /usr -type d > dirlist.txt

$ cat -n  tells me that it's 13625 directories.

then i run the attached program nonotify_bench.c with dirlist.txt. 
The program calls stat() on every entry of dirlist.txt.

$ ./nonotify_bench dirlist.txt
count=13625
start=1086144005 sec 836458 usec
stop =1086144005 sec 940930 usec
elapsed=0.104472 sec

13625 entries -> 0.1 sec
this would be per
500 entries -> 0.00367 sec

which would be 0.36 % CPU time if you poll every second. So my
estimation was almost right. I repeated  executing "./nonotify_bench
dirlist.txt" several times - the elapsed time value didn't change a lot.

Norbert









#include <stdio.h>
#include <sys/stat.h>
#include <sys/time.h>

#define DEBUG 0

int main(int argc, char ** argv) {

	char line[1000];
	struct stat statbuf;
	int stat_rval;
	FILE * fp;
	
	int count=0;

	struct timeval start, stop;

	double elapsed;
	
	if (argc<=1) {
		fprintf(stderr, "usage: statbench file\n");
		return 1;
	}
	
	gettimeofday(&start, NULL);	

	fp = fopen(argv[1], "r");
	
	while (fgets(line, 1000 ,fp)) {
		// strip newlines
		char * newline = strchr(line, '\n');
		if(newline != 0) 
			*newline = '\0';
	

		if (DEBUG) printf("%s\n", line);
		
		stat_rval=stat(line, &statbuf);
		if (stat_rval != 0) {
			fprintf(stderr, "error stating %s\n", line);
		}
		// just to see if stat really works
		if (DEBUG) printf("stat mtime=%s\n", ctime(&statbuf.st_mtime));

		
		count++;
	}

	fclose(fp);
	
	gettimeofday(&stop,NULL);

	printf ("count=%d\n", count);
	printf ("start=%d sec %d usec\n", start.tv_sec, start.tv_usec);
	printf ("stop =%d sec %d usec\n", stop.tv_sec, stop.tv_usec);
	printf ("elapsed=%f sec\n", ((double)stop.tv_sec - (double)start.tv_sec) + ((double) stop.tv_usec - (double)start.tv_usec) * 0.000001);
	
	return 0;

}






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