1 |
/* Creation date: 2005-06-26 18:11:40
|
2 |
* Authors: Don
|
3 |
* Change log:
|
4 |
*/
|
5 |
|
6 |
/* Copyright (c) 2005 Don Owens
|
7 |
All rights reserved.
|
8 |
|
9 |
This code is released under the BSD license:
|
10 |
|
11 |
Redistribution and use in source and binary forms, with or without
|
12 |
modification, are permitted provided that the following conditions
|
13 |
are met:
|
14 |
|
15 |
* Redistributions of source code must retain the above copyright
|
16 |
notice, this list of conditions and the following disclaimer.
|
17 |
|
18 |
* Redistributions in binary form must reproduce the above
|
19 |
copyright notice, this list of conditions and the following
|
20 |
disclaimer in the documentation and/or other materials provided
|
21 |
with the distribution.
|
22 |
|
23 |
* Neither the name of the author nor the names of its
|
24 |
contributors may be used to endorse or promote products derived
|
25 |
from this software without specific prior written permission.
|
26 |
|
27 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
28 |
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
29 |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
30 |
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
31 |
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
32 |
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
33 |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
34 |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
35 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
36 |
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
37 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
38 |
OF THE POSSIBILITY OF SUCH DAMAGE.
|
39 |
*/
|
40 |
|
41 |
#include "cfu.h"
|
42 |
#include "cfutime.h"
|
43 |
#include <string.h>
|
44 |
#include <stdlib.h>
|
45 |
|
46 |
#ifdef CFU_DEBUG
|
47 |
#ifdef NDEBUG
|
48 |
#undef NDEBUG
|
49 |
#endif
|
50 |
#else
|
51 |
#ifndef NDEBUG
|
52 |
#define NDEBUG 1
|
53 |
#endif
|
54 |
#endif
|
55 |
#include <assert.h>
|
56 |
|
57 |
typedef struct cfutime {
|
58 |
libcfu_type type;
|
59 |
struct timeval begin_tv;
|
60 |
struct timezone begin_tz;
|
61 |
struct timeval end_tv;
|
62 |
struct timezone end_tz;
|
63 |
} cfutime;
|
64 |
|
65 |
extern cfutime_t *
|
66 |
cfutime_new() {
|
67 |
cfutime_t *time = (cfutime_t *)calloc(1, sizeof(cfutime));
|
68 |
time->type = libcfu_t_time;
|
69 |
return time;
|
70 |
}
|
71 |
|
72 |
extern void
|
73 |
cfutime_begin(cfutime_t *time) {
|
74 |
gettimeofday(&(time->begin_tv), &(time->begin_tz));
|
75 |
}
|
76 |
|
77 |
extern void
|
78 |
cfutime_end(cfutime_t *time) {
|
79 |
gettimeofday(&(time->end_tv), &(time->end_tz));
|
80 |
}
|
81 |
|
82 |
extern double
|
83 |
cfutime_elapsed(cfutime_t *time) {
|
84 |
return (double)time->end_tv.tv_sec + ((double)time->end_tv.tv_usec)/1000000 -
|
85 |
((double)time->begin_tv.tv_sec + ((double)time->begin_tv.tv_usec)/1000000);
|
86 |
}
|
87 |
|
88 |
extern void
|
89 |
cfutime_free(cfutime_t *time) {
|
90 |
free(time);
|
91 |
}
|