Housekeeping
This commit is contained in:
parent
9a38a12e11
commit
ab3209f2dc
4 changed files with 20 additions and 37 deletions
|
|
@ -174,7 +174,7 @@
|
||||||
stream (DataOutputStream. ba)]
|
stream (DataOutputStream. ba)]
|
||||||
(freeze-to-stream! stream x print-dup?)
|
(freeze-to-stream! stream x print-dup?)
|
||||||
(let [ba (.toByteArray ba)
|
(let [ba (.toByteArray ba)
|
||||||
ba (if compress? (utils/compress-bytes ba) ba)
|
ba (if compress? (utils/compress-snappy ba) ba)
|
||||||
ba (if password (crypto/encrypt-aes128 password ba) ba)]
|
ba (if password (crypto/encrypt-aes128 password ba) ba)]
|
||||||
ba)))
|
ba)))
|
||||||
|
|
||||||
|
|
@ -260,7 +260,7 @@
|
||||||
}}]
|
}}]
|
||||||
(try
|
(try
|
||||||
(-> (let [ba (if password (crypto/decrypt-aes128 password ba) ba)
|
(-> (let [ba (if password (crypto/decrypt-aes128 password ba) ba)
|
||||||
ba (if compressed? (utils/uncompress-bytes ba) ba)]
|
ba (if compressed? (utils/uncompress-snappy ba) ba)]
|
||||||
ba)
|
ba)
|
||||||
(ByteArrayInputStream.)
|
(ByteArrayInputStream.)
|
||||||
(DataInputStream.)
|
(DataInputStream.)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
(ns taoensso.nippy.benchmarks
|
(ns taoensso.nippy.benchmarks
|
||||||
{:author "Peter Taoussanis"}
|
{:author "Peter Taoussanis"}
|
||||||
(:use [taoensso.nippy :as nippy :only (freeze-to-bytes thaw-from-bytes)])
|
(:use [taoensso.nippy :as nippy :only (freeze-to-bytes thaw-from-bytes)])
|
||||||
(:require [taoensso.nippy.utils :as utils]
|
(:require [taoensso.nippy.utils :as utils]))
|
||||||
[taoensso.nippy.crypto :as crypto]))
|
|
||||||
|
|
||||||
;; Remove stuff from stress-data that breaks reader
|
;; Remove stuff from stress-data that breaks reader
|
||||||
(def data (dissoc nippy/stress-data :queue :queue-empty :bytes))
|
(def data (dissoc nippy/stress-data :queue :queue-empty :bytes))
|
||||||
|
|
@ -19,8 +18,8 @@
|
||||||
(def roundtrip-fast (comp #(nippy/thaw-from-bytes % :compressed? false)
|
(def roundtrip-fast (comp #(nippy/thaw-from-bytes % :compressed? false)
|
||||||
#(nippy/freeze-to-bytes % :compress? false)))
|
#(nippy/freeze-to-bytes % :compress? false)))
|
||||||
|
|
||||||
(defn autobench [] (bench (roundtrip-defaults data)
|
(defn autobench [] {:defaults (bench (roundtrip-defaults data))
|
||||||
(roundtrip-encrypted data)))
|
:encrypted (bench (roundtrip-encrypted data))})
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
(ns taoensso.nippy.utils
|
(ns taoensso.nippy.utils
|
||||||
{:author "Peter Taoussanis"}
|
{:author "Peter Taoussanis"}
|
||||||
(:require [clojure.string :as str])
|
(:require [clojure.string :as str]))
|
||||||
(:import org.iq80.snappy.Snappy))
|
|
||||||
|
|
||||||
(defmacro case-eval
|
(defmacro case-eval
|
||||||
"Like `case` but evaluates test constants for their compile-time value."
|
"Like `case` but evaluates test constants for their compile-time value."
|
||||||
|
|
@ -14,25 +13,12 @@
|
||||||
clauses)
|
clauses)
|
||||||
~(when default default))))
|
~(when default default))))
|
||||||
|
|
||||||
(defn pairs
|
(defmacro time-ns "Returns number of nanoseconds it takes to execute body."
|
||||||
"Like (partition 2 coll) but faster and returns lazy seq of vector pairs."
|
[& body] `(let [t0# (System/nanoTime)] ~@body (- (System/nanoTime) t0#)))
|
||||||
[coll]
|
|
||||||
(lazy-seq
|
|
||||||
(when-let [s (seq coll)]
|
|
||||||
(let [n (next s)]
|
|
||||||
(cons [(first s) (first n)] (pairs (next n)))))))
|
|
||||||
|
|
||||||
(defmacro time-ns
|
|
||||||
"Returns number of nanoseconds it takes to execute body."
|
|
||||||
[& body]
|
|
||||||
`(let [t0# (System/nanoTime)]
|
|
||||||
~@body
|
|
||||||
(- (System/nanoTime) t0#)))
|
|
||||||
|
|
||||||
(defmacro bench
|
(defmacro bench
|
||||||
"Repeatedly executes form and returns time taken to complete execution."
|
"Repeatedly executes form and returns time taken to complete execution."
|
||||||
[num-laps form & {:keys [warmup-laps num-threads as-ms?]
|
[num-laps form & {:keys [warmup-laps num-threads as-ns?]}]
|
||||||
:or {as-ms? true}}]
|
|
||||||
`(try (when ~warmup-laps (dotimes [_# ~warmup-laps] ~form))
|
`(try (when ~warmup-laps (dotimes [_# ~warmup-laps] ~form))
|
||||||
(let [nanosecs#
|
(let [nanosecs#
|
||||||
(if-not ~num-threads
|
(if-not ~num-threads
|
||||||
|
|
@ -44,23 +30,17 @@
|
||||||
doall
|
doall
|
||||||
(map deref)
|
(map deref)
|
||||||
dorun))))]
|
dorun))))]
|
||||||
(if ~as-ms? (Math/round (/ nanosecs# 1000000.0)) nanosecs#))
|
(if ~as-ns? nanosecs# (Math/round (/ nanosecs# 1000000.0))))
|
||||||
(catch Exception e# (str "DNF: " (.getMessage e#)))))
|
(catch Exception e# (str "DNF: " (.getMessage e#)))))
|
||||||
|
|
||||||
(defn version-compare
|
(defn version-compare "Comparator for version strings like x.y.z, etc."
|
||||||
"Comparator for version strings like x.y.z, etc."
|
[x y] (let [vals (fn [s] (vec (map #(Integer/parseInt %) (str/split s #"\."))))]
|
||||||
[x y]
|
(compare (vals x) (vals y))))
|
||||||
(let [vals (fn [s] (vec (map #(Integer/parseInt %) (str/split s #"\."))))]
|
|
||||||
(compare (vals x) (vals y))))
|
|
||||||
|
|
||||||
(defn version-sufficient?
|
(defn version-sufficient? [version-str min-version-str]
|
||||||
[version-str min-version-str]
|
|
||||||
(try (>= (version-compare version-str min-version-str) 0)
|
(try (>= (version-compare version-str min-version-str) 0)
|
||||||
(catch Exception _ false)))
|
(catch Exception _ false)))
|
||||||
|
|
||||||
(defn compress-bytes [^bytes ba] (Snappy/compress ba))
|
|
||||||
(defn uncompress-bytes [^bytes ba] (Snappy/uncompress ba 0 (alength ba)))
|
|
||||||
|
|
||||||
(defn memoized
|
(defn memoized
|
||||||
"Like `memoize` but takes an explicit cache atom (possibly nil) and
|
"Like `memoize` but takes an explicit cache atom (possibly nil) and
|
||||||
immediately applies memoized f to given arguments."
|
immediately applies memoized f to given arguments."
|
||||||
|
|
@ -76,6 +56,10 @@
|
||||||
(comment (memoized nil +)
|
(comment (memoized nil +)
|
||||||
(memoized nil + 5 12))
|
(memoized nil + 5 12))
|
||||||
|
|
||||||
|
(defn compress-snappy ^bytes [^bytes ba] (org.iq80.snappy.Snappy/compress ba))
|
||||||
|
(defn uncompress-snappy ^bytes [^bytes ba] (org.iq80.snappy.Snappy/uncompress ba
|
||||||
|
0 (alength ba)))
|
||||||
|
|
||||||
(defn ba-concat ^bytes [^bytes ba1 ^bytes ba2]
|
(defn ba-concat ^bytes [^bytes ba1 ^bytes ba2]
|
||||||
(let [s1 (alength ba1)
|
(let [s1 (alength ba1)
|
||||||
s2 (alength ba2)
|
s2 (alength ba2)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue