Skip to content

Instantly share code, notes, and snippets.

@KetothXupack
Last active August 24, 2016 11:36
Show Gist options
  • Save KetothXupack/3ba9a273c53b1382a193cc6423db1c21 to your computer and use it in GitHub Desktop.
Save KetothXupack/3ba9a273c53b1382a193cc6423db1c21 to your computer and use it in GitHub Desktop.
package org.nohope;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.infra.Blackhole;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
/**
*/
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
public class ExceptionEliminating {
@Benchmark
@OperationsPerInvocation(10000)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void checkThowEliminating(Blackhole blackhole) throws IOException {
testTryCatch(blackhole);
}
public void testTryCatch(Blackhole blackhole) throws IOException {
for (int i = 0; i < 2; i++) {
try {
doSomeIO(blackhole, i);
} catch (IOException e) {
throw e;
}
}
}
public void doSomeIO(Blackhole blackhole, int i) throws IOException {
if (i < 0) {
throw new IOException();
}
blackhole.consume(i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment