daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Oct 11th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.junit.Ignore;
  2. import org.junit.Test;
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5.  
  6. public class StringPerformerTest {
  7.  
  8.     private static final Logger log = LoggerFactory.getLogger(StringPerformerTest.class);
  9.  
  10.     private static final String S1 = "table";
  11.     private static final String S2 = "variable";
  12.     private static final String S3 = "Monkeys MIGHT 'Climb out of my ass'";
  13.  
  14.     @Test
  15.     public void testBasic() {
  16.         for(int i=0; i<3; i++) {
  17.             final long start = System.nanoTime();
  18.             for(int j=0; j<1_000_000; j++) {
  19.                 basic(S1, S2, S3);
  20.             }
  21.             final long run = System.nanoTime() - start;
  22.             log.info("Time was {}ns, {}/s", run/1E6, 1E6/(run/1e9));
  23.  
  24.         }
  25.     }
  26.  
  27.     @Test
  28.     public void testStringBuilder() {
  29.         for(int i=0; i<3; i++) {
  30.             final long start = System.nanoTime();
  31.             for(int j=0; j<1_000_000; j++) {
  32.                 stringBuilder(S1, S2, S3);
  33.             }
  34.             final long run = System.nanoTime() - start;
  35.             log.info("Time was {}ns, {}/s", run/1E6, 1E6/(run/1e9));
  36.  
  37.         }
  38.     }
  39.  
  40.     @Test
  41.     public void testStringBuilderSize() {
  42.         for(int i=0; i<3; i++) {
  43.             final long start = System.nanoTime();
  44.             for(int j=0; j<1_000_000; j++) {
  45.                 stringBuilderSize(S1, S2, S3);
  46.             }
  47.             final long run = System.nanoTime() - start;
  48.             log.info("Time was {}ns, {}/s", run/1E6, 1E6/(run/1e9));
  49.  
  50.         }
  51.     }
  52.  
  53.  
  54.     @Ignore
  55.     public static String basic(String s1, String s2, String s3) {
  56.         return "SELECT " + s1 + " FROM " + s2 + " WHERE " + s3;
  57.     }
  58.  
  59.     @Ignore
  60.     public static String stringBuilder(String s1, String s2, String s3) {
  61.         return new StringBuilder().append("SELECT ").append(s1)
  62.                 .append(" FROM ").append(s2).append(" WHERE ")
  63.                 .append(s3).toString();
  64.     }
  65.  
  66.     @Ignore
  67.     public static String stringBuilderSize(String s1, String s2, String s3) {
  68.         int len = 20 + s1.length() + s2.length() + s3.length();
  69.         return new StringBuilder(len).append("SELECT ").append(s1)
  70.                 .append(" FROM ").append(s2).append(" WHERE ")
  71.                 .append(s3).toString();
  72.     }
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top