Permalink
Browse files

Add some stuff to help with profiling and other testing

  • Loading branch information...
olabini committed Jul 22, 2009
1 parent 7fbcd55 commit 4eb1d4f69c5960a7741752f7d7f2c1b6f40c6148
@@ -105,6 +105,7 @@ public void replaceLinks(IRubyObject newObject) {
for(StorageLink sl : links) {
sl.replaceLinkWith(newObject);
}
+ links.clear();
}
// syck_badalias_initialize
@@ -1,4 +1,4 @@
-/* Generated by re2j 0.13.6.dev on Tue Jul 21 19:01:09 2009 */
+/* Generated by re2j 0.13.6.dev on Wed Jul 22 14:59:56 2009 */
package org.yecht;
import java.io.IOException;
@@ -1,4 +1,4 @@
-/* Generated by re2j 0.13.6.dev on Tue Jul 21 19:01:08 2009 */
+/* Generated by re2j 0.13.6.dev on Wed Jul 22 14:59:56 2009 */
package org.yecht;
// Equivalent to implicit.re
@@ -0,0 +1,16 @@
+/*
+ * See LICENSE file in distribution for copyright and licensing information.
+ */
+package org.yecht;
+
+/**
+ *
+ * @author <a href="mailto:ola.bini@gmail.com">Ola Bini</a>
+ */
+public class NullNodeHandler implements NodeHandler {
+ private long current = 0;
+
+ public Object handle(Parser p, Node n) {
+ return Long.valueOf(current++);
+ }
+}// NullNodeHandler
@@ -0,0 +1,61 @@
+package org.yecht;
+
+import java.io.InputStream;
+import java.io.FileInputStream;
+
+public class ScannerOutput {
+ public static void main(String[] args) throws Exception {
+ String filename = args[0];
+ int len = 8000;
+ int read = 0;
+ int currRead = 0;
+ byte[] buffer = new byte[1024];
+ byte[] input = new byte[len];
+ InputStream is = new FileInputStream(filename);
+ while((currRead = is.read(buffer, 0, 1024)) != -1) {
+ if(read + currRead >= len) {
+ len *= 2;
+ input = YAML.realloc(input, len);
+ }
+ System.arraycopy(buffer, 0, input, read, currRead);
+ read += currRead;
+ }
+
+ Parser parser = Parser.newParser();
+ parser.str(Pointer.create(input, 0), read, null);
+ parser.handler(new NullNodeHandler());
+ parser.errorHandler(null);
+ parser.implicitTyping(true);
+ parser.taguriExpansion(true);
+ Scanner s = TokenScanner.createScanner(parser);
+ int tok = -1;
+ Object lval = null;
+ int indent = 0;
+ while(tok != YAMLGrammarTokens.ENDINPUT) {
+ tok = s.yylex();
+ if(tok == YAMLGrammarTokens.YAML_IOPEN) {
+ for(int i=0; i < indent; i++) {
+ System.err.print(" ");
+ }
+ indent++;
+ } else if(tok == YAMLGrammarTokens.YAML_IEND) {
+ indent--;
+ for(int i=0; i < indent; i++) {
+ System.err.print(" ");
+ }
+ } else {
+ for(int i=0; i < indent; i++) {
+ System.err.print(" ");
+ }
+ }
+
+ Object lval2 = s.getLVal();
+ System.err.print("tok: " + TokenScanner.tnames[tok]);
+ if(lval != lval2) {
+ System.err.print(" lval: " + lval2);
+ lval = lval2;
+ }
+ System.err.println();
+ }
+ }
+}
@@ -0,0 +1,37 @@
+package org.yecht;
+
+import java.io.InputStream;
+import java.io.FileInputStream;
+
+public class Test1 {
+ public static void main(String[] args) throws Exception {
+ String filename = args[0];
+ int len = 8000;
+ int read = 0;
+ int currRead = 0;
+ byte[] buffer = new byte[1024];
+ byte[] input = new byte[len];
+ InputStream is = new FileInputStream(filename);
+ while((currRead = is.read(buffer, 0, 1024)) != -1) {
+ if(read + currRead >= len) {
+ len *= 2;
+ input = YAML.realloc(input, len);
+ }
+ System.arraycopy(buffer, 0, input, read, currRead);
+ read += currRead;
+ }
+ int times = 10000;
+ long before = System.currentTimeMillis();
+ for(int i=0; i<times; i++) {
+ Parser parser = Parser.newParser();
+ parser.str(Pointer.create(input, 0), read, null);
+ parser.handler(new NullNodeHandler());
+ parser.errorHandler(null);
+ parser.implicitTyping(true);
+ parser.taguriExpansion(true);
+ parser.parse();
+ }
+ long after = System.currentTimeMillis();
+ System.err.println("parsing " + filename + " " + times + " times took " + (after-before) + "ms");
+ }
+}
@@ -0,0 +1,43 @@
+package org.yecht;
+
+import java.io.InputStream;
+import java.io.FileInputStream;
+
+public class Test2 {
+ public static void main(String[] args) throws Exception {
+ String filename = args[0];
+ int len = 8000;
+ int read = 0;
+ int currRead = 0;
+ byte[] buffer = new byte[1024];
+ byte[] input = new byte[len];
+ InputStream is = new FileInputStream(filename);
+ while((currRead = is.read(buffer, 0, 1024)) != -1) {
+ if(read + currRead >= len) {
+ len *= 2;
+ input = YAML.realloc(input, len);
+ }
+ System.arraycopy(buffer, 0, input, read, currRead);
+ read += currRead;
+ }
+ int times = 100;
+ long before = System.currentTimeMillis();
+ for(int i=0; i<times; i++) {
+ Parser parser = Parser.newParser();
+ parser.str(Pointer.create(input, 0), read, null);
+ parser.handler(new NullNodeHandler());
+ parser.errorHandler(null);
+ parser.implicitTyping(true);
+ parser.taguriExpansion(true);
+ Scanner s = TokenScanner.createScanner(parser);
+ int tok = -1;
+ while(tok != YAMLGrammarTokens.ENDINPUT) {
+ tok = s.yylex();
+// Object lval = s.getLVal();
+// System.err.println("tok: " + TokenScanner.tnames[tok] + " lval: " + lval);
+ }
+ }
+ long after = System.currentTimeMillis();
+ System.err.println("scanning " + filename + " " + times + " times took " + (after-before) + "ms");
+ }
+}
@@ -1,4 +1,4 @@
-/* Generated by re2j 0.13.6.dev on Tue Jul 21 19:01:08 2009 */
+/* Generated by re2j 0.13.6.dev on Wed Jul 22 14:59:56 2009 */
package org.yecht;
import java.io.IOException;
@@ -153,6 +153,31 @@ private int GET_TRUE_YAML_INDENT() {
private final static int ScalarBlock2 = 14;
private final static String[] names = {"", "Header", "Document", "Directive", "Plain", "Plain2", "Plain3", "SingleQuote", "SingleQuote2", "DoubleQuote", "DoubleQuote2", "TransferMethod", "TransferMethod2", "ScalarBlock", "ScalarBlock2"};
+ public final static String[] tnames = new String[126];
+ static {
+ tnames[0] = "ENDINPUT";
+ tnames[1] = "ALIAS";
+ tnames[2] = "ANCHOR";
+ tnames[3] = "BLOCK";
+ tnames[4] = "DOCSEP";
+ tnames[5] = "IEND";
+ tnames[6] = "INDENT";
+ tnames[7] = "IOPEN";
+ tnames[8] = "ITRANSFER";
+ tnames[9] = "PLAIN";
+ tnames[10] = "TAGURI";
+ tnames[11] = "TRANSFER";
+ tnames[12] = "WORD";
+ tnames[13] = "error";
+ tnames[44] = "COMMA";
+ tnames[45] = "DASH";
+ tnames[58] = "COLON";
+ tnames[63] = "QUESTION";
+ tnames[91] = "SQUAREO";
+ tnames[93] = "SQUAREC";
+ tnames[123] = "CURLYO";
+ tnames[125] = "CURLYC";
+ }
private void YYPOS(int n) {
parser.cursor = parser.token + n;
@@ -152,6 +152,31 @@ public class TokenScanner implements YAMLGrammarTokens, Scanner {
private final static int ScalarBlock2 = 14;
private final static String[] names = {"", "Header", "Document", "Directive", "Plain", "Plain2", "Plain3", "SingleQuote", "SingleQuote2", "DoubleQuote", "DoubleQuote2", "TransferMethod", "TransferMethod2", "ScalarBlock", "ScalarBlock2"};
+ public final static String[] tnames = new String[126];
+ static {
+ tnames[0] = "ENDINPUT";
+ tnames[1] = "ALIAS";
+ tnames[2] = "ANCHOR";
+ tnames[3] = "BLOCK";
+ tnames[4] = "DOCSEP";
+ tnames[5] = "IEND";
+ tnames[6] = "INDENT";
+ tnames[7] = "IOPEN";
+ tnames[8] = "ITRANSFER";
+ tnames[9] = "PLAIN";
+ tnames[10] = "TAGURI";
+ tnames[11] = "TRANSFER";
+ tnames[12] = "WORD";
+ tnames[13] = "error";
+ tnames[44] = "COMMA";
+ tnames[45] = "DASH";
+ tnames[58] = "COLON";
+ tnames[63] = "QUESTION";
+ tnames[91] = "SQUAREO";
+ tnames[93] = "SQUAREC";
+ tnames[123] = "CURLYO";
+ tnames[125] = "CURLYC";
+ }
private void YYPOS(int n) {
parser.cursor = parser.token + n;

0 comments on commit 4eb1d4f

Please sign in to comment.