POV-Ray : Newsgroups : povray.text.scene-files : counting macro calls Server Time
5 Jul 2022 06:20:52 EDT (-0400)
  counting macro calls (Message 1 to 2 of 2)  
From: jr
Subject: counting macro calls
Date: 2 Jun 2022 09:40:00
Message: <web.6298bc5be3f90d8f879e196a6cde94f1@news.povray.org>
hi,

attached is a small include to provide a "total macro calls" count, for
specified macros.

usage is v simple.  after "instrumenting" the macro(s) of interest, in the
scene, write:

  #include "tmc.inc"
  #declare tmc_ = tmc_new();
    ...
  tmc_report(tmc_)

the 'incr' macro is shown as an example of using 'tmc_add()', which does the
counting:

  #macro _incr(v_,optional n_)
    tmc_add(global.tmc_,"incr")
    #if (!defined(local.n_))
      #local n_ = 1;
    #end
    #local v_ = v_ + n_;
  #end

add a call to 'tmc_add()' to every macro of interest, and that's it.  the
'global' is not needed, but hey..  the following output is clipped from a puzzle
solver I'm playing with, from two different runs:

exiting solver, after 7th pass:
  #hexas completed - 16
  #slots completed - 27
  puzzle '211126' solved.
-----[tmc]--------------------------------------------------------------
          48 : setDigit
        1042 : incr
          16 : need2proc
          21 : copySets
         120 : isAvailable
          10 : need3proc
         336 : singleton
           5 : need1proc
  ---------- : ----------
        1598 : 8
------------------------------------------------------------------------

exiting solver, after 6th pass:
  #hexas completed - 16
  #slots completed - 25
  puzzle '220531' solved.
-----[tmc]--------------------------------------------------------------
          48 : setDigit
         905 : incr
          19 : need2proc
          19 : copySets
          88 : isAvailable
           8 : need3proc
         288 : singleton
           7 : need1proc
  ---------- : ----------
        1382 : 8
------------------------------------------------------------------------

perhaps I ought to sort the output by name :-), suggestions/feedback welcome.
in case there's interest,
I'll post the image for the '220531' puzzle in p.b.i.


enjoy, jr.


Post a reply to this message


Attachments:
Download 'tmc.inc.txt' (3 KB)

From: jr
Subject: Re: counting macro calls
Date: 11 Jun 2022 04:50:00
Message: <web.62a455f172d259902119a36b6cde94f1@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
> attached is a small include to provide a "total macro calls" count, for
> specified macros.

posting a cleaned-up version, the macros were renamed in camelCase to fit with
other includes.  in case it ("the obvious") needs saying - counters can also be
used outside of macros, for instance per-case in a '#switch', or per-branch in
some '#if ... #end'.


enjoy, jr.


Post a reply to this message


Attachments:
Download 'tmc.inc.txt' (3 KB)

Copyright 2003-2021 Persistence of Vision Raytracer Pty. Ltd.