package org.commonmark;

import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.commonmark.testutil.TestResources;

import java.util.Collections;
import java.util.List;

public class ProfilingMain {

    private static final String SPEC = TestResources.readAsString(TestResources.getSpec());
    //    private static final List<String> SPEC_EXAMPLES = ExampleReader.readExampleSources(TestResources.getSpec());
    private static final Parser PARSER = Parser.builder().build();
    private static final HtmlRenderer RENDERER = HtmlRenderer.builder().build();

    public static void main(String[] args) throws Exception {
        System.out.println("Started up, attach profiler now");
        Thread.sleep(10_000);
        System.out.println("Parsing and rendering");
        parseAndRender(Collections.singletonList(SPEC));
        System.out.println("Finished parsing");
    }

    private static long parseAndRender(List<String> examples) {
        long length = 0;
        for (String example : examples) {
            String result = RENDERER.render(PARSER.parse(example));
            length += result.length();
        }
        return length;
    }
}

@@ -18,16 +18,49 @@
 nmark;%0A%0A
+import org.commonmark.node.Node;%0A
 import o
@@ -185,16 +185,44 @@
 urces;%0A%0A
+import java.util.ArrayList;%0A
 import j
@@ -751,21 +751,9 @@
 ln(%22
-Started up, a
+A
 ttac
@@ -766,261 +766,688 @@
 iler
- now%22);%0A        Thread.sleep(10_000);%0A        System.out.println(%22Parsing and rendering%22);%0A        parseAndRender(Collections.singletonList(SPEC));%0A        System.out.println(%22Finished parsing%22);%0A    %7D%0A%0A    private static long parseAndRender(List%3CString
+, then press enter to start parsing.%22);%0A        System.in.read();%0A        System.out.println(%22Parsing%22);%0A        List%3CNode%3E nodes = parse(Collections.singletonList(SPEC));%0A        System.out.println(%22Finished parsing, press enter to start rendering%22);%0A        System.in.read();%0A        System.out.println(render(nodes));%0A        System.out.println(%22Finished rendering%22);%0A    %7D%0A%0A    private static List%3CNode%3E parse(List%3CString%3E examples) %7B%0A        List%3CNode%3E nodes = new ArrayList%3C%3E();%0A        for (String example : examples) %7B%0A            Node doc = PARSER.parse(example);%0A            nodes.add(doc);%0A        %7D%0A        return nodes;%0A    %7D%0A%0A    private static long render(List%3CNode
 %3E ex
@@ -1486,38 +1486,36 @@
 0;%0A        for (
-String
+Node
  example : examp
@@ -1565,37 +1565,24 @@
 .render(
-PARSER.parse(
 example)
 );%0A     
@@ -1573,17 +1573,16 @@
 example)
-)
 ;%0A      

Improve ProfilingMain