Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.genuineminecraft.bf;
- public class BrainFuckeryTest {
- public static String test = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.";
- public static void main(String[] args) {
- if (args.length > 0)
- test = args[0];
- test = test.replaceAll("[^\\,\\.\\<\\>\\[\\]\\-\\+]", "");
- System.out.println("===================== Time Trials =====================");
- timeTrials();
- }
- public static void timeTrials() {
- long start, stop;
- int count = 100000;
- int dCount = 10;
- for (int j = 0; j < dCount; j++) {
- if (j == 0) {
- System.out.println("Info: Running " + count + " times x" + dCount + ".");
- System.out.println("Info: These are the pre-compile results!");
- } else
- System.out.println("Info: These are the post-compile results!");
- start = System.nanoTime();
- for (int i = 0; i < count; i++)
- encode_1(test);
- stop = System.nanoTime();
- System.out.println("Debug Encode 1: " + (stop - start) + " nanoseconds.");
- start = System.nanoTime();
- for (int i = 0; i < count; i++)
- encode_2(test);
- stop = System.nanoTime();
- System.out.println("Debug Encode 2: " + (stop - start) + " nanoseconds.");
- }
- }
- private static String encode_1(String in) {
- String out = "";
- int counter = 0;
- for (int place = 0; place < in.length(); place++) {
- char compare = in.charAt(place);
- if (in.length() > place + 1 && compare == in.charAt(place + 1)) {
- counter++;
- continue;
- }
- switch (counter) {
- case 1:
- out += Character.toString(compare);
- break;
- case 0:
- out += Character.toString(compare);
- break;
- default:
- out += Integer.toString(counter + 1);
- out += Character.toString(compare);
- break;
- }
- counter = 0;
- }
- return out;
- }
- private static String encode_2(String in) {
- StringBuilder out = new StringBuilder();
- int counter = 0;
- for (int place = 0; place < in.length(); place++) {
- char compare = in.charAt(place);
- if (in.length() > place + 1 && compare == in.charAt(place + 1)) {
- counter++;
- continue;
- }
- switch (counter) {
- case 1:
- out.append(Character.toString(compare));
- case 0:
- out.append(Character.toString(compare));
- break;
- default:
- out.append(Integer.toString(counter + 1));
- out.append(Character.toString(compare));
- break;
- }
- counter = 0;
- }
- return out.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement