nsprpub/pr/tests/stat.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/tests/stat.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * Program to test different ways to get file info; right now it 
    1.11 + * only works for solaris and OS/2.
    1.12 + *
    1.13 + */
    1.14 +#include "nspr.h"
    1.15 +#include "prpriv.h"
    1.16 +#include "prinrval.h"
    1.17 +
    1.18 +#include <stdio.h>
    1.19 +#include <stdlib.h>
    1.20 +#include <string.h>
    1.21 +
    1.22 +#ifdef XP_OS2
    1.23 +#include <io.h>
    1.24 +#include <sys/types.h>
    1.25 +#include <sys/stat.h>
    1.26 +#endif
    1.27 +
    1.28 +#define DEFAULT_COUNT 100000
    1.29 +PRInt32 count;
    1.30 +
    1.31 +#ifndef XP_PC
    1.32 +char *filename = "/etc/passwd";
    1.33 +#else
    1.34 +char *filename = "..\\stat.c";
    1.35 +#endif
    1.36 +
    1.37 +static void statPRStat(void)
    1.38 +{
    1.39 +    PRFileInfo finfo;
    1.40 +    PRInt32 index = count;
    1.41 + 
    1.42 +    for (;index--;) {
    1.43 +         PR_GetFileInfo(filename, &finfo);
    1.44 +    }
    1.45 +}
    1.46 +
    1.47 +static void statStat(void)
    1.48 +{
    1.49 +    struct stat finfo;
    1.50 +    PRInt32 index = count;
    1.51 + 
    1.52 +    for (;index--;) {
    1.53 +        stat(filename, &finfo);
    1.54 +    }
    1.55 +}
    1.56 +
    1.57 +/************************************************************************/
    1.58 +
    1.59 +static void Measure(void (*func)(void), const char *msg)
    1.60 +{
    1.61 +    PRIntervalTime start, stop;
    1.62 +    double d;
    1.63 +    PRInt32 tot;
    1.64 +
    1.65 +    start = PR_IntervalNow();
    1.66 +    (*func)();
    1.67 +    stop = PR_IntervalNow();
    1.68 +
    1.69 +    d = (double)PR_IntervalToMicroseconds(stop - start);
    1.70 +    tot = PR_IntervalToMilliseconds(stop-start);
    1.71 +
    1.72 +    printf("%40s: %6.2f usec avg, %d msec total\n", msg, d / count, tot);
    1.73 +}
    1.74 +
    1.75 +int main(int argc, char **argv)
    1.76 +{
    1.77 +    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    1.78 +    PR_STDIO_INIT();
    1.79 +
    1.80 +    if (argc > 1) {
    1.81 +	count = atoi(argv[1]);
    1.82 +    } else {
    1.83 +	count = DEFAULT_COUNT;
    1.84 +    }
    1.85 +
    1.86 +    Measure(statPRStat, "time to call PR_GetFileInfo()");
    1.87 +    Measure(statStat, "time to call stat()");
    1.88 +
    1.89 +    PR_Cleanup();
    1.90 +}

mercurial