mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
paramerized show time and debug in global config
Also some additional time measurements in the qt app.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user