Created
March 1, 2015 16:18
-
-
Save bcotton/d95703f1b41939b273e9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 hdr-histogram-profile.core | |
(:require [taoensso.timbre :as timbre]) | |
(:import [org.HdrHistogram Histogram HistogramLogWriter] | |
[java.nio ByteBuffer])) | |
(timbre/refer-timbre) | |
(defnp record [^Histogram h value] | |
(.recordValue h value) | |
h) | |
(defn encoded-size [^Histogram h] | |
(.getNeededByteBufferCapacity h)) | |
(defn byte-buffer-for [^Histogram h] | |
(ByteBuffer/allocate (encoded-size h))) | |
(defnp encode [^Histogram h] | |
(let [buffer (byte-buffer-for h)] | |
(.encodeIntoByteBuffer h buffer) | |
(.rewind buffer))) | |
(defnp decode [^ByteBuffer b max-value] | |
(Histogram/decodeFromByteBuffer b max-value)) | |
(defnp decode-record-encode [^ByteBuffer buffer value] | |
(-> buffer | |
(decode 10000) | |
(record value) | |
(encode))) | |
(defn histogram | |
([significant-digits] | |
(Histogram. significant-digits)) | |
([ceiling significant-digits] | |
(Histogram. ceiling significant-digits)) | |
([floor ceiling significant-digits] | |
(Histogram. floor ceiling significant-digits))) | |
(comment | |
(defproject hdr-histogram-profile "0.1.0-SNAPSHOT" | |
:description "FIXME: write description" | |
:url "http://example.com/FIXME" | |
:license {:name "Eclipse Public License" | |
:url "http://www.eclipse.org/legal/epl-v10.html"} | |
:dependencies [[org.clojure/clojure "1.6.0"] | |
[org.hdrhistogram/HdrHistogram "2.1.4"] | |
[com.taoensso/timbre "3.4.0"]]) | |
(profile :info :decode-record-encode | |
(let [h (histogram 10000 3) | |
store (atom (encode h))] | |
(dotimes [n 1000000] | |
(reset! store (decode-record-encode @store (rand-int 10000)))) | |
(info "Total count" (.getTotalCount (decode @store 10000))))) | |
"2015-Mar-01 09:08:21 -0700 bcotton-MBR.local INFO [hdr-histogram-profile.core] - Total count 1000000 | |
2015-Mar-01 09:08:21 -0700 bcotton-MBR.local INFO [hdr-histogram-profile.core] - Profiling: :hdr-histogram-profile.core/decode-record-encode | |
Id nCalls Min Max MAD Mean Time% Time | |
:hdr-histogram-profile.core/decode-record-encode 1,000,000 21.0μs 96.0ms 8.0μs 63.0μs 97 63.1s | |
:hdr-histogram-profile.core/decode 1,000,001 0ns 6.0ms 3.0μs 35.0μs 54 34.7s | |
:hdr-histogram-profile.core/encode 1,000,001 0ns 8.0ms 2.0μs 23.0μs 36 23.5s | |
:timbre/stats-gc 36 36.0ms 57.0ms 5.0ms 48.0ms 3 1.7s | |
:hdr-histogram-profile.core/record 1,000,000 0ns 39.0μs 95ns 50ns 0 51.0ms | |
Clock Time 100 64.8s | |
Accounted Time 190 123.1s" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment