diff --git a/Makefile b/Makefile index 719fb30e5..7f416fb1a 100644 --- a/Makefile +++ b/Makefile @@ -158,6 +158,7 @@ TESTOBJ = test/options.o \ test/testsuppressions.o \ test/testsymboldatabase.o \ test/testthreadexecutor.o \ + test/testtimer.o \ test/testtoken.o \ test/testtokenize.o \ test/testuninitvar.o \ @@ -393,7 +394,7 @@ test/testleakautovar.o: test/testleakautovar.cpp lib/tokenize.h lib/errorlogger. test/testmathlib.o: test/testmathlib.cpp lib/mathlib.h lib/config.h test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testmathlib.o test/testmathlib.cpp -test/testmemleak.o: test/testmemleak.cpp lib/tokenize.h lib/errorlogger.h lib/config.h lib/suppressions.h lib/tokenlist.h lib/checkmemoryleak.h lib/check.h lib/token.h lib/settings.h lib/standards.h test/testsuite.h test/redirect.h +test/testmemleak.o: test/testmemleak.cpp lib/tokenize.h lib/errorlogger.h lib/config.h lib/suppressions.h lib/tokenlist.h lib/checkmemoryleak.h lib/check.h lib/token.h lib/settings.h lib/standards.h test/testsuite.h test/redirect.h lib/symboldatabase.h lib/mathlib.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testmemleak.o test/testmemleak.cpp test/testnonreentrantfunctions.o: test/testnonreentrantfunctions.cpp lib/tokenize.h lib/errorlogger.h lib/config.h lib/suppressions.h lib/tokenlist.h lib/checknonreentrantfunctions.h lib/check.h lib/token.h lib/settings.h lib/standards.h test/testsuite.h test/redirect.h @@ -444,6 +445,9 @@ test/testsymboldatabase.o: test/testsymboldatabase.cpp test/testsuite.h lib/erro test/testthreadexecutor.o: test/testthreadexecutor.cpp lib/cppcheck.h lib/config.h lib/settings.h lib/suppressions.h lib/standards.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/tokenlist.h test/testsuite.h test/redirect.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testthreadexecutor.o test/testthreadexecutor.cpp +test/testtimer.o: test/testtimer.cpp lib/timer.h lib/config.h test/testsuite.h lib/errorlogger.h lib/suppressions.h test/redirect.h + $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testtimer.o test/testtimer.cpp + test/testtoken.o: test/testtoken.cpp test/testsuite.h lib/errorlogger.h lib/config.h lib/suppressions.h test/redirect.h test/testutils.h lib/settings.h lib/standards.h lib/tokenize.h lib/tokenlist.h lib/token.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) ${INCLUDE_FOR_TEST} -c -o test/testtoken.o test/testtoken.cpp diff --git a/lib/timer.cpp b/lib/timer.cpp index a989cf39f..07d7a3b0d 100644 --- a/lib/timer.cpp +++ b/lib/timer.cpp @@ -19,36 +19,36 @@ #include "timer.h" /* - TODO: - - handle SHOWTIME_TOP5 in TimerResults - - sort list by time - - do not sort the results alphabetically - - rename "file" to "single" - - synchronise map access in multithreaded mode or disable timing - - add unit tests - - for --showtime (needs input file) - - for Timer* classes + TODO: + - handle SHOWTIME_TOP5 in TimerResults + - sort list by time + - do not sort the results alphabetically + - rename "file" to "single" + - synchronise map access in multithreaded mode or disable timing + - add unit tests + - for --showtime (needs input file) + - for Timer* classes */ void TimerResults::ShowResults() const { - std::clock_t overallClocks = 0; + TimerResultsData overallData; std::map::const_iterator I = _results.begin(); const std::map::const_iterator E = _results.end(); while (I != E) { - const double sec = (double)I->second._clocks / CLOCKS_PER_SEC; - const double secAverage = (double)(I->second._clocks / I->second._numberOfResults) / CLOCKS_PER_SEC; + const double sec = I->second.seconds(); + const double secAverage = sec / (double)(I->second._numberOfResults); std::cout << I->first << ": " << sec << "s (avg. " << secAverage << "s - " << I->second._numberOfResults << " result(s))" << std::endl; - overallClocks += I->second._clocks; + overallData._clocks += I->second._clocks; ++I; } - const double secOverall = (double)overallClocks / CLOCKS_PER_SEC; + const double secOverall = overallData.seconds(); std::cout << "Overall time: " << secOverall << "s" << std::endl; } diff --git a/lib/timer.h b/lib/timer.h index fe8760f06..d69b53b9f 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -46,6 +46,11 @@ struct TimerResultsData { : _clocks(0) , _numberOfResults(0) { } + + double seconds() const { + double ret = (double)((unsigned long)_clocks) / (double)CLOCKS_PER_SEC; + return ret; + } }; class CPPCHECKLIB TimerResults : public TimerResultsIntf { diff --git a/test/testfiles.pri b/test/testfiles.pri index e7c86771a..074fa03dc 100644 --- a/test/testfiles.pri +++ b/test/testfiles.pri @@ -39,6 +39,7 @@ SOURCES += $${BASEPATH}/test64bit.cpp \ $${BASEPATH}/testsuppressions.cpp \ $${BASEPATH}/testsymboldatabase.cpp \ $${BASEPATH}/testthreadexecutor.cpp \ + $${BASEPATH}/testtimer.cpp \ $${BASEPATH}/testtoken.cpp \ $${BASEPATH}/testtokenize.cpp \ $${BASEPATH}/testuninitvar.cpp \