Skip to content

Instantly share code, notes, and snippets.

@erikrozendaal
Last active December 27, 2015 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikrozendaal/7354327 to your computer and use it in GitHub Desktop.
Save erikrozendaal/7354327 to your computer and use it in GitHub Desktop.
Creating exceptions with and without stacktrace. Measured on a early 2013 MacBook Pro 13" retina.
$ scala -cp Thyme.jar
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val th = new ichi.bench.Thyme
th: ichi.bench.Thyme = ichi.bench.Thyme@7464fb1c
scala> th.pbenchOff[Exception]("stacktraces")(new Exception("foo") with scala.util.control.NoStackTrace, ftitle = "without")(new Exception("foo"), htitle = "with")
Benchmark comparison (in 20.94 s): stacktraces
without vs with
Significantly different (p ~= 0)
Time ratio: 253.49560 95% CI 233.97146 - 273.01974 (n=20)
without 9.520 ns 95% CI 9.194 ns - 9.845 ns
with 2.413 us 95% CI 2.247 us - 2.580 us
res1: Exception = java.lang.Exception: foo
scala> res1.printStackTrace
java.lang.Exception: foo
at $line5.$read$$iw$$iw$$anonfun$2.apply(<console>:9)
at $line5.$read$$iw$$iw$$anonfun$2.apply(<console>:9)
at ichi.bench.Thyme$$anonfun$benchOff$1.apply$mcVI$sp(Thyme.scala:620)
at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:141)
at ichi.bench.Thyme.benchOff(Thyme.scala:591)
at ichi.bench.Thyme.benchOffPair(Thyme.scala:689)
at ichi.bench.Thyme.pbenchOff(Thyme.scala:706)
at $line5.$read$$iw$$iw$.<init>(<console>:9)
at $line5.$read$$iw$$iw$.<clinit>(<console>)
at $line5.$eval$.<init>(<console>:7)
at $line5.$eval$.<clinit>(<console>)
at $line5.$eval.$print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983)
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:756)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:801)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:713)
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:577)
at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:584)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:587)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:878)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:833)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:833)
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:833)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:83)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:105)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
scala>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment