Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Benchmark.ark
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# @brief Measure the time it takes to run some given code, in milliseconds
# @param tag Identifier for the code block (string)
# @param code Node of code to run
# @author https://github.com/SuperFola
(macro measureOnce (tag code) {
(mut _start (time))
{ code }
(print (format "{} took {:.4} ms" tag (* 1000 (- (time) _start)))) })

(import std.List)

# @brief Benchmark some given code by running it a given number of times
# @param code code to run, eg. a function call
# @param times number of times to run the code
# =begin
# (let fib (fun (n)
# (if (< n 2)
# n
# (+ (fib (- n 1)) (fib (- n 2))))))
# (bench (fib 23) 10)
# # (fib 23), 10 times
# # ↪︎ range: [4.7 - 5.02] ms
# # ↪︎ mean: 4.85ms
# # ↪︎ median: 4.86ms
# =end
# @author https://github.com/SuperFola
(macro bench (code times) {
(mut _i 0)
(mut _data [])
(while (< _i times) {
(let _start (time))
{ ($as-is code) }
(let _end (time))
(append! _data (* 1000 (- _end _start)))
(set _i (+ 1 _i)) })

(mut _mean (/ (list:sum _data) (len _data)))
(mut _median (list:median _data))
(mut _max (list:max _data))
(mut _min (list:min _data))
(print
(format
"{}, {} times\n ↪︎ range: [{:.3} - {:.3}] ms\n ↪︎ mean: {:.3}ms\n ↪︎ median: {:.3}ms"
($repr code) times _min _max _mean _median)) })
2 changes: 1 addition & 1 deletion Cli.ark
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

(+ headers synopsis "\n\nOPTIONS\n" options) }))

(let _match_group (fun (parsed args param) {
(let _match_group (fun (parsed (mut args) param) {
(mut missing_param false)
(mut i 0)
(while (and (not missing_param) (< i (len param.children))) {
Expand Down
1 change: 1 addition & 0 deletions Dict.ark
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

# @brief Checks if the dictionary has a given key
# @param _D dictionary
# @param _key key to check for its presence in the dict
# =begin
# (let data (dict "key" "value"))
# (print (dict:contains? data "key")) # true
Expand Down
8 changes: 8 additions & 0 deletions IO.ark
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
# @author https://github.com/SuperFola
(let readFile (fun (_name) (builtin__io:readFile _name)))

# @brief Read the content from a file as a List of Strings
# @param filename the path of the file to read
# =begin
# (io:readLinesFile "hello.json")
# =end
# @author https://github.com/SuperFola
(let readLinesFile (fun (_name) (builtin__io:readLinesFile _name)))

# @brief Check if a file exists, return True or False
# @param filename the path of the file
# =begin
Expand Down
Loading
Loading