Permalink
Browse files

Added graphs and decompiled classes

  • Loading branch information...
1 parent 2a3b910 commit 09b007ef7fe7ba29b22a68991178e45382c5d4b6 @skuro committed Mar 11, 2013
View
@@ -0,0 +1,4 @@
+Java StringBuilder myth debunked
+================================
+
+Are `StringBuilder`s that better than the normal plus operator to handle `String` concatenation? Here's an attempt to provide an answer.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN catsb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,48 @@
+Compiled from "ACat.java"
+public abstract class ACat extends java.lang.Object{
+public ACat();
+ Code:
+ 0: aload_0
+ 1: invokespecial #8; //Method java/lang/Object."<init>":()V
+ 4: return
+
+protected abstract java.lang.String cat(java.lang.String, java.lang.String);
+
+public long test(int);
+ Code:
+ 0: ldc #15; //String start
+ 2: astore_2
+ 3: invokestatic #17; //Method java/lang/System.currentTimeMillis:()J
+ 6: lstore_3
+ 7: iconst_0
+ 8: istore 5
+ 10: goto 49
+ 13: bipush 10
+ 15: newarray byte
+ 17: astore 6
+ 19: new #23; //class java/util/Random
+ 22: dup
+ 23: invokespecial #25; //Method java/util/Random."<init>":()V
+ 26: aload 6
+ 28: invokevirtual #26; //Method java/util/Random.nextBytes:([B)V
+ 31: aload_0
+ 32: aload_2
+ 33: new #30; //class java/lang/String
+ 36: dup
+ 37: aload 6
+ 39: invokespecial #32; //Method java/lang/String."<init>":([B)V
+ 42: invokevirtual #34; //Method cat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
+ 45: astore_2
+ 46: iinc 5, 1
+ 49: iload 5
+ 51: iload_1
+ 52: if_icmplt 13
+ 55: invokestatic #17; //Method java/lang/System.currentTimeMillis:()J
+ 58: lstore 5
+ 60: lload 5
+ 62: lload_3
+ 63: lsub
+ 64: lreturn
+
+}
+
View
@@ -0,0 +1,39 @@
+Compiled from "CatPlus.java"
+public class CatPlus extends ACat{
+public CatPlus();
+ Code:
+ 0: aload_0
+ 1: invokespecial #8; //Method ACat."<init>":()V
+ 4: return
+
+protected java.lang.String cat(java.lang.String, java.lang.String);
+ Code:
+ 0: new #13; //class java/lang/StringBuilder
+ 3: dup
+ 4: ldc #15; //String const1
+ 6: invokespecial #17; //Method java/lang/StringBuilder."<init>":(Ljava/lang/String;)V
+ 9: aload_1
+ 10: invokevirtual #20; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 13: invokevirtual #24; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
+ 16: astore_3
+ 17: new #13; //class java/lang/StringBuilder
+ 20: dup
+ 21: aload_3
+ 22: invokestatic #28; //Method java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
+ 25: invokespecial #17; //Method java/lang/StringBuilder."<init>":(Ljava/lang/String;)V
+ 28: ldc #34; //String const2
+ 30: invokevirtual #20; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 33: invokevirtual #24; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
+ 36: astore_3
+ 37: new #13; //class java/lang/StringBuilder
+ 40: dup
+ 41: aload_3
+ 42: invokestatic #28; //Method java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
+ 45: invokespecial #17; //Method java/lang/StringBuilder."<init>":(Ljava/lang/String;)V
+ 48: aload_2
+ 49: invokevirtual #20; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 52: invokevirtual #24; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
+ 55: areturn
+
+}
+
View
@@ -0,0 +1,26 @@
+Compiled from "CatSB.java"
+public class CatSB extends ACat{
+public CatSB();
+ Code:
+ 0: aload_0
+ 1: invokespecial #8; //Method ACat."<init>":()V
+ 4: return
+
+protected java.lang.String cat(java.lang.String, java.lang.String);
+ Code:
+ 0: new #13; //class java/lang/StringBuilder
+ 3: dup
+ 4: invokespecial #15; //Method java/lang/StringBuilder."<init>":()V
+ 7: ldc #16; //String const1
+ 9: invokevirtual #18; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 12: aload_1
+ 13: invokevirtual #18; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 16: ldc #22; //String const2
+ 18: invokevirtual #18; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 21: aload_2
+ 22: invokevirtual #18; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 25: invokevirtual #24; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
+ 28: areturn
+
+}
+
View
@@ -0,0 +1,25 @@
+Compiled from "CatSB2.java"
+public class CatSB2 extends ACat{
+public CatSB2();
+ Code:
+ 0: aload_0
+ 1: invokespecial #8; //Method ACat."<init>":()V
+ 4: return
+
+protected java.lang.String cat(java.lang.String, java.lang.String);
+ Code:
+ 0: new #13; //class java/lang/StringBuilder
+ 3: dup
+ 4: ldc #15; //String const1
+ 6: invokespecial #17; //Method java/lang/StringBuilder."<init>":(Ljava/lang/String;)V
+ 9: aload_1
+ 10: invokevirtual #20; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 13: ldc #24; //String const2
+ 15: invokevirtual #20; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 18: aload_2
+ 19: invokevirtual #20; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 22: invokevirtual #26; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
+ 25: areturn
+
+}
+
View
@@ -0,0 +1,146 @@
+Compiled from "CatTest.java"
+public class CatTest extends java.lang.Object{
+public CatTest();
+ Code:
+ 0: aload_0
+ 1: invokespecial #8; //Method java/lang/Object."<init>":()V
+ 4: return
+
+private static java.io.PrintWriter getWriter(java.lang.String) throws java.io.IOException;
+ Code:
+ 0: ldc #16; //String user.dir
+ 2: invokestatic #18; //Method java/lang/System.getProperty:(Ljava/lang/String;)Ljava/lang/String;
+ 5: astore_1
+ 6: ldc #24; //String %s/%s.log
+ 8: iconst_2
+ 9: anewarray #3; //class java/lang/Object
+ 12: dup
+ 13: iconst_0
+ 14: aload_1
+ 15: aastore
+ 16: dup
+ 17: iconst_1
+ 18: aload_0
+ 19: aastore
+ 20: invokestatic #26; //Method java/lang/String.format:(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
+ 23: astore_2
+ 24: new #32; //class java/io/File
+ 27: dup
+ 28: aload_2
+ 29: invokespecial #34; //Method java/io/File."<init>":(Ljava/lang/String;)V
+ 32: invokevirtual #37; //Method java/io/File.delete:()Z
+ 35: pop
+ 36: new #41; //class java/io/PrintWriter
+ 39: dup
+ 40: new #43; //class java/io/BufferedWriter
+ 43: dup
+ 44: new #45; //class java/io/FileWriter
+ 47: dup
+ 48: aload_2
+ 49: iconst_1
+ 50: invokespecial #47; //Method java/io/FileWriter."<init>":(Ljava/lang/String;Z)V
+ 53: invokespecial #50; //Method java/io/BufferedWriter."<init>":(Ljava/io/Writer;)V
+ 56: invokespecial #53; //Method java/io/PrintWriter."<init>":(Ljava/io/Writer;)V
+ 59: areturn
+
+private static ACat getCat(java.lang.String);
+ Code:
+ 0: ldc #56; //String catplus
+ 2: aload_0
+ 3: invokevirtual #58; //Method java/lang/String.equals:(Ljava/lang/Object;)Z
+ 6: ifeq 17
+ 9: new #62; //class CatPlus
+ 12: dup
+ 13: invokespecial #64; //Method CatPlus."<init>":()V
+ 16: areturn
+ 17: ldc #65; //String catsb
+ 19: aload_0
+ 20: invokevirtual #58; //Method java/lang/String.equals:(Ljava/lang/Object;)Z
+ 23: ifeq 34
+ 26: new #67; //class CatSB
+ 29: dup
+ 30: invokespecial #69; //Method CatSB."<init>":()V
+ 33: areturn
+ 34: new #70; //class CatSB2
+ 37: dup
+ 38: invokespecial #72; //Method CatSB2."<init>":()V
+ 41: areturn
+
+public static void main(java.lang.String[]);
+ Code:
+ 0: aload_0
+ 1: iconst_0
+ 2: aaload
+ 3: astore_1
+ 4: aconst_null
+ 5: astore_2
+ 6: getstatic #75; //Field java/lang/System.out:Ljava/io/PrintStream;
+ 9: ldc #79; //String Testing %s
+ 11: iconst_1
+ 12: anewarray #3; //class java/lang/Object
+ 15: dup
+ 16: iconst_0
+ 17: aload_1
+ 18: aastore
+ 19: invokestatic #26; //Method java/lang/String.format:(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
+ 22: invokevirtual #81; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
+ 25: aload_1
+ 26: invokestatic #86; //Method getWriter:(Ljava/lang/String;)Ljava/io/PrintWriter;
+ 29: astore_2
+ 30: aload_1
+ 31: invokestatic #88; //Method getCat:(Ljava/lang/String;)LACat;
+ 34: astore_3
+ 35: iconst_0
+ 36: istore 4
+ 38: goto 82
+ 41: getstatic #75; //Field java/lang/System.out:Ljava/io/PrintStream;
+ 44: ldc #90; //String round %s
+ 46: iconst_1
+ 47: anewarray #3; //class java/lang/Object
+ 50: dup
+ 51: iconst_0
+ 52: iload 4
+ 54: invokestatic #92; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
+ 57: aastore
+ 58: invokestatic #26; //Method java/lang/String.format:(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
+ 61: invokevirtual #81; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
+ 64: aload_3
+ 65: sipush 1000
+ 68: invokevirtual #98; //Method ACat.test:(I)J
+ 71: lstore 5
+ 73: aload_2
+ 74: lload 5
+ 76: invokevirtual #104; //Method java/io/PrintWriter.println:(J)V
+ 79: iinc 4, 1
+ 82: iload 4
+ 84: bipush 100
+ 86: if_icmplt 41
+ 89: goto 121
+ 92: astore_3
+ 93: aload_3
+ 94: invokevirtual #107; //Method java/lang/Exception.printStackTrace:()V
+ 97: aload_2
+ 98: ifnull 129
+ 101: aload_2
+ 102: invokevirtual #112; //Method java/io/PrintWriter.close:()V
+ 105: goto 129
+ 108: astore 7
+ 110: aload_2
+ 111: ifnull 118
+ 114: aload_2
+ 115: invokevirtual #112; //Method java/io/PrintWriter.close:()V
+ 118: aload 7
+ 120: athrow
+ 121: aload_2
+ 122: ifnull 129
+ 125: aload_2
+ 126: invokevirtual #112; //Method java/io/PrintWriter.close:()V
+ 129: return
+ Exception table:
+ from to target type
+ 25 89 92 Class java/lang/Exception
+
+ 25 97 108 any
+
+}
+
View
@@ -0,0 +1,48 @@
+Compiled from "ACat.java"
+public abstract class ACat extends java.lang.Object{
+public ACat();
+ Code:
+ 0: aload_0
+ 1: invokespecial #1; //Method java/lang/Object."<init>":()V
+ 4: return
+
+protected abstract java.lang.String cat(java.lang.String, java.lang.String);
+
+public long test(int);
+ Code:
+ 0: ldc #2; //String start
+ 2: astore_2
+ 3: invokestatic #3; //Method java/lang/System.currentTimeMillis:()J
+ 6: lstore_3
+ 7: iconst_0
+ 8: istore 5
+ 10: iload 5
+ 12: iload_1
+ 13: if_icmpge 55
+ 16: bipush 10
+ 18: newarray byte
+ 20: astore 6
+ 22: new #4; //class java/util/Random
+ 25: dup
+ 26: invokespecial #5; //Method java/util/Random."<init>":()V
+ 29: aload 6
+ 31: invokevirtual #6; //Method java/util/Random.nextBytes:([B)V
+ 34: aload_0
+ 35: aload_2
+ 36: new #7; //class java/lang/String
+ 39: dup
+ 40: aload 6
+ 42: invokespecial #8; //Method java/lang/String."<init>":([B)V
+ 45: invokevirtual #9; //Method cat:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
+ 48: astore_2
+ 49: iinc 5, 1
+ 52: goto 10
+ 55: invokestatic #3; //Method java/lang/System.currentTimeMillis:()J
+ 58: lstore 5
+ 60: lload 5
+ 62: lload_3
+ 63: lsub
+ 64: lreturn
+
+}
+
View
@@ -0,0 +1,40 @@
+Compiled from "CatPlus.java"
+public class CatPlus extends ACat{
+public CatPlus();
+ Code:
+ 0: aload_0
+ 1: invokespecial #1; //Method ACat."<init>":()V
+ 4: return
+
+protected java.lang.String cat(java.lang.String, java.lang.String);
+ Code:
+ 0: new #2; //class java/lang/StringBuilder
+ 3: dup
+ 4: invokespecial #3; //Method java/lang/StringBuilder."<init>":()V
+ 7: ldc #4; //String const1
+ 9: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 12: aload_1
+ 13: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 16: invokevirtual #6; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
+ 19: astore_3
+ 20: new #2; //class java/lang/StringBuilder
+ 23: dup
+ 24: invokespecial #3; //Method java/lang/StringBuilder."<init>":()V
+ 27: aload_3
+ 28: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 31: ldc #7; //String const2
+ 33: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 36: invokevirtual #6; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
+ 39: astore_3
+ 40: new #2; //class java/lang/StringBuilder
+ 43: dup
+ 44: invokespecial #3; //Method java/lang/StringBuilder."<init>":()V
+ 47: aload_3
+ 48: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 51: aload_2
+ 52: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
+ 55: invokevirtual #6; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
+ 58: areturn
+
+}
+
Oops, something went wrong.

0 comments on commit 09b007e

Please sign in to comment.