Last active
August 15, 2020 10:43
-
-
Save doom369/7346b0ea98fd6493a5214ef6706a0457 to your computer and use it in GitHub Desktop.
This file contains 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
@BenchmarkMode(Mode.AverageTime) | |
@Fork(value = 1) | |
@State(Scope.Thread) | |
@Warmup(iterations = 5, time = 1) | |
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |
@Measurement(iterations = 10, time = 1) | |
public class StringBuilderChainingFailure { | |
String[] sqlColumnNames; | |
@Setup | |
public void setup() { | |
sqlColumnNames = new String[] {"a", "b"}; | |
} | |
@Benchmark | |
public String noChaining() { | |
final StringBuilder left = new StringBuilder( "(" ); | |
left.append( String.join( ", ", sqlColumnNames ) ); | |
return left.append( ")" ).toString(); | |
} | |
@Benchmark | |
public String explicitConcat() { | |
return "(" + String.join(", ", sqlColumnNames) + ")"; | |
} | |
@Benchmark | |
public String explicitConcatImproved() { | |
String joinedColumns = String.join(", ", sqlColumnNames); | |
return "(" + joinedColumns + ")"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment