~ubuntu-branches/ubuntu/saucy/python-scipy/saucy

« back to all changes in this revision

Viewing changes to Lib/sandbox/xplt/src/play/unix/timeu.c

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * timeu.c -- $Id: timeu.c 685 2003-03-08 15:26:51Z travo $
3
 
 * p_cpu_secs for UNIX machines (ANSI C version not UNIX specific)
4
 
 *
5
 
 * Copyright (c) 1998.  See accompanying LEGAL file for details.
6
 
 */
7
 
 
8
 
#include "config.h"
9
 
#include "play.h"
10
 
 
11
 
/* if getrusage exists, it is likely best choice (eg- Digital UNIX) */
12
 
#ifdef USE_GETRUSAGE
13
 
 
14
 
/* this is BSD way to get user and system time */
15
 
#undef _POSIX_SOURCE
16
 
#include <sys/time.h>
17
 
#include <sys/resource.h>
18
 
double
19
 
p_cpu_secs(double *sys)
20
 
{
21
 
  struct rusage cpu;
22
 
  getrusage(RUSAGE_SELF, &cpu);
23
 
  if (sys) *sys = cpu.ru_stime.tv_sec + 1.0e-6*cpu.ru_stime.tv_usec;
24
 
  return cpu.ru_utime.tv_sec + 1.0e-6*cpu.ru_utime.tv_usec;
25
 
}
26
 
 
27
 
#else
28
 
# ifdef USE_TIMES
29
 
 
30
 
/* this is POSIX 1003.1-1990 standard timing interface */
31
 
#ifndef _POSIX_SOURCE
32
 
#define _POSIX_SOURCE 1
33
 
#endif
34
 
#include <time.h>
35
 
#include <sys/times.h>
36
 
/* try to handle modest deviations from POSIX standard (e.g.- Sun) */
37
 
#  ifndef CLK_TCK
38
 
#   include <unistd.h>
39
 
#   ifndef CLK_TCK
40
 
#    define CLK_TCK sysconf(_SC_CLK_TCK)
41
 
#   endif
42
 
#  endif
43
 
static double secs_per_tick = 0.0;
44
 
double
45
 
p_cpu_secs(double *sys)
46
 
{
47
 
  struct tms cpu;
48
 
  times(&cpu);
49
 
  if (secs_per_tick==0.0) secs_per_tick = 1./((double)CLK_TCK);
50
 
  if (sys) *sys = cpu.tms_stime*secs_per_tick;
51
 
  return cpu.tms_utime*secs_per_tick;
52
 
}
53
 
 
54
 
# else
55
 
 
56
 
/* ANSI C standard should at least compile anywhere */
57
 
#include "time.h"
58
 
static double secs_per_tick = 0.0;
59
 
double
60
 
p_cpu_secs(double *sys)
61
 
{
62
 
  if (secs_per_tick==0.0) secs_per_tick = 1./((double)CLOCKS_PER_SEC);
63
 
  if (sys) *sys = 0.0;
64
 
  return clock()*secs_per_tick;
65
 
}
66
 
 
67
 
# endif
68
 
#endif