From 5d3a93393271dd398ee4f63f9aeb4ca4c0949df5 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 7 Feb 2023 20:27:31 +0800 Subject: [PATCH] - enhancement: Change the way to calculate execution time. --- NEWS.md | 1 + RedPandaIDE/compiler/ojproblemcasesrunner.cpp | 10 ++++++++++ RedPandaIDE/editor.cpp | 1 - libs/qsynedit/qsynedit/qsynedit.cpp | 4 ++-- tools/consolepauser/main.windows.cpp | 19 ++++++++++++++++--- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index a509cfea..aa305e3d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ Red Panda C++ Version 2.11 - fix: Respect encoding "Project default" when search/find occurrencies/open project units. - enhancement: Show progress dialog when search/find occurrencies in large projects. - enhancement: Improve auto indent. + - enhancement: Change the way to calculate execution time. Red Panda C++ Version 2.10 diff --git a/RedPandaIDE/compiler/ojproblemcasesrunner.cpp b/RedPandaIDE/compiler/ojproblemcasesrunner.cpp index a3a8f44b..5f40b9bd 100644 --- a/RedPandaIDE/compiler/ojproblemcasesrunner.cpp +++ b/RedPandaIDE/compiler/ojproblemcasesrunner.cpp @@ -153,6 +153,16 @@ void OJProblemCasesRunner::runCase(int index,POJProblemCase problemCase) sizeof(counter))){ problemCase->runningMemory = counter.PeakWorkingSetSize; } + FILETIME creationTime; + FILETIME exitTime; + FILETIME kernelTime; + FILETIME userTime; + if (GetProcessTimes(hProcess,&creationTime,&exitTime,&kernelTime,&userTime)) { + LONGLONG t=((LONGLONG)kernelTime.dwHighDateTime<<32) + +((LONGLONG)userTime.dwHighDateTime<<32) + +(kernelTime.dwLowDateTime)+(userTime.dwLowDateTime); + problemCase->runningTime=(double)t/10000; + } } #endif if (execTimeouted) { diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index b407c031..9c5af808 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -61,7 +61,6 @@ Editor::Editor(QWidget *parent): { } - Editor::Editor(QWidget *parent, const QString& filename, const QByteArray& encoding, Project* pProject, bool isNew, diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index b93e30cd..bb48ca69 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -1634,8 +1634,8 @@ int QSynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent firstToken = mSyntaxer->getToken(); attr = mSyntaxer->getTokenAttribute(); } - qDebug()<preprocessorAttribute()) { indentSpaces=0; diff --git a/tools/consolepauser/main.windows.cpp b/tools/consolepauser/main.windows.cpp index 88d93753..1046fb5f 100644 --- a/tools/consolepauser/main.windows.cpp +++ b/tools/consolepauser/main.windows.cpp @@ -21,6 +21,7 @@ using std::string; #include #include #include +#include #include #ifndef WINBOOL @@ -115,7 +116,7 @@ string GetCommand(int argc,char** argv,bool &reInp,bool &pauseAfterExit) { return result; } -DWORD ExecuteCommand(string& command,bool reInp, LONGLONG &peakMemory) { +DWORD ExecuteCommand(string& command,bool reInp, LONGLONG &peakMemory, LONGLONG &execTime) { STARTUPINFOA si; PROCESS_INFORMATION pi; @@ -147,6 +148,16 @@ DWORD ExecuteCommand(string& command,bool reInp, LONGLONG &peakMemory) { sizeof(counter))){ peakMemory = counter.PeakWorkingSetSize/1024; } + FILETIME creationTime; + FILETIME exitTime; + FILETIME kernelTime; + FILETIME userTime; + execTime=0; + if (GetProcessTimes(pi.hProcess,&creationTime,&exitTime,&kernelTime,&userTime)) { + execTime=((LONGLONG)kernelTime.dwHighDateTime<<32) + +((LONGLONG)userTime.dwHighDateTime<<32) + +(kernelTime.dwLowDateTime)+(userTime.dwLowDateTime); + } DWORD result = 0; GetExitCodeProcess(pi.hProcess, &result); return result; @@ -233,12 +244,14 @@ int main(int argc, char** argv) { LONGLONG starttime = GetClockTick(); LONGLONG peakMemory=0; + LONGLONG execTime=0; // Then execute said command - DWORD returnvalue = ExecuteCommand(command,reInp,peakMemory); + DWORD returnvalue = ExecuteCommand(command,reInp,peakMemory,execTime); // Get ending timestamp LONGLONG endtime = GetClockTick(); double seconds = (endtime - starttime) / (double)GetClockFrequency(); + double execSeconds = (double)execTime/10000; if (pBuf) { strcpy(pBuf,"FINISHED"); @@ -250,7 +263,7 @@ int main(int argc, char** argv) { // Done? Print return value of executed program printf("\n--------------------------------"); - printf("\nProcess exited after %.4g seconds with return value %lu, %d KB mem used.\n",seconds,returnvalue,peakMemory); + printf("\nProcess exited after %.4g seconds with return value %lu (%.4g ms cpu time, %d KB mem used).\n",seconds,returnvalue, execSeconds, peakMemory); if (pauseAfterExit) PauseExit(returnvalue,reInp); return 0;