I would like to compare Guava and Apache commons IO to copy an InputStream to an OutputStream:
I compared the speed of (2 Threads starting at same time, with CyclicBarrier
) :
- org.apache.commons.io.IOUtils.copy
- com.google.common.io.ByteStreams.copy
On a 4Go size file, the result is exactly the same, and here my question, I don't understand how is that possible except if the code behind is exactly the same or other reasons, but to be honest I think something wrong with my Test class ?
Result
all threads started
commonsIo perf:PT6M21.281S
Guava perf:PT6M21.282S
Code:
public class Test {
public static void main(String... a) throws InterruptedException, BrokenBarrierException {
final CyclicBarrier gate = new CyclicBarrier(3);
Thread t1 = new Thread() {
public void run() {
try {
gate.await();
Instant start = Instant.now();
IOUtils.copy(Files.newInputStream(Paths.get("C:\\Users\\emil.brigand\\Downloads\\CentOS-6.4-x86_64-bin-DVD1.iso")), Files.newOutputStream(Paths.get("C:\\Users\\emil.brigand\\Downloads\\CentOS-6.4-x86_64-bin-DVD12.iso"), StandardOpenOption.CREATE_NEW, StandardOpenOption.DELETE_ON_CLOSE));
Instant end = Instant.now();
System.out.println("commonsIo perf:" + Duration.between(start, end));
} catch (InterruptedException e) {
e.printStackTrace();
} catch (BrokenBarrierException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
};
Thread t2 = new Thread() {
public void run() {
try {
gate.await();
Instant start = Instant.now();
ByteStreams.copy(Files.newInputStream(Paths.get("C:\\Users\\emil.brigand\\Downloads\\CentOS-6.4-x86_64-bin-DVD1.iso")), Files.newOutputStream(Paths.get("C:\\Users\\emil.brigand\\Downloads\\CentOS-6.4-x86_64-bin-DVD11.iso"), StandardOpenOption.CREATE_NEW, StandardOpenOption.DELETE_ON_CLOSE));
Instant end = Instant.now();
System.out.println("Guava perf:" + Duration.between(start, end));
} catch (InterruptedException e) {
e.printStackTrace();
} catch (BrokenBarrierException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
};
t1.start();
t2.start();
gate.await();
System.out.println("all threads started");
}
}