Skip to content

Instantly share code, notes, and snippets.

@mitio
Created October 19, 2012 16:07
Show Gist options
  • Save mitio/3919061 to your computer and use it in GitHub Desktop.
Save mitio/3919061 to your computer and use it in GitHub Desktop.
Tests for copying byte[] arrays
public class ByteArrayCopyTest {
private static long timeMark;
public static void main(String[] args) {
byte[] source = new byte[1000000];
byte[] target = new byte[1000000];
start();
for (int n = 0; n < 10000; n++) {
// System.arraycopy(source, 0, target, 0, source.length);
for (int i = 0; i < source.length; i++) {
target[i] = source[i];
}
}
endAndReport();
}
private static void start() {
timeMark = System.currentTimeMillis();
}
private static void endAndReport() {
long now = System.currentTimeMillis();
System.out.println("Execution time: " + (now - timeMark) + " ms");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment