-
-
Save daniellansun/565be52ee59b325324c1752dd8e44414 to your computer and use it in GitHub Desktop.
String concat Groovy
This file contains hidden or 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
@Grab(group='org.gperfutils', module='gbench', version='0.4.3-groovy-2.4') | |
String a = 'The quick brown fox' | |
String b = 'jumps over the lazy dog' | |
int x = 1 | |
double y = 2 | |
benchmark { | |
'simple concat' { | |
String concat = a + ' ' + b + ' ' + x + ' ' + y | |
} | |
'gstring' { | |
String concat = "$a $b $x $y" | |
} | |
'gstring (closures)' { | |
String concat = "${-> a} ${-> b} ${-> x} ${-> y}" | |
} | |
'StringBuilder' { | |
String concat = new StringBuilder() | |
.append(a).append(' ').append(b).append(' ').append(x).append(' ').append(y) | |
} | |
}.prettyPrint() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment