I want to call a program in a CL for 100 times to measure up the call times with different program settings.
Maybe something like this?
DOFOR VAR(&INT) FROM(0) TO(99)
CALL PGM(TProg) PARM(&Parm)
ENDDO
When I do this kind of testing, I pass in the number of iterations as a parameter.
You should have enough iterations so that the call with the quickest settings takes at least half a minute, to help cancel out the extra work like getting the timestamps. Having the number of iterations be a parameter makes it easier to do this.
To get a timestamp in CL, you can use RTVSYSVAL QDATETIME.
dcl &before type(*char) len(20)
dcl &after type(*char) len(20)
rtvsysval QDATETIME rtnvar(&before)
--- do the loop
rtvsysval QDATETIME rtnvar(&after)
sndpgmmsg &before
sndpgmmsg &after
The timestamps aren't very readable (20180203143253529956 which means 2018-02-03-14.32.53.529956). You might want to do some substringing to make them more readable, or even do some calculations to get the number of seconds between the two timestamps.
Update to answer the question about how to substring:
Me, I would just write an RPG program to get the difference between the two timestamps.
**free
dcl-pi *n;
t1 char(20) const;
t2 char(20) const;
diffSeconds packed(7:2);
end-pi;
dcl-s ts1 timestamp;
dcl-s ts2 timestamp;
ts1 = %timestamp(t1 : *iso0);
ts2 = %timestamp(t2 : *iso0);
diffSeconds = %diff (ts1 : ts2 : *seconds : 2);
return;
If you don't want to use RPG, or you cannot, then here's how you could use substring and concatenation in CL to produce a more readable timestamp.
dcl &prtBefore type(*char) len(26)
chgvar &prtBefore (%sst(&before 1 4) *tcat '-' *tcat +
%sst(&before 5 2) *tcat '-' *tcat +
%sst(&before 7 2) *tcat '-' *tcat +
%sst(&before 9 2) *tcat '.' *tcat +
%sst(&before 11 2) *tcat '.' *tcat +
%sst(&before 13 2) *tcat '.' *tcat +
%sst(&before 15 6))
sndpgmmsg &prtBefore