1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is the Netscape Portable Runtime (NSPR).
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998-2000
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | /*
|
---|
39 | * Program to test different ways to get file info; right now it
|
---|
40 | * only works for solaris and OS/2.
|
---|
41 | *
|
---|
42 | */
|
---|
43 | #include "nspr.h"
|
---|
44 | #include "prpriv.h"
|
---|
45 | #include "prinrval.h"
|
---|
46 |
|
---|
47 | #include <stdio.h>
|
---|
48 | #include <stdlib.h>
|
---|
49 | #include <string.h>
|
---|
50 |
|
---|
51 | #ifdef XP_OS2
|
---|
52 | #include <io.h>
|
---|
53 | #include <sys/types.h>
|
---|
54 | #include <sys/stat.h>
|
---|
55 | #endif
|
---|
56 |
|
---|
57 | #define DEFAULT_COUNT 100000
|
---|
58 | PRInt32 count;
|
---|
59 |
|
---|
60 | #ifndef XP_PC
|
---|
61 | char *filename = "/etc/passwd";
|
---|
62 | #else
|
---|
63 | char *filename = "..\\stat.c";
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | static void statPRStat(void)
|
---|
67 | {
|
---|
68 | PRFileInfo finfo;
|
---|
69 | PRInt32 index = count;
|
---|
70 |
|
---|
71 | for (;index--;) {
|
---|
72 | PR_GetFileInfo(filename, &finfo);
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | static void statStat(void)
|
---|
77 | {
|
---|
78 | struct stat finfo;
|
---|
79 | PRInt32 index = count;
|
---|
80 |
|
---|
81 | for (;index--;) {
|
---|
82 | stat(filename, &finfo);
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | /************************************************************************/
|
---|
87 |
|
---|
88 | static void Measure(void (*func)(void), const char *msg)
|
---|
89 | {
|
---|
90 | PRIntervalTime start, stop;
|
---|
91 | double d;
|
---|
92 | PRInt32 tot;
|
---|
93 |
|
---|
94 | start = PR_IntervalNow();
|
---|
95 | (*func)();
|
---|
96 | stop = PR_IntervalNow();
|
---|
97 |
|
---|
98 | d = (double)PR_IntervalToMicroseconds(stop - start);
|
---|
99 | tot = PR_IntervalToMilliseconds(stop-start);
|
---|
100 |
|
---|
101 | printf("%40s: %6.2f usec avg, %d msec total\n", msg, d / count, tot);
|
---|
102 | }
|
---|
103 |
|
---|
104 | void main(int argc, char **argv)
|
---|
105 | {
|
---|
106 | PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
|
---|
107 | PR_STDIO_INIT();
|
---|
108 |
|
---|
109 | if (argc > 1) {
|
---|
110 | count = atoi(argv[1]);
|
---|
111 | } else {
|
---|
112 | count = DEFAULT_COUNT;
|
---|
113 | }
|
---|
114 |
|
---|
115 | Measure(statPRStat, "time to call PR_GetFileInfo()");
|
---|
116 | Measure(statStat, "time to call stat()");
|
---|
117 |
|
---|
118 | PR_Cleanup();
|
---|
119 | }
|
---|