Use the flag to perform 'n' computations and average the total time taken.

This commit is contained in:
Pavel Krajcevski 2012-09-17 13:36:39 -04:00
parent 7116cc8b89
commit 8bea381389

View file

@ -91,7 +91,6 @@ CompressedImage * CompressImage(
CompressionFunc f = ChooseFuncFromSettings(settings); CompressionFunc f = ChooseFuncFromSettings(settings);
if(f) { if(f) {
StopWatch stopWatch = StopWatch();
double cmpMSTime = 0.0; double cmpMSTime = 0.0;
if(settings.iNumThreads > 1) { if(settings.iNumThreads > 1) {
@ -102,22 +101,42 @@ CompressedImage * CompressImage(
return NULL; return NULL;
} }
double cmpTimeTotal = 0.0;
for(int i = 0; i < settings.iNumCompressions; i++) {
if(i > 0)
tgrp.PrepareThreads();
tgrp.Start(); tgrp.Start();
tgrp.Join(); tgrp.Join();
stopWatch = tgrp.GetStopWatch(); StopWatch stopWatch = tgrp.GetStopWatch();
cmpTimeTotal += tgrp.GetStopWatch().TimeInMilliseconds();
}
cmpMSTime = cmpTimeTotal / double(settings.iNumCompressions);
tgrp.CleanUpThreads(); tgrp.CleanUpThreads();
} }
else { else {
double cmpTimeTotal = 0.0;
for(int i = 0; i < settings.iNumCompressions; i++) {
StopWatch stopWatch = StopWatch();
stopWatch.Reset();
stopWatch.Start(); stopWatch.Start();
(*f)(img.GetPixels(), cmpData, img.GetWidth(), img.GetHeight()); (*f)(img.GetPixels(), cmpData, img.GetWidth(), img.GetHeight());
stopWatch.Stop(); stopWatch.Stop();
cmpTimeTotal += stopWatch.TimeInMilliseconds();
}
cmpMSTime = cmpTimeTotal / double(settings.iNumCompressions);
outImg = new CompressedImage(img.GetWidth(), img.GetHeight(), settings.format, cmpData); outImg = new CompressedImage(img.GetWidth(), img.GetHeight(), settings.format, cmpData);
} }
// Report compression time // Report compression time
fprintf(stdout, "Compression time: %0.3f ms\n", stopWatch.TimeInMilliseconds()); fprintf(stdout, "Compression time: %0.3f ms\n", cmpMSTime);
} }
else { else {
ReportError("Could not find adequate compression function for specified settings"); ReportError("Could not find adequate compression function for specified settings");