File: timer.cpp

package info (click to toggle)
qd 2.1.200-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,932 kB
  • ctags: 1,396
  • sloc: sh: 9,033; cpp: 5,696; f90: 5,156; ansic: 1,359; makefile: 98
file content (43 lines) | stat: -rw-r--r-- 800 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * tests/timer.cpp
 *
 * This work was supported by the Director, Office of Science, Division
 * of Mathematical, Information, and Computational Sciences of the
 * U.S. Department of Energy under contract number DE-AC03-76SF00098.
 *
 * Copyright (c) 2000-2001
 *
 * Contains function used for timing.
 */
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <ctime>
#endif

#include "timer.h"

void tic(TimeVal *tv) {
#ifdef HAVE_SYS_TIME_H
  gettimeofday(tv, 0L);
#else
  time(tv);
#endif
}

double toc(TimeVal *tv) {
  TimeVal tv2;
  
#ifdef HAVE_SYS_TIME_H
  gettimeofday(&tv2, 0L);

  double  sec = (double) (tv2.tv_sec - tv->tv_sec);
  double usec = (double) (tv2.tv_usec - tv->tv_usec);
  
  return (sec + 1.0e-6 * usec);
#else
  time(&tv2);
  return difftime(tv2, *tv);
#endif
}