Profiling your code with a macro

Share your advanced PureBasic knowledge/code with the community.
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Profiling your code with a macro

Post by uwekel »

Hi,

here is a macro i wrote today to count the number of execution per second. I put the macro into a resident file to have it available all the time. Just call it with your code, e.g. the name of a procedure, like

Code: Select all

Profile(MyTestProc())
Here is the macro code:

Code: Select all

Macro Profile(Code)
  ;run test code and count number of calls within a second
  Define profile_count = 0
  Define profile_start = ElapsedMilliseconds()
  Repeat
    Code
    profile_count + 1
  Until ElapsedMilliseconds() - profile_start > 1000
  ;show result
  CompilerIf #PB_Compiler_Debugger
    Debug profile_count
  CompilerElse
    MessageRequester("Profile", Str(profile_count))
  CompilerEndIf
EndMacro
Btw, does anyone know how to get code completion working from resident files?

Best regards
Uwe
Last edited by uwekel on Thu May 30, 2013 9:20 pm, edited 1 time in total.
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Profiling your code with a macro

Post by luis »

uwekel wrote: Btw, does anyone now how to get code completion working from resident files?
For Macros ? Sadly no.

http://www.purebasic.fr/english/viewtop ... 34#p370834
"Have you tried turning it off and on again ?"
Post Reply