[yul-phaser] AlgorithmRunner: Measure CPU time rather than wall-clock time

This commit is contained in:
Kamil Śliwak 2020-03-09 19:19:42 +01:00
parent cd16a6e178
commit 58e3fca3de
2 changed files with 12 additions and 12 deletions

View File

@ -34,10 +34,10 @@ void AlgorithmRunner::run(GeneticAlgorithm& _algorithm)
printInitialPopulation(); printInitialPopulation();
cacheClear(); cacheClear();
chrono::steady_clock::time_point totalTimeStart = std::chrono::steady_clock::now(); clock_t totalTimeStart = clock();
for (size_t round = 0; !m_options.maxRounds.has_value() || round < m_options.maxRounds.value(); ++round) for (size_t round = 0; !m_options.maxRounds.has_value() || round < m_options.maxRounds.value(); ++round)
{ {
chrono::steady_clock::time_point roundTimeStart = std::chrono::steady_clock::now(); clock_t roundTimeStart = clock();
cacheStartRound(round + 1); cacheStartRound(round + 1);
m_population = _algorithm.runNextRound(m_population); m_population = _algorithm.runNextRound(m_population);
@ -51,21 +51,21 @@ void AlgorithmRunner::run(GeneticAlgorithm& _algorithm)
void AlgorithmRunner::printRoundSummary( void AlgorithmRunner::printRoundSummary(
size_t _round, size_t _round,
chrono::steady_clock::time_point _roundTimeStart, clock_t _roundTimeStart,
chrono::steady_clock::time_point _totalTimeStart clock_t _totalTimeStart
) const ) const
{ {
if (!m_options.showOnlyTopChromosome) if (!m_options.showOnlyTopChromosome)
{ {
if (m_options.showRoundInfo) if (m_options.showRoundInfo)
{ {
chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); clock_t now = clock();
auto roundTime = chrono::duration_cast<chrono::milliseconds>(now - _roundTimeStart).count(); double roundTime = static_cast<double>(now - _roundTimeStart) / CLOCKS_PER_SEC;
auto totalTime = chrono::duration_cast<chrono::milliseconds>(now - _totalTimeStart).count(); double totalTime = static_cast<double>(now - _totalTimeStart) / CLOCKS_PER_SEC;
m_outputStream << "---------- ROUND " << _round + 1; m_outputStream << "---------- ROUND " << _round + 1;
m_outputStream << " [round: " << fixed << setprecision(1) << roundTime / 1000.0 << " s,"; m_outputStream << " [round: " << fixed << setprecision(1) << roundTime << " s,";
m_outputStream << " total: " << fixed << setprecision(1) << totalTime / 1000.0 << " s]"; m_outputStream << " total: " << fixed << setprecision(1) << totalTime << " s]";
m_outputStream << " ----------" << endl; m_outputStream << " ----------" << endl;
} }
else if (m_population.individuals().size() > 0) else if (m_population.individuals().size() > 0)

View File

@ -24,7 +24,7 @@
#include <tools/yulPhaser/Population.h> #include <tools/yulPhaser/Population.h>
#include <tools/yulPhaser/ProgramCache.h> #include <tools/yulPhaser/ProgramCache.h>
#include <chrono> #include <ctime>
#include <optional> #include <optional>
#include <ostream> #include <ostream>
@ -73,8 +73,8 @@ public:
private: private:
void printRoundSummary( void printRoundSummary(
size_t _round, size_t _round,
std::chrono::steady_clock::time_point _roundTimeStart, clock_t _roundTimeStart,
std::chrono::steady_clock::time_point _totalTimeStart clock_t _totalTimeStart
) const; ) const;
void printInitialPopulation() const; void printInitialPopulation() const;
void printCacheStats() const; void printCacheStats() const;