Spent some time and rewrote the API to use long long.
However I have nothing to do about the data that I'm processing.
I work in the finance area so effectively my API works not with
numbers - rather with money.
And all the money in the tables is kept as packed decimals.
So what I did - I read packed decimals and immediately convert them to
long long before I make some arithmetics with them.
Result is still the same - 2 times slower than the C version...

I'll now go and experiment with the benchmarking program of yours to
see what consumes time. If conversion of packed to int (or long) is
most ti,e consuming, then probably I'm digging in the wrong

On Mon, Feb 16, 2015 at 9:38 PM, Mark S Waterbury
<mark.s.waterbury@xxxxxxxxxxxxx> wrote:

I can pretty much guarantee that using 64-bit integers will always win "big
time" over using packed decimal, even in ILE C/400, from a performance
standpoint. All the more so, with ILE C++.


On 2/16/2015 2:31 PM, Jevgeni Astanovski wrote:

Mark, frankly speaking packed decimal was my suspect since I saw the
difference. I saw the difference - it was intuitively clear that the
implementations of packed decimal is fundamentally different in C and C++
(however unclear why). What I'll do tomorrow, I'll write my own trivial
benchmark using decimal arithmetics.
Hopefully I shall see the difference.
The program uses decimal (15,0), decimal (15,9) and decimal (11,7) - It
seems that they all fit into 8 byte int.
I'll then see which is better - staying on C and decimals or switch to C++
and integers...

On Feb 16, 2015 8:29 PM, "Mark S Waterbury"


I just noticed near the bottom of your post, where you said:

Program makes a lot of calculations with packed decimal.

There is a big difference in the way ILE C implements support for "packed
decimal" as a "native" data type -- versus the way it is "supported" in
C++ -- in ILE C, the compiler directly genrerates in-line code (in WCode
NMI) to work on packed decimal data. In the ILE C++ compiler, support
"packed decimal" is through a C++ library called "BCD" -- there are a lot
of macros and such defined in the QSYSINC/H include member named BCD ...
you take a peek at that member, I think you will see that this uses
"operator overloading" in C++ to trick the compiler into calling the
desired library functions when operations are performed on "packed

This difference could easily account for the big differences you are

And then, you said:

... is there anything that can be done about it?

In C++, you could look into converting the packed decimal data into
integers, and then performing any calculations using those long integers.
This would be much faster than using packed decimal arithmetic, then
convert back to packed decimal format, if needed. Or, just stick with
C/400 for those programs that require doing a lot of packed decimal
arithmetic operations.

Hope that helps,

Mark S. Waterbury

This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L)
mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by 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].