Recent

Author Topic: [Solved]calculating code efficiency  (Read 416 times)

Ten_Mile_Hike

  • Jr. Member
  • **
  • Posts: 95
[Solved]calculating code efficiency
« on: February 04, 2025, 10:04:08 pm »
It is a trivial task to determine the time it takes to execute a command, an entire subprogram, or an entire program. In Lazarus how would I "easily" determine the number of CPU operations, heap,  stack & memory bus transfers that a particular code segment produces as well as the time intervals of the same?

I am aware that the above tasks are sometimes accomplished by a "profiler" program. Is there a "free $$" and robust profiler for Lazarus/FPC that any of you use?

TIA

P.S. I'm writing this in a dark coffeeshop on my cell
        without my reading glasses; I therefore disavow
        all spelling and formatting errors :D
« Last Edit: February 05, 2025, 02:47:04 am by Ten_Mile_Hike »
When any government, or any church for that matter, undertakes to say to its subjects, This you may not read, this you
must not see, this you are forbidden to know, the end result is tyranny and oppression no matter how holy the motives.

Robert A. Heinlein

Paolo

  • Hero Member
  • *****
  • Posts: 556
Re: calculating code efficiency
« Reply #1 on: February 04, 2025, 10:36:49 pm »
Quote
It is a trivial task to determine the time...

Really ?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10837
  • Debugger - SynEdit - and more
    • wiki
Re: calculating code efficiency
« Reply #2 on: February 04, 2025, 10:39:13 pm »
I don't know if you can get all the details from this, but you could look at cachegrind and callgrind (both part of valgrind), combined with kcachegrid as result viewer. There is also a heap analyser but I never looked at it yet.

They do require Linux. So only if your app can be compiled for Linux.

Ten_Mile_Hike

  • Jr. Member
  • **
  • Posts: 95
Re: calculating code efficiency
« Reply #3 on: February 05, 2025, 02:42:42 am »
Quote
It is a trivial task to determine the time...

Really ?
Code: Text  [Select][+][-]
  1. Yes; crude and not rigorous, but fine for casual evaluation of code changes to ensure no sudden bottlenecks
  2.  
  3. {Unit Dateutils}
  4. Athen:=now;
  5. For x:=1 to 1000 Do BusyFunction(x);
  6. Interval:= MilliSecondsBetween(Now, AThen: Double);
When any government, or any church for that matter, undertakes to say to its subjects, This you may not read, this you
must not see, this you are forbidden to know, the end result is tyranny and oppression no matter how holy the motives.

Robert A. Heinlein

Ten_Mile_Hike

  • Jr. Member
  • **
  • Posts: 95
Re: calculating code efficiency
« Reply #4 on: February 05, 2025, 02:45:22 am »
I don't know if you can get all the details from this, but you could look at cachegrind and callgrind (both part of valgrind), combined with kcachegrid as result viewer. There is also a heap analyser but I never looked at it yet.

They do require Linux. So only if your app can be compiled for Linux.
Code: Text  [Select][+][-]
  1. Thank you Martin
When any government, or any church for that matter, undertakes to say to its subjects, This you may not read, this you
must not see, this you are forbidden to know, the end result is tyranny and oppression no matter how holy the motives.

Robert A. Heinlein

 

TinyPortal © 2005-2018