- enhancement: Change the way to calculate execution time.

This commit is contained in:
Roy Qu 2023-02-07 20:27:31 +08:00
parent dd5df6912c
commit 5d3a933932
5 changed files with 29 additions and 6 deletions

View File

@ -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

View File

@ -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) {

View File

@ -61,7 +61,6 @@ Editor::Editor(QWidget *parent):
{
}
Editor::Editor(QWidget *parent, const QString& filename,
const QByteArray& encoding,
Project* pProject, bool isNew,

View File

@ -1634,8 +1634,8 @@ int QSynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent
firstToken = mSyntaxer->getToken();
attr = mSyntaxer->getTokenAttribute();
}
qDebug()<<line<<lineText;
qDebug()<<(int)rangeAfterFirstToken.lastUnindent.type<<rangeAfterFirstToken.lastUnindent.line;
// qDebug()<<line<<lineText;
// qDebug()<<(int)rangeAfterFirstToken.lastUnindent.type<<rangeAfterFirstToken.lastUnindent.line;
if (trimmedLineText.startsWith('#')
&& attr == ((CppSyntaxer *)mSyntaxer.get())->preprocessorAttribute()) {
indentSpaces=0;

View File

@ -21,6 +21,7 @@ using std::string;
#include <stdio.h>
#include <windows.h>
#include <psapi.h>
#include <processthreadsapi.h>
#include <conio.h>
#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;