RosettaCodeData/Task/Time-a-function/Fennel/time-a-function.fennel

23 lines
521 B
Fennel

(do ;;; Time a function
(fn time-function [fn-to=be-timed]
(local start-time (os.clock))
(fn-to=be-timed)
(- (os.clock) start-time) ;;; execution time in seconds
)
(fn delay [delta-t]
(local end-time (+ (os.clock) delta-t))
(while (< (os.clock) end-time)
(var x 0)
(for [i 1 100_000] (set x (+ x 1)))
)
)
(fn test-fn []
(delay 1.234) ; sleep 1.234 seconds
)
(print (time-function test-fn " seconds"))
)