benchmark for lazy deserialization

5 views
Skip to first unread message

William la Forge

unread,
Sep 28, 2015, 10:52:20 AM9/28/15
to AgileWikiDevelopers
Wrote a first benchmark. And it looks like the time is about the same as it was for Java!

Time to build a vector of size 100000 = 2349000.0 microseconds

Time per entry: 23.49 microseconds

Time to perform 1000 updates = 1940000.0 microseconds

Time per update: 1940.0 microseconds

So in 2 milliseconds we can (partially) deserialize a vector with a million items, update an entry in that vector, and then reserialize the vector.


Here's the code:


(ns aatree.vector-updates
(:require [aatree.core :refer :all])
(:import (java.nio ByteBuffer)))

(def vector-size 1000000)
(def updates 1000)

(println)
(def t0 (System/currentTimeMillis))
(def lazy-vector (reduce conj emptyLazyAAVector (range vector-size)))
(def t1 (System/currentTimeMillis))
(def micr-0 (* 1000. (- t1 t0)))
(println "Time to build a vector of size" vector-size "=" micr-0 "microseconds")
(println "Time per entry:" (/ micr-0 vector-size) "microseconds")

(defn upd [v i]
(let [v1 (assoc v i (- i))
bb (ByteBuffer/allocate (lazy-byte-length v1))]
(lazy-write v1 bb)
(.flip bb)
(load-aavector bb)))

(println)
(def t0 (System/currentTimeMillis))
(def lazy-vector (reduce upd lazy-vector (range updates)))
(def t1 (System/currentTimeMillis))
(def micr-0 (* 1000. (- t1 t0)))
(println "Time to deserialize/update/reserialize " updates "times =" micr-0 "microseconds")
(println "Time per complete update:" (/ micr-0 updates) "microseconds")

(println)

William la Forge

unread,
Sep 28, 2015, 10:57:18 AM9/28/15
to AgileWikiDevelopers
Oops. I showed the results for 100 thousand items.

William la Forge

unread,
Sep 28, 2015, 10:59:23 AM9/28/15
to AgileWikiDevelopers
Here's the correct timings. And it is 8 times slower than the java.

Time to build a vector of size 1000000 = 2.7142E7 microseconds
Time per entry: 27.142 microseconds

Time to deserialize/update/reserialize  1000 times = 1.6171E7 microseconds
Time per complete update: 16171.0 microseconds

Raoul Duke

unread,
Sep 28, 2015, 1:58:53 PM9/28/15
to AgileWikiDevelopers
next up: why? :-)

William la Forge

unread,
Sep 28, 2015, 3:43:00 PM9/28/15
to AgileWikiDevelopers
That was the old JActor1, which was back when I was sweating every nanosecond.

The clojure code aims for brevity and clarity, not speed. Speed is important, but only if there is adoption! So I cheat a lot and use things like pr-str to serialize all the data except for the top-level vector or map. But now you can read the code in hours rather than weeks.

So I guess I've gone all soft and pedagogical. Just got tired of writing magic. This at least should be quite maintainable! And besides, it is well known that writing fast clojure is very difficult--which is one of the justifications for clojure not to be written in clojure.


On Mon, Sep 28, 2015 at 1:58 PM, Raoul Duke <rao...@gmail.com> wrote:
next up: why? :-)

--
You received this message because you are subscribed to the Google Groups "AgileWikiDevelopers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to agilewikidevelo...@googlegroups.com.
To post to this group, send email to agilewiki...@googlegroups.com.
Visit this group at http://groups.google.com/group/agilewikidevelopers.
For more options, visit https://groups.google.com/d/optout.

William la Forge

unread,
Sep 28, 2015, 3:44:08 PM9/28/15
to AgileWikiDevelopers
Now here's the results for the lazy map benchmark: 

Time to build a map of size 1000000 = 2.0032E7 microseconds
Time per entry: 20.032 microseconds

Time to deserialize/update/reserialize  1000 times = 3.0838E7 microseconds
Time per complete update: 30838.0 microseconds

Reply all
Reply to author
Forward
0 new messages