Advertisement
GenuineSounds

Untitled

Feb 10th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.45 KB | None | 0 0
  1. package com.genuineminecraft.bf;
  2.  
  3. public class BrainFuckeryTest {
  4.  
  5.     public static String test = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.";
  6.  
  7.     public static void main(String[] args) {
  8.         if (args.length > 0)
  9.             test = args[0];
  10.         test = test.replaceAll("[^\\,\\.\\<\\>\\[\\]\\-\\+]", "");
  11.         System.out.println("===================== Time Trials =====================");
  12.         timeTrials();
  13.     }
  14.  
  15.     public static void timeTrials() {
  16.         long start, stop;
  17.         int count = 100000;
  18.         int dCount = 10;
  19.         for (int j = 0; j < dCount; j++) {
  20.             if (j == 0) {
  21.                 System.out.println("Info: Running " + count + " times x" + dCount + ".");
  22.                 System.out.println("Info: These are the pre-compile results!");
  23.             } else
  24.                 System.out.println("Info: These are the post-compile results!");
  25.             start = System.nanoTime();
  26.             for (int i = 0; i < count; i++)
  27.                 encode_1(test);
  28.             stop = System.nanoTime();
  29.             System.out.println("Debug Encode 1: " + (stop - start) + " nanoseconds.");
  30.             start = System.nanoTime();
  31.             for (int i = 0; i < count; i++)
  32.                 encode_2(test);
  33.             stop = System.nanoTime();
  34.             System.out.println("Debug Encode 2: " + (stop - start) + " nanoseconds.");
  35.         }
  36.     }
  37.  
  38.     private static String encode_1(String in) {
  39.         String out = "";
  40.         int counter = 0;
  41.         for (int place = 0; place < in.length(); place++) {
  42.             char compare = in.charAt(place);
  43.             if (in.length() > place + 1 && compare == in.charAt(place + 1)) {
  44.                 counter++;
  45.                 continue;
  46.             }
  47.             switch (counter) {
  48.                 case 1:
  49.                     out += Character.toString(compare);
  50.                     break;
  51.                 case 0:
  52.                     out += Character.toString(compare);
  53.                     break;
  54.                 default:
  55.                     out += Integer.toString(counter + 1);
  56.                     out += Character.toString(compare);
  57.                     break;
  58.             }
  59.             counter = 0;
  60.         }
  61.         return out;
  62.     }
  63.  
  64.     private static String encode_2(String in) {
  65.         StringBuilder out = new StringBuilder();
  66.         int counter = 0;
  67.         for (int place = 0; place < in.length(); place++) {
  68.             char compare = in.charAt(place);
  69.             if (in.length() > place + 1 && compare == in.charAt(place + 1)) {
  70.                 counter++;
  71.                 continue;
  72.             }
  73.             switch (counter) {
  74.                 case 1:
  75.                     out.append(Character.toString(compare));
  76.                 case 0:
  77.                     out.append(Character.toString(compare));
  78.                     break;
  79.                 default:
  80.                     out.append(Integer.toString(counter + 1));
  81.                     out.append(Character.toString(compare));
  82.                     break;
  83.             }
  84.             counter = 0;
  85.         }
  86.         return out.toString();
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement