The MASM Forum

General => The Campus => Topic started by: Lonewolff on March 16, 2016, 02:03:32 PM

Title: Profiling question
Post by: Lonewolff on March 16, 2016, 02:03:32 PM
Hi Guys,

Is there any way to profile the output exe to show how many clock cycles were consumed?

Thanks in advance :)
Title: Re: Profiling question
Post by: jj2007 on March 16, 2016, 02:49:26 PM
There are several well-tested ways, see The Laboratory.
If you are only interested in relative comparisons between algos, measuring milliseconds is usually precise enough. Simple example:
include \masm32\MasmBasic\MasmBasic.inc
.data
somestring db "Hello, this is a simple string intended for testing string algos. It has 100 characters without zero", 0

  Init
  NanoTimer()
  LoopCount=20000000
  mov ebx, LoopCount
  .Repeat
invoke crt_strlen, offset somestring
dec ebx
  .Until Sign?
  Print Str$("crt_strlen took %i ms\n", NanoTimer(ms))

  NanoTimer()
  mov ebx, LoopCount
  .Repeat
void len(offset somestring)
dec ebx
  .Until Sign?
  Print Str$("Masm32 len() took %i ms\n", NanoTimer(ms))

  NanoTimer()
  mov ebx, LoopCount
  .Repeat
void Len(offset somestring)
dec ebx
  .Until Sign?
  Inkey Str$("MasmBasic Len() took %i ms\n", NanoTimer(ms))

EndOfCode


Output:
crt_strlen took 715 ms
Masm32 len() took 872 ms
MasmBasic Len() took 233 ms


NanoTimer() needs the MasmBasic library (http://masm32.com/board/index.php?topic=94.0), with a 100 nanosecs resolution. You can use GetTickCount instead, but note that its resolution is only around 16 ms.
Title: Re: Profiling question
Post by: Lonewolff on March 16, 2016, 03:03:33 PM
Nice jj2007. Thanks heaps.

It's great getting back in to MASM, really makes you think hard about every little thing you do. I have made quite a bit of progress learning (and re-learning) this today. :)