Skip to content

Instantly share code, notes, and snippets.

@jaor
Last active January 17, 2022 21:14
Show Gist options
  • Save jaor/01f0f887c2d7019389a6ae04ca3b510d to your computer and use it in GitHub Desktop.
Save jaor/01f0f887c2d7019389a6ae04ca3b510d to your computer and use it in GitHub Desktop.
create and delete sources in a loop
{
"name": "create sources",
"kind": "script",
"description": "loops creation/deletion of sources, reporting timings",
"source_code": "script.whizzml",
"imports":[
],
"inputs":[
{"name": "iterations",
"type": "number",
"default": 20,
"description": "number of sources to create"},
{"name": "polling",
"type": "boolean",
"default": true,
"description": "Whether to wait by polling GETs"}
],
"outputs":[
{
"name": "result",
"type": "list",
"description": "list of [id creation-time elapsed-time]"
}]
}
(define (polling-wait id)
(loop (s ((fetch id) "status"))
(when (!= 5 (s "code"))
(prog (sleep 1000)
(recur ((with-time-log (log-info id " - fetching") (fetch id))
"status"))))))
(define (doit iterations polling)
(for (n (range iterations))
(let (t (current-time)
iris (create-source {"remote" "https://static.bigml.com/csv/iris.csv"})
_ ((if polling polling-wait wait) iris)
d0 (/ (- (current-time) t) 1000)
e ((fetch iris) ["status" "elapsed"]))
(log-info n " " iris " create took " d0 " secs (elapsed: " e ")")
(let (t (current-time)
_ (delete iris)
d1 (/ (- (current-time) t) 1000))
(when (> d1 1) (log-info n " " iris " delete took " d1 " secs"))
[iris d0 e]))))
(define result (doit iterations polling))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment