nsprpub/pr/tests/stat.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial