Last active
January 3, 2016 17:09
-
-
Save mbossenbroek/8493699 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns pigpen.benchmark | |
(:require [taoensso.nippy :as nippy] | |
[clojure.data.fressian :as fressian] | |
[clojure.data]) | |
(:import [java.nio ByteBuffer])) | |
(set! *warn-on-reflection* true) | |
(defn bench-nippy [f] | |
(prn (count (nippy/freeze (f) {:legacy-mode true, :compressor nil}))) | |
(dotimes [_ 10] | |
(time | |
(dotimes [_ 1000000] | |
(nippy/thaw (nippy/freeze (f) {:legacy-mode true, :compressor nil}) | |
{:legacy-opts {:compressed? false}}))))) | |
(defn fressian-freeze [value] | |
(let [^ByteBuffer buffer (fressian/write value) | |
len (.remaining buffer) | |
bytes (byte-array len)] | |
(.get buffer bytes 0 len) | |
bytes)) | |
(defn fressian-thaw [value] | |
(let [buffer (ByteBuffer/wrap value)] | |
(fressian/read buffer))) | |
(defn test-roundtrip [] | |
(let [data (dissoc nippy/stress-data | |
:queue | |
:queue-empty | |
:byte | |
:throwable | |
:exception | |
:ex-info)] | |
(take 2 | |
(clojure.data/diff | |
data | |
(fressian-thaw (fressian-freeze data)))))) | |
(defn bench-fressian [f] | |
(prn (count (fressian-freeze (f)))) | |
(dotimes [_ 10] | |
(time | |
(dotimes [_ 1000000] | |
(fressian-thaw (fressian-freeze (f))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment