Skip to content

Instantly share code, notes, and snippets.

@ato
Created October 8, 2010 11:32
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/616651 to your computer and use it in GitHub Desktop.
Save ato/616651 to your computer and use it in GitHub Desktop.
;; Clojure
(import 'java.io.ByteArrayOutputStream)
(defn microbench []
(let [baos (ByteArrayOutputStream. 100000000)]
(time (dotimes [i 80000000] (.write baos 0)))))
(dotimes [j 10] (microbench))
"Elapsed time: 427.485207 msecs"
"Elapsed time: 423.458867 msecs"
"Elapsed time: 421.879964 msecs"
"Elapsed time: 423.900782 msecs"
"Elapsed time: 423.651932 msecs"
"Elapsed time: 425.128776 msecs"
"Elapsed time: 422.608709 msecs"
"Elapsed time: 423.007863 msecs"
"Elapsed time: 429.286751 msecs"
"Elapsed time: 434.69319 msecs"
;; Java
import java.io.ByteArrayOutputStream;
public class baos {
public static void microbench() {
ByteArrayOutputStream baos = new ByteArrayOutputStream(100000000);
long start = System.currentTimeMillis();
for (int i = 0; i < 80000000; i++) {
baos.write(i);
}
baos.reset();
System.out.println("took " + (System.currentTimeMillis() - start) + " ms");
}
public static void main(String args[]) {
for (int i = 0; i < 10; i++) {
microbench();
}
}
}
$ java -server baos
took 1657 ms
took 1655 ms
took 1710 ms
took 432 ms
took 434 ms
took 434 ms
took 434 ms
took 440 ms
took 416 ms
took 415 ms
$ cat /proc/cpuinfo | grep name
model name : Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment