slow performance with one of the reasons in huge amount of malloc/free and strlen
The simple program from #4 (closed) has a huge amount of calls to malloc+free (> 12 000 000 times) directly in the main function _11_dice_roller4
.
Furthermore its most expensive call is to __gg__initialize_variable
(called > 5 000 000 times) which seems to execute strlen
2 times in each call.
Suggestion (in order):
- check if
__gg__initialize_variable
needs an strlen at all (I guess not, all lengths for initialization may be known at compile time, no?) - check if
__gg__initialize_variable
needs to be called that often, possibly a temporary variable may be re-used? - reduce those many malloc+free calls in the generated ENTRY; possibly those can be replaced by function-local variables/arrays?
If those are solved I see chances for the program to execute much less instructions until its end than the GnuCOBOL generated version, and possibly a similar amount when FUNCTION RANDOM
actually does something (note: GnuCOBOL switched to the portable random function of GMP in GnuCOBOL 3.2, because rand
was too limited on 32bit and did not have the necessary quality [equal distribution] needed on all systems).