paramerized show time and debug in global config

Also some additional time measurements in the qt app.
This commit is contained in:
jorenchik
2024-10-27 12:12:00 +02:00
parent 09a25d9216
commit 6359d97ba5
13 changed files with 97 additions and 44 deletions

View File

@@ -1,17 +1,18 @@
#include <iostream>
#include <sstream>
#include <vector>
#include <chrono>
#include <cmath>
#include "api.h"
#include "result.h"
#include "lexer.h"
#include "parser.h"
#include "time.h"
#include "config.h"
#define TABWIDTH 4
bool debug;
bool debug = false;
bool showTimes = false;
std::chrono::high_resolution_clock::time_point start;
std::chrono::high_resolution_clock::time_point end;
@@ -88,10 +89,9 @@ std::string escapeText(std::string text) {
return ss.str();
}
Result<ParseInfo> transpile(std::string fileContent, bool isDebug) {
Result<ParseInfo> transpile(std::string fileContent) {
start = std::chrono::high_resolution_clock::now();
end = std::chrono::high_resolution_clock::now();
debug = isDebug;
auto lexRes = tokenizeMdem(fileContent);
auto tokens = lexRes.value;
@@ -122,6 +122,16 @@ Result<ParseInfo> transpile(std::string fileContent, bool isDebug) {
}
end = std::chrono::high_resolution_clock::now();
showTime("Transpilation time");
if (showTimes) {
std::cout << showTime("Transpilation time") << std::endl;
}
return {questions};
}
std::string showTime(std::string label) {
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
double_t seconds = (double_t) duration.count() / 1000000;
double_t miliseconds = (double_t) duration.count() / 1000;
return std::format("{}: {:.3f} s, {:.3f} ms", label, seconds, miliseconds);
}