Skip to content

Instantly share code, notes, and snippets.

@bodiam
Last active August 29, 2015 14:05
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 bodiam/48a06dc9c74a90dfba8c to your computer and use it in GitHub Desktop.
Save bodiam/48a06dc9c74a90dfba8c to your computer and use it in GitHub Desktop.
@Grab(group='org.gperfutils', module='gbench', version='0.4.2-groovy-2.1')
import java.lang.String
trait NoStackTrace {
Throwable fillInStackTrace() {
return this
}
}
class ExpensiveException extends RuntimeException { }
class CheapException extends RuntimeException implements NoStackTrace {}
def r = benchmark {
'Cheap Exception' {
def e = new CheapException()
}
'Expensive Exception' {
def e = new ExpensiveException()
}
'Make expensive exception cheap' {
def e = new ExpensiveException() as NoStackTrace
}
}
r.prettyPrint()
Environment
===========
* Groovy: 2.3.6
* JVM: Java HotSpot(TM) 64-Bit Server VM (25.0-b70, Oracle Corporation)
* JRE: 1.8.0
* Total Memory: 245 MB
* Maximum Memory: 3641 MB
* OS: Mac OS X (10.9.4, x86_64)
Options
=======
* Warm Up: Auto (- 60 sec)
* CPU Time Measurement: On
user system cpu real
Cheap Exception 42 0 42 43
Expensive Exception 6722 3 6725 6734
Make expensive exception cheap 14982 7 14989 15010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment