Parameter passing benchmark test
Contents
The Test
This test program is designed to benchmark the passing of large character data to a subprocedure. To call this program simply call it from a command line. The program will perform each check and print out the average call times per 100 calls for each check. There are 2 optional parameters. The first parameter will instruct the program to perform that number of calls for each test. The second parameter will instruct the program to print the call time as the average time taken to perform that number of calls. The default for the two parameters is 10,000 and 100. That is, the program will call each subprocedure 10,000 times and give the average time taken to call each subprocedure 100 times.
The results will be displayed on the terminal.
Original discussion thread from RPG400-L can be found at http://archive.midrange.com/rpg400-l/200710/msg00724.html
Subject: Is const really that much better than value? From: "Larry Ducie" <Larry_Ducie@xxxxxxxxxxx> Date: Tue, 30 Oct 2007 22:16:37 +1000
The code
H dftactgrp(*no) bnddir('QC2LE') option(*srcstmt)
d valueconst pr extpgm('VALUECONST')
d p_ntimes 15p 5 const
d p_percall 15p 5 const
d valueconst pi
d p_ntimes 15p 5 const
d p_percall 15p 5 const
d byvalue pr
d bigparm 65535a varying value
d byconst pr
d bigparm 65535a varying const
d byvalueC pr
d bigparm 65535a value
d byconstC pr
d bigparm 65535a const
d byvalue2 pr
d bigparm 32768a varying value
d byconst2 pr
d bigparm 32768a varying const
d byvalueC2 pr
d bigparm 32768a value
d byconstC2 pr
d bigparm 32768a const
d printf pr extproc('printf')
d * value options(*string)
d getchar pr 10i 0 extproc('getchar')
d ntimes s 10i 0 inz(10000)
d percall s 10i 0 inz(100)
d group s 10i 0 inz(0)
d startTime s z
d endTime s z
d t1 s 10i 0
d t2 s 10i 0
d msg s 52a
d i s 10i 0
d crlf c const(X'0d25')
d char100 s 100a varying inz(*all'X')
d char1000 s 1000a varying inz(*all'X')
d char32768 s 32768a varying inz(*all'X')
d char65535 s 65535a varying inz(*all'X')
d varyingField s 65535a varying
d varying2Field s 32768a varying
d charField s 65535a
d char2Field s 32768a
/free
// Override number of calls to make to each function...
if %parms >= 1;
ntimes = p_ntimes;
endif;
// Override number of calls to group over...
if %parms >= 2;
percall = p_percall;
endif;
group = ntimes/percall;
printf('----------------------------------------------' + crlf);
printf('--- ---' + crlf);
printf('--- Starting test ---' + crlf);
printf('--- ---' + crlf);
printf('----------------------------------------------' + crlf);
printf('' + crlf);
printf('Testing with ' + %char(ntimes) + ' func calls ' + crlf);
printf('Times given per ' + %char(percall) + ' calls' + crlf);
printf('' + crlf);
printf('++++++++++++++++++++++++++++++++++++++++++++++' + crlf);
printf('Testing passing a 1a literal to 65535a parm' + crlf);
printf('++++++++++++++++++++++++++++++++++++++++++++++' + crlf);
printf('' + crlf);
printf('----------------------------------------------' + crlf);
printf('Varying when passing a 1a literal' + crlf);
printf('----------------------------------------------' + crlf);
printf('' + crlf);
// For VARYING...
startTime = %timestamp();
for i = 1 to ntimes;
byvalue ('a');
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconst ('a');
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing the literal _a_ for 65535a varying...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
printf('' + crlf);
printf('----------------------------------------------' + crlf);
printf('Varying where variable length is 65535' + crlf);
printf('----------------------------------------------' + crlf);
printf('' + crlf);
varyingField = char100;
startTime = %timestamp();
for i = 1 to ntimes;
byvalue (varyingField);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconst (varyingField);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 65535a varying with 100a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
varyingField = char1000;
startTime = %timestamp();
for i = 1 to ntimes;
byvalue (varyingField);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconst (varyingField);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 65535a varying with 1000a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
varyingField = char65535;
startTime = %timestamp();
for i = 1 to ntimes;
byvalue (varyingField);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconst (varyingField);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 65535a varying with 65535a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
printf('' + crlf);
printf('----------------------------------------------' + crlf);
printf('Fixed-length when passing a 1a literal' + crlf);
printf('----------------------------------------------' + crlf);
printf('' + crlf);
// For CHAR...
startTime = %timestamp();
for i = 1 to ntimes;
byvalueC ('a');
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconstC ('a');
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing the literal _a_ for 65535a...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
printf('' + crlf);
printf('----------------------------------------------' + crlf);
printf('Fixed-length where variable length is 65535...' + crlf);
printf('----------------------------------------------' + crlf);
printf('' + crlf);
charField = char100;
startTime = %timestamp();
for i = 1 to ntimes;
byvalueC (charField);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconstC (charField);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 65535a with 100a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
charField = char1000;
startTime = %timestamp();
for i = 1 to ntimes;
byvalueC (charField);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconstC (charField);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 65535a with 1000a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
charField = char65535;
startTime = %timestamp();
for i = 1 to ntimes;
byvalueC (charField);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconstC (charField);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 65535a with 65535a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
printf('' + crlf);
printf('++++++++++++++++++++++++++++++++++++++++++++++' + crlf);
printf('Testing passing 32768a variables to 65535 parm ' + crlf);
printf('++++++++++++++++++++++++++++++++++++++++++++++' + crlf);
printf('' + crlf);
printf('----------------------------------------------' + crlf);
printf('Varying where variable length is 32768...' + crlf);
printf('----------------------------------------------' + crlf);
printf('' + crlf);
varying2Field = char100;
startTime = %timestamp();
for i = 1 to ntimes;
byvalue (varying2Field);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconst (varying2Field);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 32768a varying with 100a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
varying2Field = char1000;
startTime = %timestamp();
for i = 1 to ntimes;
byvalue (varying2Field);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconst (varying2Field);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 32768a varying with 1000a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
varying2Field = char32768;
startTime = %timestamp();
for i = 1 to ntimes;
byvalue (varying2Field);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconst (varying2Field);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 32768a varying with 32768a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
printf('' + crlf);
printf('----------------------------------------------' + crlf);
printf('Fixed-length where variable length is 32768a...' + crlf);
printf('----------------------------------------------' + crlf);
printf('' + crlf);
char2Field = char100;
startTime = %timestamp();
for i = 1 to ntimes;
byvalueC (char2Field);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconstC (char2Field);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 32768a with 100a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
char2Field = char1000;
startTime = %timestamp();
for i = 1 to ntimes;
byvalueC (char2Field);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconstC (char2Field);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 32768a with 1000a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
char2Field = char32768;
startTime = %timestamp();
for i = 1 to ntimes;
byvalueC (char2Field);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconstC (char2Field);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 32768a with 32768a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
printf('' + crlf);
printf('++++++++++++++++++++++++++++++++++++++++++++++' + crlf);
printf('Testing passing 65535a variables to 32768 parm' + crlf);
printf('++++++++++++++++++++++++++++++++++++++++++++++' + crlf);
printf('' + crlf);
printf('----------------------------------------------' + crlf);
printf('Varying where variable length is 65535' + crlf);
printf('----------------------------------------------' + crlf);
printf('' + crlf);
varyingField = char100;
startTime = %timestamp();
for i = 1 to ntimes;
byvalue2 (varyingField);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconst2 (varyingField);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 65535a varying with 100a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
varyingField = char1000;
startTime = %timestamp();
for i = 1 to ntimes;
byvalue2 (varyingField);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconst2 (varyingField);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 65535a varying with 1000a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
varyingField = char65535;
startTime = %timestamp();
for i = 1 to ntimes;
byvalue2 (varyingField);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconst2 (varyingField);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 65535a varying with 65535a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
printf('' + crlf);
printf('----------------------------------------------' + crlf);
printf('Fixed-length where variable length is 65535...' + crlf);
printf('----------------------------------------------' + crlf);
printf('' + crlf);
charField = char100;
startTime = %timestamp();
for i = 1 to ntimes;
byvalueC2 (charField);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconstC2 (charField);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 65535a with 100a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
charField = char1000;
startTime = %timestamp();
for i = 1 to ntimes;
byvalueC2 (charField);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconstC2 (charField);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 65535a with 1000a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
charField = char65535;
startTime = %timestamp();
for i = 1 to ntimes;
byvalueC2 (charField);
endfor;
endTime = %timestamp();
t1 = (%diff(endTime : startTime : *ms)/group);
startTime = %timestamp();
for i = 1 to ntimes;
byconstC2 (charField);
endfor;
endTime = %timestamp();
t2 = (%diff(endTime : startTime : *ms)/group);
printf('Passing a 65535a with 65535a filled...' + crlf);
printf('value: ' + %editc(t1 : 'P') + ' ms | '
+ 'const: ' + %editc(t2 : 'P') + ' ms' + crlf);
printf('' + crlf);
printf('----------------------------------------------' + crlf);
printf('Test ended - press ENTER to close window...' + crlf);
printf('----------------------------------------------' + crlf);
// Read 1 char from the keyboard - to force display of screen...
i = getchar();
*inlr = *on;
/end-free
P byvalue b
D byValue pi
D bigParm 65535a varying value
P byValue e
P byConst b
D byConst pi
D bigParm 65535a varying const
P byConst e
P byvalueC b
D byValueC pi
D bigParm 65535a value
P byValueC e
P byConstC b
D byConstC pi
D bigParm 65535a const
P byConstC e
P byvalue2 b
D byValue2 pi
D bigParm 32768a varying value
P byValue2 e
P byConst2 b
D byConst2 pi
D bigParm 32768a varying const
P byConst2 e
P byvalueC2 b
D byValueC2 pi
D bigParm 32768a value
P byValueC2 e
P byConstC2 b
D byConstC2 pi
D bigParm 32768a const
P byConstC2 e
Results
The results so far are:
(If you wish to include the timings for your machine it is recommended that you call the program with no parameters. This will ensure all benchmark tests will be easily compared (10,000 calls per subprocedure, and time per 100 calls printed)
V5R2 Model 170-2290
Times per 1 call Passing the literal _a_ for 65535a varying... value: 3339 ms | const: 24 ms Passing a 65535a varying with 100a filled... value: 3314 ms | const: 21 ms Passing a 65535a varying with 1000a filled... value: 3367 ms | const: 21 ms Passing a 65535a varying with 65535a filled... value: 4572 ms | const: 21 ms Passing the literal _a_ for 65535a... value: 4579 ms | const: 1087 ms Passing a 65535a with 100a filled... value: 2483 ms | const: 21 ms Passing a 65535a with 1000a filled... value: 2844 ms | const: 23 ms Passing a 65535a with 65535a filled... value: 2503 ms | const: 22 ms
V5R2 Model 270
Times per 100 calls Passing the literal _a_ for 65535a varying... value: 152460 ms | const: 470 ms Passing a 65535a varying with 100a filled... value: 145350 ms | const: 440 ms Passing a 65535a varying with 1000a filled... value: 149180 ms | const: 340 ms Passing a 65535a varying with 65535a filled.. value: 224750 ms | const: 330 ms Passing the literal _a_ for 65535a... value: 188500 ms | const: 33620 ms Passing a 65535a with 100a filled... value: 96280 ms | const: 310 ms Passing a 65535a with 1000a filled... value: 96270 ms | const: 310 ms Passing a 65535a with 65535a filled... value: 96370 ms | const: 310 ms
V5R2 Model SB1-2313
Times per 1 call Passing the literal _a_ for 65535a varying... value: 318 ms | const: 2 ms Passing a 65535a varying with 100a filled... value: 301 ms | const: 1 ms Passing a 65535a varying with 1000a filled... value: 339 ms | const: 1 ms Passing a 65535a varying with 65535a filled... value: 439 ms | const: 1 ms Passing the literal _a_ for 65535a... value: 570 ms | const: 95 ms Passing a 65535a with 100a filled... value: 246 ms | const: 1 ms Passing a 65535a with 1000a filled... value: 276 ms | const: 1 ms Passing a 65535a with 65535a filled... value: 246 ms | const: 1 ms
V5R3 Model 520-7453
Testing with total 10000 calls Times given per 100 calls Passing the literal _a_ for 65535a varying... value: 5270 ms | const: 20 ms Passing a 65535a varying with 100a filled... value: 5600 ms | const: 90 ms Passing a 65535a varying with 1000a filled... value: 5360 ms | const: 10 ms Passing a 65535a varying with 65535a filled... value: 7760 ms | const: 20 ms Passing the literal _a_ for 65535a... value: 8120 ms | const: 1940 ms Passing a 65535a with 100a filled... value: 5130 ms | const: 10 ms Passing a 65535a with 1000a filled... value: 5140 ms | const: 20 ms Passing a 65535a with 65535a filled... value: 5070 ms | const: 20 ms
V5R3 Model 810-7409
Testing with total 10000 calls Times given per 100 calls Passing the literal _a_ for 65535a varying... value: 24510 ms | const: 40 ms Passing a 65535a varying with 100a filled... value: 24900 ms | const: 40 ms Passing a 65535a varying with 1000a filled... value: 23830 ms | const: 60 ms Passing a 65535a varying with 65535a filled... value: 33800 ms | const: 40 ms Passing the literal _a_ for 65535a... value: 40760 ms | const: 4760 ms Passing a 65535a with 100a filled... value: 17030 ms | const: 40 ms Passing a 65535a with 1000a filled... value: 17360 ms | const: 30 ms Passing a 65535a with 65535a filled... value: 15920 ms | const: 40 ms
V5R3 Model 890
Times per 1 call Passing the literal _a_ for 65535a varying... value: 120 ms | const: 0 ms Passing a 65535a varying with 100a filled... value: 60 ms | const: 0 ms Passing a 65535a varying with 1000a filled... value: 50 ms | const: 0 ms Passing a 65535a varying with 65535a filled... value: 90 ms | const: 0 ms Passing the literal _a_ for 65535a... value: 180 ms | const: 30 ms Passing a 65535a with 100a filled... value: 60 ms | const: 0 ms Passing a 65535a with 1000a filled... value: 60 ms | const: 0 ms Passing a 65535a with 65535a filled... value: 60 ms | const: 0 ms
V5R4 Model 520
Times per 1 call Passing the literal _a_ for 65535a varying... value: 133 ms | const: 6 ms Passing a 65535a varying with 100a filled... value: 150 ms | const: 1 ms Passing a 65535a varying with 1000a filled... value: 131 ms | const: 6 ms Passing a 65535a varying with 65535a filled.. value: 201 ms | const: 1 ms Passing the literal _a_ for 65535a... value: 207 ms | const: 41 ms Passing a 65535a with 100a filled... value: 127 ms | const: 1 ms Passing a 65535a with 1000a filled... value: 122 ms | const: 7 ms Passing a 65535a with 65535a filled... value: 120 ms | const: 1 ms