backout 29799f914cab, Bug 917642 - [Helix] Please update the helix blobs
[gecko.git] / nsprpub / pr / tests / stat.c
blobc570056f88f4aceaa12e4b338a3185cb95bc1292
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 * Program to test different ways to get file info; right now it
8 * only works for solaris and OS/2.
11 #include "nspr.h"
12 #include "prpriv.h"
13 #include "prinrval.h"
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
19 #ifdef XP_OS2
20 #include <io.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #endif
25 #define DEFAULT_COUNT 100000
26 PRInt32 count;
28 #ifndef XP_PC
29 char *filename = "/etc/passwd";
30 #else
31 char *filename = "..\\stat.c";
32 #endif
34 static void statPRStat(void)
36 PRFileInfo finfo;
37 PRInt32 index = count;
39 for (;index--;) {
40 PR_GetFileInfo(filename, &finfo);
44 static void statStat(void)
46 struct stat finfo;
47 PRInt32 index = count;
49 for (;index--;) {
50 stat(filename, &finfo);
54 /************************************************************************/
56 static void Measure(void (*func)(void), const char *msg)
58 PRIntervalTime start, stop;
59 double d;
60 PRInt32 tot;
62 start = PR_IntervalNow();
63 (*func)();
64 stop = PR_IntervalNow();
66 d = (double)PR_IntervalToMicroseconds(stop - start);
67 tot = PR_IntervalToMilliseconds(stop-start);
69 printf("%40s: %6.2f usec avg, %d msec total\n", msg, d / count, tot);
72 int main(int argc, char **argv)
74 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
75 PR_STDIO_INIT();
77 if (argc > 1) {
78 count = atoi(argv[1]);
79 } else {
80 count = DEFAULT_COUNT;
83 Measure(statPRStat, "time to call PR_GetFileInfo()");
84 Measure(statStat, "time to call stat()");
86 PR_Cleanup();