title: Analysis for an XML parsing (and validating) C program
body: <p>Thanks to jmbr at Stack Overflow, I finally found a way to validate xml against RELAX NG via a C program. The program is as follows...</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  
  #include &lt;libxml/xmlmemory.h&gt;
  #include &lt;libxml/parser.h&gt;
  #include &lt;libxml/relaxng.h&gt;
  
  int main(int argc, char *argv[])
  {
     int status;
     xmlDoc *doc;
     xmlRelaxNGPtr schema;
     xmlRelaxNGValidCtxtPtr validctxt;
     xmlRelaxNGParserCtxtPtr rngparser;
  
     doc = xmlParseFile(argv[1]);
  
     rngparser = xmlRelaxNGNewParserCtxt(argv[2]);
     schema = xmlRelaxNGParse(rngparser);
     validctxt = xmlRelaxNGNewValidCtxt(schema);
  
     status = xmlRelaxNGValidateDoc(validctxt, doc);
     printf("status == %d\n", status);
  
     xmlRelaxNGFree(schema);
     xmlRelaxNGFreeValidCtxt(validctxt);
     xmlRelaxNGFreeParserCtxt(rngparser);
     xmlFreeDoc(doc);
     exit(EXIT_SUCCESS);
  </code></pre>
  
  <p>}</p>
  
  <p>I have, since then, significantly tweaked the program so as to find out the "processing time" for parsing and validating an xml file. Is there any way to find out the best case and worst case for this program. Worst case being, the time taken is always highest for any xml file as input. And best case being, the time taken is always lowest. I am really stuck at this. Would really appreciate it, if any of you guys could help me out.</p>