I’m doing what seems like a simple read from a data file, and it’s taking for fricking ever. (And by that, I mean 300ms.) This is the code in question:
BufferedReader f = new BufferedReader(new FileReader("input.txt"));
StringTokenizer st = new StringTokenizer(f.readLine());
int var1 = Integer.parseInt(st.nextToken())
int var2 = Integer.parseInt(st.nextToken());
Integer[][] people = new Integer[var1][];
for(int i = 0; i < var2; i++)
f.readLine();
for(Integer i = 0; i < var1; i++)
{
StringTokenizer line = new StringTokenizer(f.readLine(), " \t\n\r\f,");
line.nextToken();
Integer[] list = new Integer[line.countTokens()];
for(int j = 0; j < drinks.length; j++)
list[j] = Integer.parseInt(line.nextToken());
people[i] = list;
}
And this is the relevant time output:
sammysmbp:fridgemadness_lean sfishman$ time java fridgemadness
real 0m0.311s
user 0m0.277s
sys 0m0.056s
Is it just me or is that really, really slow. It’s only going through 51 lines of input in this example.
Just guessing, but probably a lot of the time is used up just for the jvm to start up.
Print a timestamp just before and after the relevant code. If my guess is correct a little server taking requests might help to eliminate the startup time.