McCode icon indicating copy to clipboard operation
McCode copied to clipboard

Profile the code execution to find bottlenecks

Open farhi opened this issue 8 months ago • 0 comments

A profiling of the code should be performed with e.g. gprof and gcov.

The procedure is the following. Then look at ways to either reduce the number of calls, or simplify the code where calculations are done (e.g. remove sqrt etc)..

profiling per function (gprof)

mxrun --write-user-config
# add -pg to ~/.mcxtrace/3.3-20231220/mccode_config.json CFLAGS
mxrun -c Test_SX.instr -n0
mxrun Test_SX.instr TTH=13
gprof Test_SX.out gmon.out > gprof.txt
gedit gprof.txt

profiling per line (gcov = nb of calls)

mxrun --write-user-config
# add -fprofile-arcs -ftest-coverage to /home/farhi/.mcxtrace/3.3-20231220/mccode_config.json CFLAGS
./Test_SX.out -n 1e7  TTH=13
mv Test_SX.out-Test_SX.gcda Test_SX.gcda
mv Test_SX.out-Test_SX.gcno Test_SX.gcno
gcov Test_SX.c
geany Test_SX.c.gcov

farhi avatar Dec 20 '23 12:12 farhi