Skip to content

Instantly share code, notes, and snippets.

@ato
Created October 8, 2010 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ato/616655 to your computer and use it in GitHub Desktop.
Save ato/616655 to your computer and use it in GitHub Desktop.
(defn microbench-lock []
(let [ba (byte-array 100000000)]
(time (dotimes [i 80000000] (locking ba (aset ba i (byte 0)))))))
(dotimes [j 10] (microbench-lock))
"Elapsed time: 9323.400529 msecs"
"Elapsed time: 9181.996864 msecs"
"Elapsed time: 9084.981462 msecs"
"Elapsed time: 9090.169757 msecs"
"Elapsed time: 9162.061647 msecs"
[... (got bored and stopped it)]
(defn microbench-nolock []
(let [ba (byte-array 100000000)]
(time (dotimes [i 80000000] (aset ba i (byte 0))))))
(dotimes [j 10] (microbench-nolock))
"Elapsed time: 51.819095 msecs"
"Elapsed time: 47.302764 msecs"
"Elapsed time: 46.975915 msecs"
"Elapsed time: 46.790621 msecs"
"Elapsed time: 47.223832 msecs"
"Elapsed time: 46.95477 msecs"
"Elapsed time: 47.31063 msecs"
"Elapsed time: 47.218298 msecs"
"Elapsed time: 47.412488 msecs"
"Elapsed time: 47.326872 msecs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment