|
On Wed, 9 Oct 2002, Steve Richter wrote:
>
> Its just a hunch of mine. C relies on null term strings so I am speculating
> that ILE handles them efficiently.
>
Okay, I wrote & ran some benchmarks on these things. To my surprise, both
fixed-length and null-terminated strings performed SIGNIFICANTLY better
than varying. About twice as fast! I hope Hans or Barbara can explain
why...
This was done on my company's iSeries, 9406-270(2248) at V4R5.
I was the only person online / only job running.
I did not enable any special optimization for either compiler.
All the strings I passed were 32000 bytes long.
Here's the results:
Description Iters per Second
-------------------------------- -----------------
ILE RPG fixed-len by value 4167
ILE RPG fixed-len by reference 416667
ILE RPG null-terminated by value 4167
ILE RPG null-terminated by reference 416667
ILE RPG varying by value 2083
ILE RPG varying by reference 217391
ILE C null-terminated by value 8333
ILE C null-terminated by reference 1666666
Here are the programs that I used to perform the test. Note that I
assigned a 'x' to the first byte in each string in each function just
to make sure the compiler didn't "remove" the routine during some sort
of optimization.
H DFTACTGRP(*NO) ACTGRP(*NEW)
D by_value PR
D data 32000A value
D by_reference PR
D data 32000A
D v_by_value PR
D data 32000A value varying
D v_by_reference PR
D data 32000A varying
D n_by_value PR
D data 32000A value
D n_by_reference PR
D data 32000A
D data S 32000A
D data2 S 32000A varying
D start S Z
D end S Z
D diff S 10I 0
D msg S 50A
D x S 10I 0
c eval data = 'This is not a null-terminated '+
c 'string.'
c eval data2= 'This is not a null-terminated '+
c 'string.'
c time start
c for x = 1 to 50000
c callp by_value(data)
c endfor
c time end
c end subdur start diff:*seconds
c eval msg = 'by-value ' + %editc(diff:'Z')
c msg dsply
c time start
c for x = 1 to 5000000
c callp by_reference(data)
c endfor
c time end
c end subdur start diff:*seconds
c eval msg = 'by-ref ' + %editc(diff:'Z')
c msg dsply
c time start
c for x = 1 to 50000
c callp v_by_value(data2)
c endfor
c time end
c end subdur start diff:*seconds
c eval msg = 'v-by-value ' + %editc(diff:'Z')
c msg dsply
c time start
c for x = 1 to 5000000
c callp v_by_reference(data2)
c endfor
c time end
c end subdur start diff:*seconds
c eval msg = 'v-by-ref ' + %editc(diff:'Z')
c dsply msg
c eval data = 'This is now a null-terminated '+
c 'string.' + X'00'
c time start
c for x = 1 to 50000
c callp n_by_value(data)
c endfor
c time end
c end subdur start diff:*seconds
c eval msg = 'n-by-value ' + %editc(diff:'Z')
c msg dsply
c time start
c for x = 1 to 5000000
c callp n_by_reference(data)
c endfor
c time end
c end subdur start diff:*seconds
c eval msg = 'n-by-ref ' + %editc(diff:'Z')
c dsply msg
c eval *inlr = *on
P by_value B
D by_value PI
D data 32000A value
c eval %subst(data:1:1) = 'x'
P E
P by_reference B
D by_reference PI
D data 32000A
c eval %subst(data:1:1) = 'x'
P E
P v_by_value B
D v_by_value PI
D data 32000A value varying
c eval %subst(data:1:1) = 'x'
P E
P v_by_reference B
D v_by_reference PI
D data 32000A varying
c eval %subst(data:1:1) = 'x'
P E
P n_by_value B
D n_by_value PI
D data 32000A value
c eval %subst(data:1:1) = 'x'
P E
P n_by_reference B
D n_by_reference PI
D data 32000A
c eval %subst(data:1:1) = 'x'
P E
#include <stdio.h>
#include <string.h>
#include <time.h>
struct my_data {
char string[32000];
};
void by_value(struct my_data d);
void by_reference(char *str);
int main(void) {
struct my_data dta;
time_t start, end;
int x;
strcpy(dta.string, "This is now a null-terminated string.");
time(&start);
for (x=0; x<50000; x++)
by_value(dta);
time(&end);
printf("By-value total time %f seconds\n", difftime(end,start));
time(&start);
for (x=0; x<5000000; x++)
by_reference(dta.string);
time(&end);
printf("By-reference total time %f seconds\n",
difftime(end,start));
return 0;
}
void by_value(struct my_data d) {
d.string[0] = 'x';
}
void by_reference(char *str) {
str[0] = 'x';
}
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.