title: How to improve antlr4 runtime performance on c++ target?
body: <p>My tool intention is calculate the results parsed from antlr4. The inputs had break into many lines, 
  eg: 1+1,
      3*4,
      ...
  Each line will init the parser and call the visitor. Therefore, if there is 1000 lines, it will call 1000 times of antlr4 parser. It run perfectly except the performances are slightly slow on the device. I hope to improve the performances even there is 1second faster.</p>
  
  <p>I'm using antlr4.7 as runtime. The runtime target is on c++.</p>
  
  <pre><code>for (itFormulas = fMap - &gt; begin(); itFormulas != fMap - &gt; end(); itFormulas++) 
  {
    auto initStart = std::chrono::high_resolution_clock::now();
  
    ANTLRInputStream input(itFormulas - &gt; second);
    FormulaLexer lexer( &amp; input);
    CommonTokenStream tokens( &amp; lexer);
    FormulaParser parser( &amp; tokens);
    FormulaParser::MainContext * mainContext = parser.main();
  
    auto initEnd = std::chrono::high_resolution_clock::now();
    std::chrono::duration &lt; double &gt; totalInit = initEnd - initStart;
  
    //calculate time
    totalInitTime += totalInit.count();
  
    auto visitStart = std::chrono::high_resolution_clock::now();
  
    EvaluatorVisitor visitor(formulaMap, resultMap, inputMaps);
  
    try {
      antlrcpp::Any result = visitor.visit(mainContext - &gt; children[0]);
  
      auto visitEnd = std::chrono::high_resolution_clock::now();
      std::chrono::duration &lt; double &gt; totalElapsed = visitEnd - visitStart;
  
      //calculate time
      totalVisitTime += totalElapsed.count();
  
      resultMap - &gt; insert(pair &lt; string, double &gt; (itFormulas - &gt; first, v));
    } catch (EvaluationException ex) {
      string from = "Mistake" + string(" itFormulas-&gt;") + itFormulas - &gt; first;
    }
  }
  </code></pre>
  
  <p>If the total routine will took 5seconds
  The parser time will be around 1 second, and the visitor time will be 4seconds.</p>
  
  <p>I expect the time could be shorter, and wish to know which part can be optimised.</p>