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
|
mdemList.cpp
|
||||||
trainWindow.cpp
|
trainWindow.cpp
|
||||||
settings.cpp
|
settings.cpp
|
||||||
${RESOURCES}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(
|
add_executable(
|
||||||
MdemoryApp
|
MdemoryApp
|
||||||
main.cpp
|
main.cpp
|
||||||
|
${RESOURCES}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(gui Qt5::Widgets /usr/lib/libqscintilla2_qt5.so api)
|
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) {
|
std::string getFilename(std::string path) {
|
||||||
static const std::regex lastPathElementExp = std::regex("(.+\\/)*(.+)");
|
static const std::regex lastPathElementExp = std::regex("(.+\\/)*(.+)");
|
||||||
std::smatch matches;
|
std::smatch matches;
|
||||||
auto filenameMatched = std::regex_search(path, matches, lastPathElementExp);
|
std::regex_search(path, matches, lastPathElementExp);
|
||||||
return matches[2].str();
|
return matches[2].str();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,7 +385,6 @@ Mdem* makeMdem() {
|
|||||||
mdem->hFront.addWidget(&mdem->toggleVisibility);
|
mdem->hFront.addWidget(&mdem->toggleVisibility);
|
||||||
|
|
||||||
// Back
|
// Back
|
||||||
QVBoxLayout *hBack = new QVBoxLayout();
|
|
||||||
mdem->wBack.setLayout(&mdem->hBack);
|
mdem->wBack.setLayout(&mdem->hBack);
|
||||||
mdem->vMdem.addWidget(&mdem->wBack);
|
mdem->vMdem.addWidget(&mdem->wBack);
|
||||||
|
|
||||||
@@ -563,7 +562,6 @@ void reloadMdem(std::string path) {
|
|||||||
MdemBuffer *buffer;
|
MdemBuffer *buffer;
|
||||||
auto filename = getFilename(path);
|
auto filename = getFilename(path);
|
||||||
if (currentMdem.compare(path) == 0) {
|
if (currentMdem.compare(path) == 0) {
|
||||||
buffer = currentMdemBuffer;
|
|
||||||
currentMdem = path;
|
currentMdem = path;
|
||||||
if (buffers.contains(path)) {
|
if (buffers.contains(path)) {
|
||||||
buffers.erase(path);
|
buffers.erase(path);
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
#include "api.h"
|
#include "api.h"
|
||||||
#include "mdemList.h"
|
#include "mdemList.h"
|
||||||
#include "settings.h"
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#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 testFileDirectory;
|
||||||
|
|
||||||
std::string readFileContents(const std::string& filePath) {
|
std::string readFileContents(const std::string& filePath) {
|
||||||
std::ifstream file(filePath);
|
std::ifstream file(filePath);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
std::cerr << "Could not open the file!" << std::endl;
|
std::cerr << "Nevar atvert failu!" << std::endl;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
@@ -19,54 +24,45 @@ std::string readFileContents(const std::string& filePath) {
|
|||||||
return ss.str();
|
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 filePath = testFileDirectory + "/100000_simple_questions.mdem";
|
||||||
const std::string contents = readFileContents(filePath);
|
const std::string contents = readFileContents(filePath);
|
||||||
const int numIterations = 15;
|
const int numIterations = 15;
|
||||||
auto parseLargeFile = [contents]() {
|
|
||||||
auto questions = transpile(contents);
|
|
||||||
};
|
|
||||||
|
|
||||||
auto start = std::chrono::high_resolution_clock::now();
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
for (int i = 0; i < numIterations; ++i) {
|
for (int i = 0; i < numIterations; ++i) {
|
||||||
parseLargeFile();
|
auto questions = transpile(contents);
|
||||||
}
|
}
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
std::chrono::duration<double> duration = end - start;
|
|
||||||
|
ASSERT_GE(timePerformance(start, end, numIterations), 24999);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(PerformanceTest, MeasureOutput100_000SimpleQuestions) {
|
TEST(PerformanceTest, MeasureOutput100000SimpleQuestions) {
|
||||||
const std::string filePath = testFileDirectory + "/100000_simple_questions.mdem";
|
const std::string filePath = testFileDirectory + "/100000_simple_questions.mdem";
|
||||||
const std::string contents = readFileContents(filePath);
|
const std::string contents = readFileContents(filePath);
|
||||||
auto info = transpile(contents).value;
|
|
||||||
const int numIterations = 15;
|
const int numIterations = 15;
|
||||||
|
|
||||||
|
auto info = transpile(contents).value;
|
||||||
auto start = std::chrono::high_resolution_clock::now();
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
for (int i = 0; i < numIterations; ++i) {
|
for (int i = 0; i < numIterations; ++i) {
|
||||||
auto output = outputMdem(info.questions, 0, 80, 0);
|
auto output = outputMdem(info.questions, 0, 80, 0);
|
||||||
}
|
}
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
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) {
|
int main(int argc, char **argv) {
|
||||||
@@ -80,4 +76,3 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -231,6 +231,8 @@ Result<std::vector<Token>> tokenizeMdem(const std::string& content) {
|
|||||||
previousRow = row;
|
previousRow = row;
|
||||||
previousColumn = column;
|
previousColumn = column;
|
||||||
textStarted = false;
|
textStarted = false;
|
||||||
|
} break;
|
||||||
|
default:{
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ Result<NoneType> ValidateGrammar(const std::vector<Token>& tokens) {
|
|||||||
auto capitalize = [](const std::string& str) {
|
auto capitalize = [](const std::string& str) {
|
||||||
if (str.empty()) return str;
|
if (str.empty()) return str;
|
||||||
std::string result = str;
|
std::string result = str;
|
||||||
result[0] = std::towupper(result[0]);
|
result[0] = std::toupper(result[0]);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user