mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
some fixes
This commit is contained in:
@@ -23,12 +23,12 @@ add_library(
|
||||
mdemList.cpp
|
||||
trainWindow.cpp
|
||||
settings.cpp
|
||||
${RESOURCES}
|
||||
)
|
||||
|
||||
add_executable(
|
||||
MdemoryApp
|
||||
main.cpp
|
||||
${RESOURCES}
|
||||
)
|
||||
|
||||
target_link_libraries(gui Qt5::Widgets /usr/lib/libqscintilla2_qt5.so api)
|
||||
|
||||
@@ -273,7 +273,7 @@ void switchPage(int pageIdx);
|
||||
std::string getFilename(std::string path) {
|
||||
static const std::regex lastPathElementExp = std::regex("(.+\\/)*(.+)");
|
||||
std::smatch matches;
|
||||
auto filenameMatched = std::regex_search(path, matches, lastPathElementExp);
|
||||
std::regex_search(path, matches, lastPathElementExp);
|
||||
return matches[2].str();
|
||||
}
|
||||
|
||||
@@ -385,7 +385,6 @@ Mdem* makeMdem() {
|
||||
mdem->hFront.addWidget(&mdem->toggleVisibility);
|
||||
|
||||
// Back
|
||||
QVBoxLayout *hBack = new QVBoxLayout();
|
||||
mdem->wBack.setLayout(&mdem->hBack);
|
||||
mdem->vMdem.addWidget(&mdem->wBack);
|
||||
|
||||
@@ -563,7 +562,6 @@ void reloadMdem(std::string path) {
|
||||
MdemBuffer *buffer;
|
||||
auto filename = getFilename(path);
|
||||
if (currentMdem.compare(path) == 0) {
|
||||
buffer = currentMdemBuffer;
|
||||
currentMdem = path;
|
||||
if (buffers.contains(path)) {
|
||||
buffers.erase(path);
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
#include "api.h"
|
||||
#include "mdemList.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
typedef std::chrono::nanoseconds duration;
|
||||
typedef duration::rep rep;
|
||||
typedef duration::period period;
|
||||
typedef std::chrono::time_point<std::chrono::system_clock, duration> time_point;
|
||||
|
||||
std::string testFileDirectory;
|
||||
|
||||
std::string readFileContents(const std::string& filePath) {
|
||||
std::ifstream file(filePath);
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "Could not open the file!" << std::endl;
|
||||
std::cerr << "Nevar atvert failu!" << std::endl;
|
||||
return "";
|
||||
}
|
||||
std::ostringstream ss;
|
||||
@@ -19,54 +24,45 @@ std::string readFileContents(const std::string& filePath) {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
TEST(PerformanceTest, DISABLED_Measure100_000SimpleQuestions) {
|
||||
double timePerformance(time_point start, time_point end, int numIterations) {
|
||||
std::chrono::duration<double> duration = end - start;
|
||||
double averageTime = duration.count() / numIterations;
|
||||
std::cout << "Vidējais laiks (" << numIterations << " iterācijas): "
|
||||
<< averageTime
|
||||
<< " sekundes iterācijā\n";
|
||||
auto averagePerSecond = (100000 / averageTime);
|
||||
std::cout << "Jautājumi sekundē(" << numIterations << " iterācijas): "
|
||||
<< averagePerSecond << std::endl;
|
||||
return averagePerSecond;
|
||||
};
|
||||
|
||||
TEST(PerformanceTest, Measure100000SimpleQuestions) {
|
||||
const std::string filePath = testFileDirectory + "/100000_simple_questions.mdem";
|
||||
const std::string contents = readFileContents(filePath);
|
||||
const int numIterations = 15;
|
||||
auto parseLargeFile = [contents]() {
|
||||
auto questions = transpile(contents);
|
||||
};
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < numIterations; ++i) {
|
||||
parseLargeFile();
|
||||
auto questions = transpile(contents);
|
||||
}
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> duration = end - start;
|
||||
|
||||
double averageTime = duration.count() / numIterations;
|
||||
std::cout << "Average time: "
|
||||
<< averageTime
|
||||
<< " seconds per iteration\n";
|
||||
auto averagePerSecond = (100000 / averageTime);
|
||||
std::cout << "Questions per second (" << numIterations << " iterations): "
|
||||
<< averagePerSecond << std::endl;
|
||||
|
||||
ASSERT_GE(averagePerSecond, 24999);
|
||||
ASSERT_GE(timePerformance(start, end, numIterations), 24999);
|
||||
}
|
||||
|
||||
TEST(PerformanceTest, MeasureOutput100_000SimpleQuestions) {
|
||||
TEST(PerformanceTest, MeasureOutput100000SimpleQuestions) {
|
||||
const std::string filePath = testFileDirectory + "/100000_simple_questions.mdem";
|
||||
const std::string contents = readFileContents(filePath);
|
||||
auto info = transpile(contents).value;
|
||||
const int numIterations = 15;
|
||||
|
||||
auto info = transpile(contents).value;
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
for (int i = 0; i < numIterations; ++i) {
|
||||
auto output = outputMdem(info.questions, 0, 80, 0);
|
||||
}
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> duration = end - start;
|
||||
|
||||
double averageTime = duration.count() / numIterations;
|
||||
std::cout << "Average time: "
|
||||
<< averageTime
|
||||
<< " seconds per iteration\n";
|
||||
auto averagePerSecond = (100000 / averageTime);
|
||||
std::cout << "Questions per second (" << numIterations << " iterations): "
|
||||
<< averagePerSecond << std::endl;
|
||||
|
||||
ASSERT_GE(averagePerSecond, 24999);
|
||||
ASSERT_GE(timePerformance(start, end, numIterations), 100000);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
@@ -80,4 +76,3 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
|
||||
@@ -231,6 +231,8 @@ Result<std::vector<Token>> tokenizeMdem(const std::string& content) {
|
||||
previousRow = row;
|
||||
previousColumn = column;
|
||||
textStarted = false;
|
||||
} break;
|
||||
default:{
|
||||
} break;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ Result<NoneType> ValidateGrammar(const std::vector<Token>& tokens) {
|
||||
auto capitalize = [](const std::string& str) {
|
||||
if (str.empty()) return str;
|
||||
std::string result = str;
|
||||
result[0] = std::towupper(result[0]);
|
||||
result[0] = std::toupper(result[0]);
|
||||
return result;
|
||||
};
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user