Created
October 3, 2009 17:32
-
-
Save digash/200761 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 write-speed | |
(:use [incanter core charts]) | |
(:import [java.io FileOutputStream])) | |
(set! clojure.core/*warn-on-reflection* true) | |
(defmacro with-time | |
"Evaluates expr and returns a vector of expression value and the | |
time it took to evaluate it in milliseconds." | |
[expr] | |
`(let [start# (. System (nanoTime)) | |
ret# ~expr | |
t# (/ (double (- (. System (nanoTime)) start#)) 1000000.0)] | |
[ret# t#])) | |
(def #^"[B" test-row (into-array Byte/TYPE (map byte (range 1e3)))) | |
(defn write-to-file [#^String file] | |
(with-open [s (FileOutputStream. file)] | |
(loop [i 0 r (transient [])] | |
(if (< i 1e3) | |
(recur (inc i) (conj! r (with-time | |
(doto s | |
(.write test-row) | |
(.flush))))) | |
(persistent! r))))) | |
(println "************* START ****************") | |
(def write-millis | |
(doall (for [i (range 20) | |
[v t] (write-to-file (format "test%d.lab" i))] | |
t))) | |
(println "************* DONE *****************") | |
(set! clojure.core/*warn-on-reflection* false) | |
(view (xy-plot (range (count write-millis)) write-millis | |
:title (System/getProperty "user.dir") | |
:x-label "1k blocks" | |
:y-label "milliseconds")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment