summaryrefslogtreecommitdiff
path: root/nacl/cpucycles/gettimeofday.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-02 09:53:34 -0400
committerirungentoo <irungentoo@gmail.com>2013-07-02 09:53:34 -0400
commite2967396ac73cb7410787886cdaf072a184ffc49 (patch)
tree527a74d25a4a0705fc641994fd35bfab22662034 /nacl/cpucycles/gettimeofday.c
parent8928c817df345f29aa0b194743595aa11bd6a8ba (diff)
Added NaCl crypto library.
Diffstat (limited to 'nacl/cpucycles/gettimeofday.c')
-rw-r--r--nacl/cpucycles/gettimeofday.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/nacl/cpucycles/gettimeofday.c b/nacl/cpucycles/gettimeofday.c
new file mode 100644
index 00000000..0bf5e03c
--- /dev/null
+++ b/nacl/cpucycles/gettimeofday.c
@@ -0,0 +1,32 @@
1#include <time.h>
2#include <stdio.h>
3#include <unistd.h>
4#include <sys/time.h>
5#include <sys/types.h>
6#include "osfreq.c"
7
8static double cpufrequency = 0;
9
10static void init(void)
11{
12 cpufrequency = osfreq();
13}
14
15long long cpucycles_gettimeofday(void)
16{
17 double result;
18 struct timeval t;
19 if (!cpufrequency) init();
20 gettimeofday(&t,(struct timezone *) 0);
21 result = t.tv_usec;
22 result *= 0.000001;
23 result += (double) t.tv_sec;
24 result *= cpufrequency;
25 return result;
26}
27
28long long cpucycles_gettimeofday_persecond(void)
29{
30 if (!cpufrequency) init();
31 return cpufrequency;
32}