summaryrefslogtreecommitdiffstats
path: root/special/nstat.c
blob: 87c1def547d507e25a2081310d7ded5920284590 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 *	@(#)nstat.c	1.2 98/10/26 Connectathon Testsuite
 *	1.3 Lachman ONC Test Suite source
 *
 * Stat a file n times
 */

#if defined (DOS) || defined (WIN32)
#define DOSorWIN32
#endif

#ifndef DOSorWIN32
#include	<stdio.h>
#include	<stdlib.h>
#include <string.h>
#include	<sys/types.h>
#include	<sys/stat.h>
#ifdef SVR3
#include	<sys/fs/nfs/time.h>
#else
#include	<sys/time.h>
#endif
#endif /* DOSorWIN32 */

#include "../tests.h"

static int stats = 0;

main(argc, argv)
	int argc;
	char *argv[];
{
	struct timeval etim;
	float elapsed;
	register int count;
	register int i;
	struct stat statb;

	if (argc != 2) {
		fprintf(stderr, "usage: %s count\n", argv[0]);
		exit(1);
	}

	count = atoi(argv[1]);
	starttime();
	for (i=0; i<count; i++) {
		if (stat(argv[0], &statb) < 0) {
			fprintf(stderr, "pass %d: can't stat %s: %s\n",
				i, argv[0], strerror(errno));
			exit(1);
		}
		stats++;
	}
	endtime(&etim);
	elapsed = (float)etim.tv_sec + (float)etim.tv_usec / 1000000.0;
	if (elapsed == 0.0) {
		fprintf(stdout, "%d calls 0.0 seconds\n", count);
	} else {
		fprintf(stdout,
		    "%d calls %.2f seconds %.2f calls/sec %.2f msec/call\n",
		    count, elapsed, (float)count / elapsed,
		    1000.0 * elapsed / (float)count);
	}
	exit(0);
}