Created
June 9, 2017 16:42
-
-
Save melix/dc96c3c36adfae63c3f0dabda2fe6e62 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
Shows: