home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / stat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.2 KB  |  89 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20.  * Program to test different ways to get file info; right now it 
  21.  * only works for solaris.
  22.  *
  23.  */
  24. #include "nspr.h"
  25. #include "prpriv.h"
  26. #include "prinrval.h"
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31.  
  32. #define DEFAULT_COUNT 100000
  33. PRInt32 count;
  34.  
  35. static void statPRStat(void)
  36. {
  37.     PRFileInfo finfo;
  38.     PRInt32 index = count;
  39.  
  40.     for (;index--;) {
  41.          PR_GetFileInfo("/etc/passwd", &finfo);
  42.     }
  43. }
  44.  
  45. static void statStat(void)
  46. {
  47.     struct stat finfo;
  48.     PRInt32 index = count;
  49.  
  50.     for (;index--;) {
  51.         stat("/etc/passwd", &finfo);
  52.     }
  53. }
  54.  
  55. /************************************************************************/
  56.  
  57. static void Measure(void (*func)(void), const char *msg)
  58. {
  59.     PRIntervalTime start, stop;
  60.     double d;
  61.     PRInt32 tot;
  62.  
  63.     start = PR_IntervalNow();
  64.     (*func)();
  65.     stop = PR_IntervalNow();
  66.  
  67.     d = (double)PR_IntervalToMicroseconds(stop - start);
  68.     tot = PR_IntervalToMilliseconds(stop-start);
  69.  
  70.     printf("%40s: %6.2f usec avg, %d msec total\n", msg, d / count, tot);
  71. }
  72.  
  73. void main(int argc, char **argv)
  74. {
  75.     PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
  76.     PR_STDIO_INIT();
  77.  
  78.     if (argc > 1) {
  79.     count = atoi(argv[1]);
  80.     } else {
  81.     count = DEFAULT_COUNT;
  82.     }
  83.  
  84.     Measure(statPRStat, "time to call PR_GetFileInfo()");
  85.     Measure(statStat, "time to call stat()");
  86.  
  87.     PR_Cleanup();
  88. }
  89.