Skip to content

Instantly share code, notes, and snippets.

@davidsantiago
Created March 7, 2012 02:49
Show Gist options
  • Save davidsantiago/1990573 to your computer and use it in GitHub Desktop.
Save davidsantiago/1990573 to your computer and use it in GitHub Desktop.
;; Organizing idea is that there are benchmark tasks, which are basically abstract
;; goals you might want to do, apart from any code. And then there are benchmark functions,
;; or variants, that render these concretely into hypothesized bits of code. This helps
;; you compare various implementations of the same task easily.
;;
;; Benchmark framework then takes all your functions, and runs them on your command,
;; generating a report at the end of how all the variants did all the test tasks.
;;
;; A benchmark might need to have data set up and cleanup that is apart from the part that
;; you want to actually benchmark. So you want some way to separate out those phases and
;; still tie them together so that the code can count on those things having been done,
;; to ensure correctness.
;; They have to know the names of the various phases....
(defbenchmark basic-test
"Basic test of template speed"
:setup nil
:variants {})
;; They have to know the format of the map structure, and name phases etc.
;; But no special magic macros needed...
(def basic-test
{:setup nil
:variants {:hiccup {:setup nil :action #(...) :cleanup nil}
:enlive {:setup nil :action #(...) :cleanup nil}}
:cleanup nil})
;; Groups the benchmark task and variants, lets you have setup tasks
;; as lexical bindings instead of going through vars. But cleanup code is very
;; awkward, as is having defs inside of defs.
(defbenchtask basic-test "Basic test of template speed"
(defbenchfn basic-test-hiccup
"Basic test of template speed for hiccup"
[my-bindings (load my-data)]
(the body of the test function...)
finally (cleanup stuff))
(defbenchfn basic-test-enlive
...)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment