nippy/benchmarks/benchmarks.clj

41 lines
1.4 KiB
Clojure
Raw Normal View History

2012-07-06 19:12:59 +00:00
(ns taoensso.nippy.benchmarks
{:author "Peter Taoussanis"}
2012-07-12 08:35:12 +00:00
(:use [taoensso.nippy :as nippy :only (freeze-to-bytes thaw-from-bytes)])
(:require [taoensso.nippy.utils :as utils]))
2012-07-06 19:12:59 +00:00
;; Remove stuff from stress-data that breaks reader
2012-07-12 08:35:12 +00:00
(def data (dissoc nippy/stress-data :queue :queue-empty :bytes))
(defmacro bench [& body] `(utils/bench 10000 (do ~@body) :warmup-laps 1000))
2012-07-06 19:12:59 +00:00
(defn reader-freeze [x] (binding [*print-dup* false] (pr-str x)))
(defn reader-thaw [x] (binding [*read-eval* false] (read-string x)))
(def roundtrip (comp thaw-from-bytes freeze-to-bytes))
(def reader-roundtrip (comp reader-thaw reader-freeze))
(comment
;;; Times
(println
"---\n"
{:reader {:freeze (bench (reader-freeze data))
:thaw (let [frozen (reader-freeze data)]
2012-07-12 08:35:12 +00:00
(bench (reader-thaw frozen)))
:round (bench (reader-roundtrip data))}
2012-07-12 08:35:12 +00:00
:nippy {:freeze (bench (freeze-to-bytes data))
:thaw (let [frozen (freeze-to-bytes data)]
2012-07-12 08:35:12 +00:00
(bench (thaw-from-bytes frozen)))
:round (bench (roundtrip data))}})
2012-07-06 19:12:59 +00:00
;; Clojure 1.3.0, Nippy 0.9.0
;; {:reader {:freeze 23573, :thaw 31923, :round 53253},
;; :nippy {:freeze 3805, :thaw 3789, :round 7522}}
;; (float (/ 53253 7522)) = 7.079633
;;; Data size
(let [frozen (reader-freeze data)] (count (.getBytes frozen "UTF8")))
(let [frozen (freeze-to-bytes data)] (count frozen))
2012-07-06 19:12:59 +00:00
;; 22711, 12168
)