ionAs far as I know, it uses the same underlying processing. The only real
difference is that SCAN can output to an array, whereas %scan can't
(although if run in a loop, it can do the same thing).
That all being said, it *can* be possible to make some performance
improvements to scan processing (using a combination of memcmp and memchr
instead of the RPG BIF) *under some circumstances* - dependent on a few
factors, such as the likelihood that the scanned-for string will be found
and whether the first character in the scanned-for string is likely to be
found frequently in situations where it's not part of the scanned-for
string.
RPG/400 used the SCAN MI instruction (
http://publib.boulder.ibm.com/iseries/v5r1/ic2924/tstudio/tech_ref/mi/SCAN.htm)
to process the SCAN op-code. I assume RPGLE does the same, and I think that
memcmp does also.
As an example of what I'm talking about, if you have a 'base' instruct (the
one you're scanning) which contains e.g. 'AAAAAAAAA...(lot's more 'A's
here)...AAAAAbcAAAA' and you're scanning for 'Abc', then one method would
'technically' be faster than the other.
In this particular case, I actually *have* seen a noticeable performance
improvement when using one of the two methods, but I knew in advance what
the contents of the base string would be. Also, I was searching for a
5-byte string in a 65535-byte base string.
So basically, if you know what the base string is likely to be
*and*certain other factors are true, then you
*might* be able to get better performance by writing some code to call some
C functions. Just not using %scan instead of SCAN.
If you want to see what the two different code methods look like, let me
know and I'll post them.
Finally, performance is (as you know) much more likely to be affected by
things other than data scanning. If you're actually hitting problems (as
opposed to just musing!), check things like file I/O before looking at
scanning. Also, maybe think outside the box - do you need to scan these
strings at all - is there any 'pre-processing' you could do to hold offsets
separately? Stuff like that might be slightly more code, but could give
good savings.
Rory
On Mon, Jan 9, 2012 at 11:11 AM, sjl <sjl_abc@xxxxxxxxxxx> wrote:
has anyone benchmarked speed comparison of using SCAN versus %SCAN?
I inherited and am maintaining a fixed-format RPGIV program which uses SCAN
to scan strings for certain values (hundreds of occurences of the SCAN
opcode), and I am wondering if I can get any kind of performance
improvement
if I change them to use %scan instead.
- sjl
--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.