I have a variable with PIC S9(4). Whether I use COMP or COMP-3 here?

2.6k views Asked by At

I know COMP will take 2 bytes and COMP-3 will take 3 bytes of size. The field will undergo lot of computations. What should I use here?

The field involves only addition and subtraction with another thirty PIC S9(4) variables, for which also I need to decide the usage clauses need to be used.

1

There are 1 answers

5
Joe Zitzelberger On BEST ANSWER

Much of that is platform dependent. As a general rule, "comp", which is a twos compliment binary is going to be a little faster, and "comp-3" which is packed decimal, is going to be human readable as decimal in memory or on DASD, is easier for humans to work with.

But those rules were laid down in the ages of very slow processors with single pipelines. Trying to make a decision based on performance is very premature. Especially for only thirty fields. On todays hardware, with todays compilers, with caching and speculative execution, there might be no difference that you can ever notice.

If you are really concerned about it, write two small test programs with your intended calculations and the fields defined both ways, then do a comparative performance test on your intended hardware. My prediction is that you will notice no difference at all.

Mostly though, just write for accuracy and tune later. It is highly unlikely that you will notice the very fast add/subtract operations when in the context of I/O.