Issue #261 - Replaced clock()

This commit is contained in:
Justin Ethier 2018-06-13 13:28:40 -04:00
parent 650aac1a58
commit 027a95ed77

View file

@ -12,6 +12,7 @@
current-jiffy
jiffies-per-second
)
(include-c-header "<sys/time.h>")
(import (scheme base)
)
;; TODO: get an FFI syntax for including C header files, even if it is not needed for this library
@ -24,13 +25,30 @@
return_closcall1(data, k, &box); ")
(define-c current-jiffy
"(void *data, int argc, closure _, object k)"
" make_double(box, 0.0);
clock_t jiffy = clock();
" struct timeval tv;
make_double(box, 0.0);
gettimeofday(&tv, NULL); /* TODO: longer-term use clock_gettime instead */
long long jiffy = (tv.tv_sec)*1000000LL + tv.tv_usec;
/* TODO: future consideration
mp_int bn_tmp, bn_tmp2, bn_tmp3;
mp_init(&bn_tmp);
mp_init(&bn_tmp2);
mp_init(&bn_tmp3);
Cyc_int2bignum(tv.tv_sec, &bn_tmp);
Cyc_int2bignum(1000000LL, &bn_tmp2);
Cyc_int2bignum(tv.tv_usec, &bn_tmp3);
alloc_bignum(data, box);
mp_mul(&bn_tmp, &bn_tmp2, &bn_tmp);
mp_add(&bn_tmp, &bn_tmp3, &bignum_value(box));
mp_clear(&bn_tmp);
mp_clear(&bn_tmp2);
mp_clear(&bn_tmp3);
*/
double_value(&box) = jiffy;
return_closcall1(data, k, &box); ")
(define-c jiffies-per-second
"(void *data, int argc, closure _, object k)"
" int n = CLOCKS_PER_SEC;
" int n = 1000000;
object obj = obj_int2obj(n);
return_closcall1(data, k, obj); ")
))