Skip to content

Commit

Permalink
Reduce size of output file after upgrading to criterium 0.4.2
Browse files Browse the repository at this point in the history
Criterium 0.4.2 returns the full benchmark expression return values in
the map it returns.  The previous version I was using only had the
.hashCode values of the expression return values, which was much
smaller to print in most cases.  Do not change criterium, but replace
the :results key with a :result-hashes key that contains only the
result hashes.
  • Loading branch information
jafingerhut committed Nov 7, 2013
1 parent 5669d0d commit d29c6b7
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions cljexprs/src/cljexprs/core.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@
(:name os) (:version os)))) (:name os) (:version os))))




(defn replace-results-with-hashes
"An earlier version of criterium returned only the .hashCode values
of the resutls of the benchmark expressions. With criterium 0.4.2 it
returns the actual values. Some of these are much larger than I want
to record in my output files, so replace them with the hash values."
[results]
(let [rs (:results results)]
(-> results
(dissoc :results)
(assoc :result-hashes (map hash rs)))))


(defmacro benchmark (defmacro benchmark
[bindings expr & opts] [bindings expr & opts]
`(do `(do
Expand All @@ -114,7 +126,7 @@
(pp/pprint {:bindings '~bindings (pp/pprint {:bindings '~bindings
:expr '~expr :expr '~expr
:opts '~opts :opts '~opts
:results results#}) :results (replace-results-with-hashes results#)})
(iprintf *err* " %s\n" (time-with-scale (first (:mean results#)))) (iprintf *err* " %s\n" (time-with-scale (first (:mean results#))))
;; (iprintf *err* " %s\n" (platform-desc results#)) ;; (iprintf *err* " %s\n" (platform-desc results#))
)) ))
Expand Down Expand Up @@ -166,7 +178,7 @@
(pp/pprint {:bindings bindings# (pp/pprint {:bindings bindings#
:expr expr# :expr expr#
:opts nil :opts nil
:results results#})) :results (replace-results-with-hashes results#)}))
;; (iprintf *err* " %s\n" (time-with-scale (first (:mean results#)))) ;; (iprintf *err* " %s\n" (time-with-scale (first (:mean results#))))
)) ))
(flush))) (flush)))
Expand Down Expand Up @@ -712,9 +724,10 @@
%s [ help | -h | --help ] %s [ help | -h | --help ]
%s replace-leiningen-project-clojure-version <project.clj> <clj_version_str> <newproject.clj> %s replace-leiningen-project-clojure-version <project.clj> <clj_version_str> <newproject.clj>
%s benchmark <output_file> <benchmark_set_name> %s benchmark <output_file> <benchmark_set_name>
" prog-name prog-name prog-name)) %s report <output_file> ...
" prog-name prog-name prog-name prog-name))


(def prog-name "lein2 run") (def prog-name "lein run")




(defn -main [& args] (defn -main [& args]
Expand Down

0 comments on commit d29c6b7

Please sign in to comment.