michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Program to test different ways to get file info; right now it michael@0: * only works for solaris and OS/2. michael@0: * michael@0: */ michael@0: #include "nspr.h" michael@0: #include "prpriv.h" michael@0: #include "prinrval.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #ifdef XP_OS2 michael@0: #include michael@0: #include michael@0: #include michael@0: #endif michael@0: michael@0: #define DEFAULT_COUNT 100000 michael@0: PRInt32 count; michael@0: michael@0: #ifndef XP_PC michael@0: char *filename = "/etc/passwd"; michael@0: #else michael@0: char *filename = "..\\stat.c"; michael@0: #endif michael@0: michael@0: static void statPRStat(void) michael@0: { michael@0: PRFileInfo finfo; michael@0: PRInt32 index = count; michael@0: michael@0: for (;index--;) { michael@0: PR_GetFileInfo(filename, &finfo); michael@0: } michael@0: } michael@0: michael@0: static void statStat(void) michael@0: { michael@0: struct stat finfo; michael@0: PRInt32 index = count; michael@0: michael@0: for (;index--;) { michael@0: stat(filename, &finfo); michael@0: } michael@0: } michael@0: michael@0: /************************************************************************/ michael@0: michael@0: static void Measure(void (*func)(void), const char *msg) michael@0: { michael@0: PRIntervalTime start, stop; michael@0: double d; michael@0: PRInt32 tot; michael@0: michael@0: start = PR_IntervalNow(); michael@0: (*func)(); michael@0: stop = PR_IntervalNow(); michael@0: michael@0: d = (double)PR_IntervalToMicroseconds(stop - start); michael@0: tot = PR_IntervalToMilliseconds(stop-start); michael@0: michael@0: printf("%40s: %6.2f usec avg, %d msec total\n", msg, d / count, tot); michael@0: } michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); michael@0: PR_STDIO_INIT(); michael@0: michael@0: if (argc > 1) { michael@0: count = atoi(argv[1]); michael@0: } else { michael@0: count = DEFAULT_COUNT; michael@0: } michael@0: michael@0: Measure(statPRStat, "time to call PR_GetFileInfo()"); michael@0: Measure(statStat, "time to call stat()"); michael@0: michael@0: PR_Cleanup(); michael@0: }