0

I want to know the time taken to parse an XML file. I am using SAX Parser. I dont want to know how long it took ( after the parsing is complete) hence I cannot use System.nanoTime() or System.currentTimeMillis()

How can I estimate the time taken for parsing in advance? ( maybe based on the size of the file)

Abi
  • 1,335
  • 2
  • 15
  • 28

2 Answers2

3

This is a tricky question. The short answer is: you can't know in advance exactly how long it is going to take.

Your best bet might be to estimate how long it will take by running some benchmarks on how long it takes you to parse say a 1K file, a 10K file, a 100K file, and a 1MB and interpolate between them. (assuming 1MB is a reasonable upper bound)

However, this estimate would only be valid on your computer for your specific hardware/software configuration. You can't generalize it in a meaningful way.

JohnnyO
  • 3,018
  • 18
  • 30
  • In addition to this, remember that sometimes your code could have some functions depending on the incremental number of processed nodes. So, when analyzing make sure, there is no o(n) or more functions in your code. it could be okay to parse 50,000 but the more the nodes, the lower the speed of processing ! – Mohamed Taher Alrefaie Feb 05 '14 at 15:34
1

What you could do is, take a sample 1 MB File and parse it. Record the time as below:

int testcases = 10; // Configure it to find the average
for(int i=0;i<testcases;i++)
{
long startTime = System.currentTimeMillis();
// Call a method that performs parsing of the XML.
// Method Returns once parsing is done.

long endTime = System.currentTimeMillis();

long delta = endTime - startTime;
System.out.println("Average Time taken: " + delta);
}

By the above, it is possible to come up with an average of the time taken.

mreaper
  • 126
  • 7