JanetDocsSourcePlaygroundI'm feeling luckyCommunityGitHub sign in

spork/test/timeit

spork


    macro
    /usr/local/lib/janet/spork/test.janet on line 61, column 1

    (timeit form &opt tag)

    Time the execution of `form` using `os/clock` before and after, and 
    print the result to stdout. Returns result of executing `form`. 
    Uses `tag` (default "Elapsed time:") to tag the printout.


1 exampleSign in to add an example
Loading...
# Upgrade mutates, but I wasn't sure whether it'd matter using the pure sorted or mutative sort. So I
# did a simple test.

(import spork)
# create data before test
(def d @{:data (range 10000000 0 -1)})
(spork/test/timeit (update d :data sort)) # 4.32930135726929 seconds and 87.4 MB

(def d @{:data (range 10000000 0 -1)}) # 87.4 MB
(spork/test/timeit (update d :data sorted)) # 4.49482655525208 seconds and 167 MB

# Where did those memory numbers come from? With only the data, the Janet process 
# uses 87.4 MB. Timewise, they take the same amount of time but on starting, sorted
# prepares memory equivalent to its input. To check ram within Janet:
(def pid (os/getpid)) # => "/proc/367537/statm"
(def statm-path (string "/proc/" pid "/statm")) # => 367537
(slurp statm-path) # => @"40444 40038 710 82 0 39426 0\n"

# Collecting garbage:
(gccollect)
(slurp statm-path) # => @"20912 20503 695 82 0 19894 0\n"
veqqqPlayground