home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / MP / timer / regular / second.c < prev   
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.2 KB  |  50 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /* include param.h to define BSD or HZ depending on OS */
  18. #include <sys/param.h>
  19.  
  20. #ifdef BSD
  21.  
  22. #include <sys/time.h>
  23. #include <sys/resource.h>
  24.  
  25. double
  26. second_ ()
  27. {
  28.   struct rusage ru;
  29.   getrusage (RUSAGE_SELF, &ru);
  30.   return (double)ru.ru_utime.tv_sec + ((double)ru.ru_utime.tv_usec * 1.0e-6);
  31. }
  32.  
  33. #else
  34.  
  35. #include <sys/types.h>
  36. #include <sys/times.h>
  37.  
  38. extern long times();
  39.  
  40. double
  41. second_ ()
  42. {
  43.   register long walltime;
  44.   struct tms tm;
  45.   walltime = times(&tm);
  46.   return (double)tm.tms_utime / (double)HZ;
  47. }
  48.  
  49. #endif
  50.