mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
core: move elapsed_time into bench module
This commit is contained in:
parent
153f0fb4f6
commit
1b7e027642
@ -1,13 +1,16 @@
|
||||
(load "Statistics.carp")
|
||||
|
||||
(system-include "carp_bench.h")
|
||||
(register get-time-elapsed (Fn [] Double))
|
||||
|
||||
(defmodule Bench
|
||||
(def min-runs 50)
|
||||
(private min-runs)
|
||||
(hidden min-runs)
|
||||
|
||||
(private get-time-elapsed)
|
||||
(hidden get-time-elapsed)
|
||||
(register get-time-elapsed (Fn [] Double) "get_time_elapsed")
|
||||
|
||||
(doc set-min-runs! "sets the minimum number of runs to `n`.
|
||||
|
||||
If your functions takes a large amount of time, experimenting with this might make sense. The default value is `50`, which means that your function runs at least `50` times before even hitting a timeout.")
|
||||
@ -106,15 +109,15 @@ If your functions takes a large amount of time, experimenting with this might ma
|
||||
|
||||
|
||||
(defmacro benchn [n form]
|
||||
(list 'let ['before (get-time-elapsed)
|
||||
(list 'let ['before (Bench.get-time-elapsed)
|
||||
'times []]
|
||||
(list 'do
|
||||
(list 'for ['i 0 n]
|
||||
(list 'let ['before-once (get-time-elapsed)]
|
||||
(list 'let ['before-once (Bench.get-time-elapsed)]
|
||||
(list 'do
|
||||
form
|
||||
(list 'set! × (Array.push-back (Array.copy ×) (Double.- (get-time-elapsed) before-once))))))
|
||||
(list 'let ['total (Double.- (get-time-elapsed) before)
|
||||
(list 'set! × (Array.push-back (Array.copy ×) (Double.- (Bench.get-time-elapsed) before-once))))))
|
||||
(list 'let ['total (Double.- (Bench.get-time-elapsed) before)
|
||||
'per (list 'Double./ 'total (list 'Double.from-int n))]
|
||||
(do
|
||||
(Bench.print "Total time elapsed: " total)
|
||||
|
@ -1,4 +1,4 @@
|
||||
double get_MINUS_time_MINUS_elapsed() {
|
||||
double get_time_elapsed() {
|
||||
struct timespec tv;
|
||||
clock_gettime(CLOCK_REALTIME, &tv);
|
||||
return 1000000000 * tv.tv_sec + tv.tv_nsec;
|
||||
|
Loading…
Reference in New Issue
Block a user