diff --git a/sim/Propagator.cpp b/sim/Propagator.cpp index 79b3b79..4abd97b 100644 --- a/sim/Propagator.cpp +++ b/sim/Propagator.cpp @@ -3,10 +3,12 @@ #include "sim/RK4Solver.h" #include "model/Rocket.h" +#include "utils/Logger.h" #include "QtRocket.h" #include -#include +#include +#include namespace sim { @@ -45,8 +47,9 @@ Propagator::~Propagator() void Propagator::runUntilTerminate() { + std::chrono::steady_clock::time_point startTime = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point endTime; - QTextStream out(stdout); std::size_t j = 0; while(true && j < 100000) { @@ -66,19 +69,19 @@ void Propagator::runUntilTerminate() { states.push_back(currentState); } - out << currentTime << ": (" - << currentState[0] << ", " - << currentState[1] << ", " - << currentState[2] << ", " - << currentState[3] << ", " - << currentState[4] << ", " - << currentState[5] << ")\n"; if(currentState[2] < 0.0) break; j++; currentTime += timeStep; } + endTime = std::chrono::steady_clock::now(); + + std::stringstream duration; + duration << "runUntilTerminate time (microseconds): "; + duration << std::chrono::duration_cast(endTime - startTime).count(); + utils::Logger::getInstance()->debug(duration.str()); + } double Propagator::getMass() diff --git a/utils/Logger.cpp b/utils/Logger.cpp index da226e9..879ac89 100644 --- a/utils/Logger.cpp +++ b/utils/Logger.cpp @@ -18,12 +18,6 @@ Logger* Logger::getInstance() Logger::Logger() { outFile.open("log.txt"); - /* - error = [this](std::string_view msg) { log(msg, ERROR); }; - warn = [this](std::string_view msg) { log(msg, WARN); }; - info = [this](std::string_view msg) { log(msg, INFO); }; - debug = [this](std::string_view msg) { log(msg, DEBUG); }; - */ } Logger::~Logger() @@ -42,21 +36,21 @@ void Logger::log(std::string_view msg, const LogLevel& lvl) if(lvl == DEBUG) { outFile << "[DEBUG] " << msg << std::endl; - std::cout << "[DEBUG] " << msg << std::endl; + std::cout << "[DEBUG] " << msg << "\n"; } [[fallthrough]]; case INFO: if(lvl == INFO) { outFile << "[INFO] " << msg << std::endl; - std::cout << "[INFO] " << msg << std::endl; + std::cout << "[INFO] " << msg << "\n"; } [[fallthrough]]; case WARN: if(lvl == WARN) { outFile << "[WARN] " << msg << std::endl; - std::cout << "[WARN] " << msg << std::endl; + std::cout << "[WARN] " << msg << "\n"; } [[fallthrough]]; // Regardless of what level is set, ERROR is always logged, so @@ -65,8 +59,7 @@ void Logger::log(std::string_view msg, const LogLevel& lvl) if(lvl == ERROR) { outFile << "[ERROR] " << msg << std::endl; - std::cout << "[ERROR] " << msg << std::endl; - std::cerr << "[ERROR] " << msg << std::endl; + std::cout << "[ERROR] " << msg << "\n"; } } } diff --git a/utils/Logger.h b/utils/Logger.h index d716df7..c151c4e 100644 --- a/utils/Logger.h +++ b/utils/Logger.h @@ -4,7 +4,6 @@ #include #include #include -//#include /** * @todo write docs