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:
@@ -8,7 +8,6 @@ add_library(
|
||||
api
|
||||
lexer.cpp
|
||||
parser.cpp
|
||||
time.cpp
|
||||
api.cpp
|
||||
stringUtils.cpp
|
||||
)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
#include "time.h"
|
||||
#include "config.h"
|
||||
#include "api.h"
|
||||
|
||||
std::string readFile(const std::string& filePath) {
|
||||
@@ -27,11 +27,11 @@ std::string readFile(const std::string& filePath) {
|
||||
int main(int argc, char* argv[]) {
|
||||
std::string filePath;
|
||||
|
||||
bool debug = false;
|
||||
if (argc == 3) {
|
||||
auto option = std::string(argv[1]);
|
||||
if (option == "--debug") {
|
||||
debug = true;
|
||||
debug = true;
|
||||
showTimes = true;
|
||||
} else {
|
||||
std::cout << std::format("Unrecognized option: {}", option) << std::endl;
|
||||
return 1;
|
||||
@@ -47,9 +47,11 @@ int main(int argc, char* argv[]) {
|
||||
try {
|
||||
std::string fileContent = readFile(filePath);
|
||||
end = std::chrono::high_resolution_clock::now();
|
||||
showTime("I/O time");
|
||||
if (showTimes) {
|
||||
std::cout << showTime("I/O time") << std::endl;
|
||||
}
|
||||
|
||||
auto res = transpile(fileContent, debug);
|
||||
auto res = transpile(fileContent);
|
||||
auto questions = res.value.questions;
|
||||
if (res.error.length() > 0) {
|
||||
std::cout << std::format(
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
#include "time.h"
|
||||
|
||||
void showTime(std::string label) {
|
||||
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
|
||||
double_t msDuration = (double_t) duration.count() / 1000;
|
||||
std::cout << std::format("{}: {:.3f} ms", label, msDuration) << std::endl;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include<chrono>
|
||||
|
||||
extern std::chrono::high_resolution_clock::time_point start;
|
||||
extern std::chrono::high_resolution_clock::time_point end;
|
||||
|
||||
void showTime(std::string label);
|
||||
Reference in New Issue
Block a user