GitHub PullRequestReviewCommentEvent at 2014-05-31 20:26:54
Repository: antlr4
Actor: sharwell
Payload: {"comment":{"url":"https://api.github.com/repos/antlr/antlr4/pulls/comments/13263214","id":13263214,"diff_hunk":"@@ -0,0 +1,158 @@\n+/*\n+ * [The \"BSD license\"]\n+ *  Copyright (c) 2014 Terence Parr\n+ *  Copyright (c) 2014 Sam Harwell\n+ *  All rights reserved.\n+ *\n+ *  Redistribution and use in source and binary forms, with or without\n+ *  modification, are permitted provided that the following conditions\n+ *  are met:\n+ *\n+ *  1. Redistributions of source code must retain the above copyright\n+ *     notice, this list of conditions and the following disclaimer.\n+ *  2. Redistributions in binary form must reproduce the above copyright\n+ *     notice, this list of conditions and the following disclaimer in the\n+ *     documentation and/or other materials provided with the distribution.\n+ *  3. The name of the author may not be used to endorse or promote products\n+ *     derived from this software without specific prior written permission.\n+ *\n+ *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n+ *  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n+ *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\n+ *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n+ *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.antlr.v4.runtime.atn;\n+\n+import org.antlr.v4.runtime.dfa.DFA;\n+\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+public class ParseInfo {\n+\t/** ALL(*) paper says: 717.6s to parse Java 1.6 corpus without dfa (no trees).\n+\t *  Takes 3.73s to reparse (pure DFA, no trees). That ratio 717.6 / 3.73 = 192.3861 means\n+\t *  ATN transitions are about 192 times more expensive.  Max lookahead very shallow.\n+\t *\n+\t *  Hmm... C grammar that has some deep lookahead shows much lower ratio. (albeit with atn profiling on)\n+\t *\n+\t *      C SLL grammar with dfa and SLL 6295ms  (3rd run)\n+\t *      C SLL grammar NO   dfa and SLL 26776ms (3rd run)\n+\t *      ratio = 4.25x\n+\t *\n+\t *      C LL  grammar with dfa 2-stage 10895ms (3rd run)\n+\t *      C LL  grammar NO   dfa 2-stage 32867ms (3rd run)\n+\t *      ratio = 3x\n+\t */\n+\tpublic static final double ATN_TO_DFA_TRANSITION_COST = 717.6 / 3.73;\n+\n+\tprotected ProfilingATNSimulator atnSimulator;\n+\n+\tpublic ParseInfo(ProfilingATNSimulator atnSimulator) {\n+\t\tthis.atnSimulator = atnSimulator;\n+\t}\n+\n+\t//\tpublic double cost() {\n+\t//\t\treturn (SLL_ATNTransitions+LL_ATNTransitions) * ATN_TO_DFA_TRANSITION_COST + DFATransitions;\n+\t//\t}\n+\t//\n+\n+\tpublic String getCSV() {\n+\t\tDecisionInfo[] decisions = atnSimulator.getDecisionInfo();\n+\t\tStringBuilder buf = new StringBuilder();\n+\t\tbuf.append(\n+\t\t\t\tString.format(\"\\t %3s, %8s, %8s, %8s, %8s, %8s, %8s, %8s, %8s, %8s, %8s, %8s\\n\",\n+\t\t\t\t\t\t\"dec\", \"invoc\", \"time ns\", \"DFA states\", \"fullctx\", \"total\", \"min\", \"max\", \"DFA\", \"SLL-ATN\", \"LL-ATN\", \"preds\")\n+\t\t);\n+\t\tfor (int i=0; i<decisions.length; i++) {\n+\t\t\tDecisionInfo d = decisions[i];\n+\t\t\tbuf.append(\n+\t\t\t\t\tString.format(\"\\t%3d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d\\n\",\n+\t\t\t\t\t\t\ti,\n+\t\t\t\t\t\t\td.invocations,\n+\t\t\t\t\t\t\td.timeInPrediction,\n+\t\t\t\t\t\t\tgetDFASize(i),\n+\t\t\t\t\t\t\td.LL_Fallback,\n+\t\t\t\t\t\t\td.totalLook,\n+\t\t\t\t\t\t\td.minLook,\n+\t\t\t\t\t\t\td.maxLook,\n+\t\t\t\t\t\t\td.DFATransitions,\n+\t\t\t\t\t\t\td.SLL_ATNTransitions,\n+\t\t\t\t\t\t\td.LL_ATNTransitions,\n+\t\t\t\t\t\t\td.predicateEvals.size())\n+\t\t\t);\n+\t\t}\n+\t\treturn buf.toString();\n+\t}\n+\n+\tpublic DecisionInfo[] getDecisionInfo() {\n+\t\treturn atnSimulator.getDecisionInfo();\n+\t}\n+\n+\tpublic List<Integer> getLLDecisions() {\n+\t\tDecisionInfo[] decisions = atnSimulator.getDecisionInfo();\n+\t\tList<Integer> LL = new ArrayList<Integer>();\n+\t\tfor (int i=0; i<decisions.length; i++) {\n+\t\t\tlong fallBack = decisions[i].LL_Fallback;\n+\t\t\tif ( fallBack>0 ) LL.add(i);\n+\t\t}\n+\t\treturn LL;\n+\t}\n+\n+\tpublic long getTotalTimeInPrediction() {\n+\t\tDecisionInfo[] decisions = atnSimulator.getDecisionInfo();\n+\t\tlong t = 0;\n+\t\tfor (int i=0; i<decisions.length; i++) {\n+\t\t\tt += decisions[i].timeInPrediction;\n+\t\t}\n+\t\treturn t;\n+\t}\n+\n+\tpublic long getTotalLookaheadOps() {\n+\t\tDecisionInfo[] decisions = atnSimulator.getDecisionInfo();\n+\t\tlong k = 0;\n+\t\tfor (int i = 0; i < decisions.length; i++) {\n+\t\t\tk += decisions[i].totalLook;\n+\t\t}\n+\t\treturn k;\n+\t}\n+\n+\tpublic long getTotalATNLookaheadOps() {\n+\t\tDecisionInfo[] decisions = atnSimulator.getDecisionInfo();\n+\t\tlong k = 0;\n+\t\tfor (int i = 0; i < decisions.length; i++) {\n+\t\t\tk += decisions[i].SLL_ATNTransitions;\n+\t\t\tk += decisions[i].LL_ATNTransitions;\n+\t\t}\n+\t\treturn k;\n+\t}\n+\n+\tpublic long getTotalLLATNLookaheadOps() {\n+\t\tDecisionInfo[] decisions = atnSimulator.getDecisionInfo();\n+\t\tlong k = 0;\n+\t\tfor (int i = 0; i < decisions.length; i++) {\n+\t\t\tk += decisions[i].LL_ATNTransitions;\n+\t\t}\n+\t\treturn k;\n+\t}\n+\n+\tpublic int getDFASize() {\n+\t\tint n = 0;\n+\t\tDFA[] decisionToDFA = atnSimulator.decisionToDFA;\n+\t\tfor (int i = 0; i < decisionToDFA.length; i++) {\n+\t\t\tn += getDFASize(i);\n+\t\t}\n+\t\treturn n;\n+\t}\n+\n+\tpublic int getDFASize(int decision) {","path":"runtime/Java/src/org/antlr/v4/runtime/atn/ParseInfo.java","position":154,"original_position":154,"commit_id":"3e2f7060134bcf24c921da50711a17b537c10d1c","original_commit_id":"3e2f7060134bcf24c921da50711a17b537c10d1c","user":{"login":"sharwell","id":1408396,"avatar_url":"https://avatars.githubusercontent.com/u/1408396?","gravatar_id":"2ad736b6060385dcc24177fa172ee66d","url":"https://api.github.com/users/sharwell","html_url":"https://github.com/sharwell","followers_url":"https://api.github.com/users/sharwell/followers","following_url":"https://api.github.com/users/sharwell/following{/other_user}","gists_url":"https://api.github.com/users/sharwell/gists{/gist_id}","starred_url":"https://api.github.com/users/sharwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharwell/subscriptions","organizations_url":"https://api.github.com/users/sharwell/orgs","repos_url":"https://api.github.com/users/sharwell/repos","events_url":"https://api.github.com/users/sharwell/events{/privacy}","received_events_url":"https://api.github.com/users/sharwell/received_events","type":"User","site_admin":false},"body":"What is this statistic?","created_at":"2014-05-31T20:26:54Z","updated_at":"2014-05-31T20:26:54Z","html_url":"https://github.com/antlr/antlr4/pull/583#discussion_r13263214","pull_request_url":"https://api.github.com/repos/antlr/antlr4/pulls/583","_links":{"self":{"href":"https://api.github.com/repos/antlr/antlr4/pulls/comments/13263214"},"html":{"href":"https://github.com/antlr/antlr4/pull/583#discussion_r13263214"},"pull_request":{"href":"https://api.github.com/repos/antlr/antlr4/pulls/583"}}}}