Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find out what part of my code is slowing my c++ program

I wrote 2 versions of my program, wich is an evolutionary algorithm in c++. The first version is procedural and works fine and very fast. The second version is completely OOP, and the program finds results, but is very very slow (like 10 times slower than the 1st version). Is there a way to maybe measure time of segments of code inside loops or something like that? Any advice or idea would help. Thanks in advance.

like image 466
Pablo Acuña Avatar asked Dec 04 '25 23:12

Pablo Acuña


2 Answers

Use a profiler. Which one is best depends on the platform/operating environment; e.g. with g++ you can use gprof, or if you don't want to recompile you can use oprofile, assuming Linux. On Solaris you could use dtrace. On other platforms, such as Windows or Mac, add the tag for your platform to the question...

like image 53
barefootliam Avatar answered Dec 07 '25 13:12

barefootliam


You need a profiler to find performance related issues in your program.

Depending on the Visual Studio edition, you have various levels of profiling support in your Visual Studio. If you're lucky enough to be at the Visual Studio Ultimate or Premium edition, you have very good profiling support built right in.

If you're on Visual Studio Express or Visual Studio Professional, there is sadly no profiling support built into Visual Studio, but you can use for example info at this link how to do it manually for free with those editions anyway.

like image 45
Joachim Isaksson Avatar answered Dec 07 '25 15:12

Joachim Isaksson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!