mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
bench: added nanosecond accuracy
This commit is contained in:
parent
e2dfe35079
commit
f794d7685f
@ -2,12 +2,11 @@
|
||||
(register get-time-elapsed (Fn [] Double))
|
||||
|
||||
(defmodule Bench
|
||||
|
||||
(defn get-unit [n]
|
||||
(cond
|
||||
(< n 1000.0) (String.append (Double.str n) @"µs")
|
||||
(< n 1000000.0) (String.append (Double.str (/ n 1000.0)) @"ms")
|
||||
(< n 1000000000.0) (String.append (Double.str (/ n 1000000.0)) @"s")
|
||||
(< n 1000.0) (String.append (Double.str n) @"ns")
|
||||
(< n 1000000.0) (String.append (Double.str (/ n 1000.0)) @"µs")
|
||||
(< n 1000000000.0) (String.append (Double.str (/ n 1000000.0)) @"ms")
|
||||
(String.append (Double.str (/ n 1000000000.0)) @"s")))
|
||||
|
||||
(defn print [title n]
|
||||
@ -54,12 +53,13 @@
|
||||
(Statistics.Summary.median &summ5))
|
||||
(Statistics.Summary.median-abs-dev &summ5))))
|
||||
(do
|
||||
(set! &total (Double.+ total loop-run))
|
||||
(set! &done true)
|
||||
(set! &res &summ5))
|
||||
(do
|
||||
(set! &total (Double.+ total loop-run))
|
||||
(cond
|
||||
(< (Double.* n 10.0) n) (set! &total (Double.+ total 30000000000.0)) ; abort
|
||||
(< (Double.* n 10.0) n) (set! &total (Double.+ total 3000000000.0)) ; abort
|
||||
(set! &n (Double.* n 2.0))))))))))))
|
||||
(if done
|
||||
(do
|
||||
|
@ -1,8 +1,7 @@
|
||||
#include <sys/time.h>
|
||||
|
||||
// TODO: use timespecs for better accuracy!
|
||||
double get_MINUS_time_MINUS_elapsed() {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return 1000000 * tv.tv_sec + tv.tv_usec;
|
||||
struct timespec tv;
|
||||
clock_gettime(CLOCK_REALTIME, &tv);
|
||||
return 1000000000 * tv.tv_sec + tv.tv_nsec;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user