Created
October 11, 2018 16:28
-
-
Save jac18281828/8f648f11f13646f3e29148456f4e6ea6 to your computer and use it in GitHub Desktop.
Here is why Java 10 is awesome ;-)
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
import org.junit.Ignore; | |
import org.junit.Test; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class StringPerformerTest { | |
private static final Logger log = LoggerFactory.getLogger(StringPerformerTest.class); | |
private static final String S1 = "table"; | |
private static final String S2 = "variable"; | |
private static final String S3 = "Monkeys MIGHT 'Climb out of my ass'"; | |
@Test | |
public void testBasic() { | |
for(int i=0; i<3; i++) { | |
final long start = System.nanoTime(); | |
for(int j=0; j<1_000_000; j++) { | |
basic(S1, S2, S3); | |
} | |
final long run = System.nanoTime() - start; | |
log.info("Time was {}ns, {}/s", run/1E6, 1E6/(run/1e9)); | |
} | |
} | |
@Test | |
public void testStringBuilder() { | |
for(int i=0; i<3; i++) { | |
final long start = System.nanoTime(); | |
for(int j=0; j<1_000_000; j++) { | |
stringBuilder(S1, S2, S3); | |
} | |
final long run = System.nanoTime() - start; | |
log.info("Time was {}ns, {}/s", run/1E6, 1E6/(run/1e9)); | |
} | |
} | |
@Test | |
public void testStringBuilderSize() { | |
for(int i=0; i<3; i++) { | |
final long start = System.nanoTime(); | |
for(int j=0; j<1_000_000; j++) { | |
stringBuilderSize(S1, S2, S3); | |
} | |
final long run = System.nanoTime() - start; | |
log.info("Time was {}ns, {}/s", run/1E6, 1E6/(run/1e9)); | |
} | |
} | |
@Ignore | |
public static String basic(String s1, String s2, String s3) { | |
return "SELECT " + s1 + " FROM " + s2 + " WHERE " + s3; | |
} | |
@Ignore | |
public static String stringBuilder(String s1, String s2, String s3) { | |
return new StringBuilder().append("SELECT ").append(s1) | |
.append(" FROM ").append(s2).append(" WHERE ") | |
.append(s3).toString(); | |
} | |
@Ignore | |
public static String stringBuilderSize(String s1, String s2, String s3) { | |
int len = 20 + s1.length() + s2.length() + s3.length(); | |
return new StringBuilder(len).append("SELECT ").append(s1) | |
.append(" FROM ").append(s2).append(" WHERE ") | |
.append(s3).toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment