如何在 CL 中调用程序 100 次?

How can I call a program 100 times in a CL?

我想在 CL 中调用一个程序 100 次,以测量不同程序设置下的调用时间。

也许是这样的?

DOFOR      VAR(&INT) FROM(0) TO(99)
CALL       PGM(TProg) PARM(&Parm)
ENDDO    

当然可以。您将如何衡量绩效?

当我做这种测试时,我将迭代次数作为参数传入。

您应该有足够的迭代,以便使用最快设置的调用至少需要半分钟,以帮助取消额外的工作,例如获取时间戳。将迭代次数作为参数可以更容易地做到这一点。

要在 CL 中获取时间戳,可以使用 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 

时间戳不是很可读(20180203143253529956,意思是 2018-02-03-14.32.53.529956)。您可能想要做一些子字符串化以使其更具可读性,或者甚至进行一些计算以获得两个时间戳之间的秒数。

更新以回答有关如何子串的问题:

我,我会写一个 RPG 程序来获取两个时间戳之间的差异。

**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;

如果您不想或不能使用 RPG,那么您可以按照以下方法在 CL 中使用子字符串和串联来生成更具可读性的时间戳。

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