Created
October 25, 2012 08:18
-
-
Save yurylyt/3951380 to your computer and use it in GitHub Desktop.
where-do-stack-traces-come-7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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