diff --git a/corelib/test/perf_bayesfilter.cpp b/corelib/test/perf_bayesfilter.cpp index c224f586..ab1a1d62 100644 --- a/corelib/test/perf_bayesfilter.cpp +++ b/corelib/test/perf_bayesfilter.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -151,8 +152,8 @@ private: struct Result { - double firstIteration = 0.0; // includes generating the prediction matrix, and its sparse view - double steadyState = 0.0; // mean of the following iterations, the matrix being unchanged + double firstIteration = 0.0; // includes generating the prediction, sparse or dense + double steadyState = 0.0; // fastest of the following iterations, the prediction being unchanged unsigned long memoryUsed = 0; std::map posterior; }; @@ -172,14 +173,34 @@ Result run(const SyntheticMap & map, const char * predictionLC, bool sparse, int filter.computePosterior(map.memory(), likelihood); result.firstIteration = timer.ticks(); - double total = 0.0; + // A few untimed iterations to let the caches and the processor clock settle before + // measuring. A fixed count, the same whatever the mode: the filter is recursive, so + // how many iterations it has run decides where its posterior is, and warming up for a + // fixed duration instead would run hundreds of them in the fast mode against one in + // the slow one and leave the two posteriors nowhere near each other. + for(int i=0; i<3; ++i) + { + filter.computePosterior(map.memory(), likelihood); + } + + // The fastest iteration rather than the mean or the median of them. Everything that + // makes an iteration slower than its own best is the machine rather than the code + // being measured, and the dense multiplication reads the whole prediction matrix from + // memory, which makes it sensitive to whatever else is using that memory. The fastest + // is the one measurement of the run that is the least of it, so it is the one that + // compares between runs and between machines. + double best = 0.0; for(int i=1; i 1 ? total/double(iterations-1) : result.firstIteration; + result.steadyState = best > 0.0 ? best : result.firstIteration; result.memoryUsed = filter.getMemoryUsed(); result.posterior = filter.getPosterior(); return result; @@ -212,7 +233,7 @@ double maxPosteriorDifference(const std::map & a, const std::map