First of all, this question is quite generic, I fully recognise that. I cannot share the code of the text parsers as I'm working on some private data, but the context is as follows. I've been coding for about a year in Java (so my apologies if this seems uninformed). I wrote a text parser that dealt with pulling data from a website, and my original one was quite inefficent (like O(11n) if you want it asymptotically) which I know is still linear but the text file was huge, and the inefficiency shows by the fact that I got it down to O(n), essentially pulling everything I want in one go rather than 11 different gos.
To test if this efficiency improvement had made any empirical difference, I created a tester class that would start a stopwatch, run the first parser, print the time, end the first stopwatch, start a second one, run the second parser, and print the time. When I run the parsers separately, the first one is approximately 1.5-3 seconds (volatile, I know), and the second one is almost always 0.7 secs. When I run them through that independent tester class, the first one is slightly faster (1.5-2.5) but the second one runs absurdly quicker at around 0.05-0.07 seconds.
Is there any reason for this? I can't put my finger on it. Sorry if this is a generic question, it's not life or death but it's really intrigued me. For what it's worth, both parsers work perfectly/have the exact same outcome whether they're run by themselves or through the tester class.
If it helps, here's the code for the tester class. Sorry I can't share the code for the parsers.
public class ParserSpeedTest {
public static void main(final String[] args) {
Stopwatch st1 = new Stopwatch();
className.runParser1();
double time1 = st1.elapsedTime();
System.out.println("Elapsed Time: " + time1+" s");
System.out.println("---------------------------");
Stopwatch st2 = new Stopwatch();
otherClassName.runParser2();
double time2 = st2.elapsedTime();
System.out.println("Elapsed Time: " + time2+" s");
}
}