My program iterates over a given data and I have observed a strange behavior. The first few samples that the algorithm processes, show a slow run time performance but then the subsequent samples and iterations run at almost a consistent (and with a relatively low run time than the first few samples/iterations).
Why is this so? I even tried to call the function outside of the iterating loop as a warm up function call hoping if the JVM was optimizing the code it would do that with the warm up function call.
// warm up function call
warpInfo = warp.getDTW(testSet.get(startIndex), trainSet.get(0), distFn, windowSize);
this.startTime = System.currentTimeMillis();
for(int i=startIndex; i<endIndex; i++) {
for(int j=0; j<trainSet.size(); j++) {
train = trainSet.get(j);
instStartTime = System.currentTimeMillis();
warpInfo = warp.getDTW(test, train, distFn, windowSize);
if(warpInfo.getWarpDistance()<bestDist) {
bestDist = warpInfo.getWarpDistance();
classPredicted = train.getTSClass();
}
instEndTime = System.currentTimeMillis();
instProcessingTime = instEndTime - instStartTime;
// record timiing and results here
}
// record other information here
}