Skip to content

Instantly share code, notes, and snippets.

@ato
Created October 8, 2010 12:35
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/616708 to your computer and use it in GitHub Desktop.
Save ato/616708 to your computer and use it in GitHub Desktop.
public class babench {
public static void microbench() {
byte[] ba = new byte[100000000];
long start = System.currentTimeMillis();
for (int i = 0; i < 80000000; i++) {
synchronized (ba) {
ba[i] = 0;
}
}
System.out.println("took " + (System.currentTimeMillis() - start) + " ms");
}
public static void main(String args[]) {
for (int i = 0; i < 10; i++) {
microbench();
}
}
}
/*
took 417 ms
took 414 ms
took 409 ms
took 409 ms
took 409 ms
took 410 ms
took 409 ms
took 411 ms
took 410 ms
took 411 ms
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment