Is there a way to test performance of code and it functions for optimization purposes ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Inces

What I am thinking of is :

I am currently trying to code efficient pathfinding system, and as I am changing mathematical operations, trying out various loops and approaches - all I can measure are framedrop and small freezes. I wish to know how much each line of code is contributing to this freeze, so I could optimize it better. Instead I have to rely on subjective duration of freeze.

I remove one needless boolean condition - freeze is slightly smaller. Or is it ? Was it in my head ? Should I try to search in arrays instead of in dictionaries ? Freeze seems to be shorter on arrays… or is it…? You know what I mean :slight_smile:

Did anyone come up with a way to objectively test optimization of code ? Or better - of single lines of code ??

Hey everyone! I totally relate to the struggle of optimizing code and trying to measure its performance objectively. It can be incredibly frustrating when all we have to rely on our subjective observations like frame drops and freezes. I’ve been there, constantly questioning whether a small change actually made a difference or if it was just in my head.

One approach that has helped me is using profiling tools. These tools analyze the execution of your code and provide detailed information about the time spent in each function or line of code. By using a profiler, you can pinpoint exactly which parts of your code are causing the freezes and framedrops, and focus your optimization efforts there.

There are several great profiling tools available for different programming languages, such as cProfile for Python or Instruments for iOS development. These tools can give you valuable insights into the performance of your code and help you make informed decisions about optimization.

Another helpful technique is benchmarking. By creating specific test cases and measuring the execution time of different approaches or lines of code, you can compare their performance objectively. This way, you can identify the most time-consuming parts and prioritize your optimization efforts accordingly.

angelacow | 2023-06-12 13:58

:bust_in_silhouette: Reply From: IceExplosive

Profiler is included within Godot.

Start the scene, then at the very bottom of the editor select ‘Debugger’ tab, under which will be ‘Profiler’ tab. You’ll see how much time functions takes.

Also read this:

Wow thanks, it is much more than I could imagine :slight_smile:
I have been programming for some time, but it was all turn-based games before, never had to dig in into optimizing process() :slight_smile:

Inces | 2021-07-13 14:44

1 Like