nsprpub/pr/tests/stat.c

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     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.
     9  *
    10  */
    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)
    35 {
    36     PRFileInfo finfo;
    37     PRInt32 index = count;
    39     for (;index--;) {
    40          PR_GetFileInfo(filename, &finfo);
    41     }
    42 }
    44 static void statStat(void)
    45 {
    46     struct stat finfo;
    47     PRInt32 index = count;
    49     for (;index--;) {
    50         stat(filename, &finfo);
    51     }
    52 }
    54 /************************************************************************/
    56 static void Measure(void (*func)(void), const char *msg)
    57 {
    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);
    70 }
    72 int main(int argc, char **argv)
    73 {
    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;
    81     }
    83     Measure(statPRStat, "time to call PR_GetFileInfo()");
    84     Measure(statStat, "time to call stat()");
    86     PR_Cleanup();
    87 }

mercurial