|
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/. */ |
|
5 |
|
6 /* |
|
7 * Program to test different ways to get file info; right now it |
|
8 * only works for solaris and OS/2. |
|
9 * |
|
10 */ |
|
11 #include "nspr.h" |
|
12 #include "prpriv.h" |
|
13 #include "prinrval.h" |
|
14 |
|
15 #include <stdio.h> |
|
16 #include <stdlib.h> |
|
17 #include <string.h> |
|
18 |
|
19 #ifdef XP_OS2 |
|
20 #include <io.h> |
|
21 #include <sys/types.h> |
|
22 #include <sys/stat.h> |
|
23 #endif |
|
24 |
|
25 #define DEFAULT_COUNT 100000 |
|
26 PRInt32 count; |
|
27 |
|
28 #ifndef XP_PC |
|
29 char *filename = "/etc/passwd"; |
|
30 #else |
|
31 char *filename = "..\\stat.c"; |
|
32 #endif |
|
33 |
|
34 static void statPRStat(void) |
|
35 { |
|
36 PRFileInfo finfo; |
|
37 PRInt32 index = count; |
|
38 |
|
39 for (;index--;) { |
|
40 PR_GetFileInfo(filename, &finfo); |
|
41 } |
|
42 } |
|
43 |
|
44 static void statStat(void) |
|
45 { |
|
46 struct stat finfo; |
|
47 PRInt32 index = count; |
|
48 |
|
49 for (;index--;) { |
|
50 stat(filename, &finfo); |
|
51 } |
|
52 } |
|
53 |
|
54 /************************************************************************/ |
|
55 |
|
56 static void Measure(void (*func)(void), const char *msg) |
|
57 { |
|
58 PRIntervalTime start, stop; |
|
59 double d; |
|
60 PRInt32 tot; |
|
61 |
|
62 start = PR_IntervalNow(); |
|
63 (*func)(); |
|
64 stop = PR_IntervalNow(); |
|
65 |
|
66 d = (double)PR_IntervalToMicroseconds(stop - start); |
|
67 tot = PR_IntervalToMilliseconds(stop-start); |
|
68 |
|
69 printf("%40s: %6.2f usec avg, %d msec total\n", msg, d / count, tot); |
|
70 } |
|
71 |
|
72 int main(int argc, char **argv) |
|
73 { |
|
74 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); |
|
75 PR_STDIO_INIT(); |
|
76 |
|
77 if (argc > 1) { |
|
78 count = atoi(argv[1]); |
|
79 } else { |
|
80 count = DEFAULT_COUNT; |
|
81 } |
|
82 |
|
83 Measure(statPRStat, "time to call PR_GetFileInfo()"); |
|
84 Measure(statStat, "time to call stat()"); |
|
85 |
|
86 PR_Cleanup(); |
|
87 } |