Skip to content

Instantly share code, notes, and snippets.

@yurylyt
Created October 25, 2012 08:18
Show Gist options
  • Save yurylyt/3951380 to your computer and use it in GitHub Desktop.
Save yurylyt/3951380 to your computer and use it in GitHub Desktop.
where-do-stack-traces-come-7
public class StackTraceBenchmark extends SimpleBenchmark {
@Param({"1", "10", "100", "1000"})
public int threadDepth;
public void timeWithoutException(int reps) throws InterruptedException {
while(--reps >= 0) {
notThrowing(threadDepth);
}
}
private int notThrowing(int depth) {
if(depth <= 0)
return depth;
return notThrowing(depth - 1);
}
//--------------------------------------
public void timeWithStackTrace(int reps) throws InterruptedException {
while(--reps >= 0) {
try {
throwingWithStackTrace(threadDepth);
} catch (RuntimeException e) {
}
}
}
private void throwingWithStackTrace(int depth) {
if(depth <= 0)
throw new RuntimeException();
throwingWithStackTrace(depth - 1);
}
//--------------------------------------
public void timeWithoutStackTrace(int reps) throws InterruptedException {
while(--reps >= 0) {
try {
throwingWithoutStackTrace(threadDepth);
} catch (RuntimeException e) {
}
}
}
private void throwingWithoutStackTrace(int depth) {
if(depth <= 0)
throw new ExceptionFromHell();
throwingWithoutStackTrace(depth - 1);
}
//--------------------------------------
public static void main(String[] args) {
Runner.main(StackTraceBenchmark.class, new String[]{"--trials", "1"});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment