News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Timing execution time in a batch file

Started by jj2007, December 11, 2020, 01:08:33 AM

Previous topic - Next topic

jj2007

Instead of dir *.asm, you can put any executable(s) you like:
@echo off
TimeWithAtom.exe
set twa=%ERRORLEVEL%
dir *.asm
TimeWithAtom.exe %twa%
pause


Output:
... plenty of files ...
** compiling took 284 milliseconds **


Source & exe attached. Note it's assembly - heuristic scanners of crappy AV software don't like it. I've assembled the exe a minute ago, so if you trust me, simply ignore them (or consult our dedicated sub-forum) :cool:

HSE

Hi JJ!

RichMasm crash with the option "Autoformat" without text selected. (I was searching the option "To kill the turquois"  :biggrin:)

PD: How you change highlight7?
Equations in Assembly: SmplMath

jj2007

Quote from: HSE on December 11, 2020, 06:26:51 AM
Hi JJ!

RichMasm crash with the option "Autoformat" without text selected. (I was searching the option "To kill the turquois"  :biggrin:)

PD: How you change highlight7?

Good find, thanks :thup:

Autoformat will be fixed in a few hours. What do you mean with "highlight7", the yellow highlighting? Change it manually by selecting the text and pressing Ctrl H. This toggles between no highlighting, yellow and white background. I use that frequently for push & pop sequences - the outer ones yellow, the middle ones white etc

In case you want a different background colour, copy
\Masm32\MasmBasic\Res\RichMasm.ini to
\Masm32\MasmBasic\Res\UserDef\RichMasm.ini and start editing that file. Needs a restart of RichMasm, though.

Another option is to hit Ctrl G, then type udc=1 <Return> (0...7; caution with udc=6, it's white on black)

Btw TimeWithAtom seems not to work with Win10; the atom functions don't work any more :sad:

HSE

Quote from: jj2007 on December 11, 2020, 07:42:19 AM
What do you mean with "highlight7", the yellow highlighting?
highlight7 is the turquois below "Usage", don't die ( :biggrin: ) changing others backgrounds in RichMasm.ini.

Quote from: jj2007 on December 11, 2020, 07:42:19 AM
In case you want a different background colour, copy
\Masm32\MasmBasic\Res\RichMasm.ini to
\Masm32\MasmBasic\Res\UserDef\RichMasm.ini and start editing that file. Needs a restart of RichMasm, though.
No here. \Masm32\MasmBasic\Res\RichMasm.ini is the active file.
Equations in Assembly: SmplMath

jj2007

Quote from: HSE on December 11, 2020, 09:37:46 AM
highlight7 is the turquois below "Usage"

Just select the text and press Ctrl H three times.

P.S.: The Autoformat problem is fixed, see version 11 December

Back on topic: Attached two new versions of the timing program. One uses global atoms and is meant to check why it fails on Windows 10, the other one called "timeit.exe" uses a much simpler solution, but I'm not sure if it works everywhere - feedback welcome. Just extract all files to a folder and run the *.bat file :cool:

TimoVJL

With UAsm tests i used this tool.
@DEL *.obj
@DEL *.err
_RunCmdTime.exe %1 -c -coff -q \masm32\m32lib\*.asm >NUL
@ECHO %1
@DEL *.obj
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>

#pragma comment(lib, "user32.lib")

int __cdecl mainCRTStartup(void)
//int main(int argc, char **argv)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
FILETIME ftCreationTime, ftExitTime, ftKernelTime, ftUserTime;
SYSTEMTIME stTime;
DWORD nLen, nWrite;
long long ll;
char *pChar;
char szTmp[100];

pChar = GetCommandLine();
if (*pChar == '"') {
pChar++;
while (*pChar && *pChar != '"')
pChar++;
pChar++;
} else {
while (*pChar && *pChar != ' ')
pChar++;
}
while (*pChar <= ' ')
pChar++;

ftExitTime.dwHighDateTime = 0;
ftExitTime.dwLowDateTime = 0;
memset(&si, 0, sizeof(si));
si.cb = sizeof(STARTUPINFO);
if (CreateProcess(NULL, pChar, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
{
WaitForSingleObject(pi.hProcess, INFINITE);
GetProcessTimes(pi.hProcess, &ftCreationTime, &ftExitTime, &ftKernelTime, &ftUserTime);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
ll = *((long long*)&ftExitTime) - *((long long*)&ftCreationTime);
FileTimeToSystemTime(((FILETIME*)&ll), &stTime);
nLen = wsprintf(szTmp, "%d.%ds\n", stTime.wSecond, stTime.wMilliseconds);
//printf("%d.%ds %lld\n", stTime.wSecond, stTime.wMilliseconds, ll);
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), szTmp, nLen, &nWrite, NULL);
} //else printf("error\n");
return 0;
}
May the source be with you

jj2007

Thanks, Timo - I never heard of GetProcessTime :thumbsup:

At SOF, some people complain that the resolution is 15.x ms, like GetTickCount(). My tool uses NanoTimer(), which is precise, but I guess it hardly matters for timing an assembler or compiler. The results look like this (I guess 1.26s means 1260ms):

with timeit:

*** 1030 ms for SleepOneSecond.exe ***

with Timo's tool:
0:1.26s


From my tests it seems that your tool is 2ms "faster" for very short processes, and 2-20 ms slower for processes that take more than 2 seconds.

TimoVJL

Quote from: jj2007 on December 11, 2020, 10:33:27 PM
Thanks, Timo - I never heard of GetProcessTime :thumbsup:

At SOF, some people complain that the resolution is 15.x ms, like GetTickCount(). My tool uses NanoTimer(), which is precise, but I guess it hardly matters for timing an assembler or compiler. The results look like this (I guess 1.26s means 1260ms):
...
nLen = wsprintf(szTmp, "%d:%d.%ds\n", stTime.wMinute, stTime.wSecond, stTime.wMilliseconds);
May the source be with you