@Grab('com.googlecode.gbench:gbench:0.3.1-groovy-2.0')
@Grab('commons-lang:commons-lang:2.6')
import gbench.*
import org.apache.commons.lang.StringUtils
new BenchmarkBuilder().run {
'jdk.String.split' {
100.times{ "a b c d e f g h i j k l m n o p q r s t u v w x y z".split(" ") }
}
'commons-lang.StringUtils.split' {
100.times{ StringUtils.split("a b c d e f g h i j k l m n o p q r s t u v w x y z", " ") }
}
}.prettyPrint()
I ran above and get the following on my machine:
$ groovy benchmarkSplit.groovy
Environment
===========
* Groovy: 2.0.0
* JVM: Java HotSpot(TM) Client VM (20.1-b02, Sun Microsystems Inc.)
* JRE: 1.6.0_26
* Total Memory: 15.5 MB
* Maximum Memory: 247.5 MB
* OS: Windows XP (5.1, x86)
Options
=======
* Warm Up: Auto
* CPU Time Measurement: On
user system cpu real
jdk.String.split 663219 0 663219 693382
commons-lang.StringUtils.split 192721 0 192721 212359
Hi, it seems that your example code compares same code (String.split) :)
ReplyDeleteIf you run it with the second test being StringUtils.split( ..., " " ), I get:
ReplyDeletejdk.String.split 284934
commons-lang.StringUtils.split 106498
Oops! Thank you for pointing it out Nagai and Tim. I guess after edited the post few times (in attempt to pretty it up), I messed it up.
ReplyDeleteI have fixed the code sample and re-printed the result now. Thanks again!