Re: C vs C++
Jevgeni Astanovski <[email protected]>
| Newsgroups | gmane.comp.lang.as400.c |
|---|---|
| Message-ID | <CAJuVQr1uQCOi8jasH-SXQNNV=uY7u8co8qnfNRjPTfMxHFPuSw@mail.gmail.com> |
Mark, Not used to just believe, I repeated your test. I also tried to substitute 11,0 that you use with 15,0 that I use - to see its effect. Probably my box is slightly more powerful :-) but the trend is exactly the same: C and decimal(11,0) : 470ms C++ and decimal(11,0) : 23900ms C and decimal(15,0) : 560ms C++ and decimal(15,0) : 25500ms Turning optimization on reduces the time to 21000 ms - but it is still so far from what is seen in C. I'll go and see what can be done with the sources to decrease the use of packed.... :-(((( Jevgeni. On Mon, Feb 16, 2015 at 9:32 PM, Mark S Waterbury <[email protected]> wrote: > Jevgeni: > > To confirm my hypothesis, I made a few small changes to that BENCH.C > program, now re-posted as BENCHBCD.C here: > > http://code.midrange.com/136eb55598.html > > When I run this here, the differences in elapsed time is much worse than > just twice as slow -- the C++ version took 24 times longer than the C > version -- 8 seconds versus 3 minutes and 16 seconds -- Tis example, dping > all of those loops, and dong lots of BCD math, grossly exaggerates the > differences between the overhead of procedure/function calls to library > routines in ILE C++, versus "in-line" code in ILE C.. > > Mark > >> On 2/16/2015 1:29 PM, Mark S Waterbury wrote: >> >> Jevjeni: >> >> 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 ILE >> 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 for >> "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 ... if 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 decimal" data. >> >> This difference could easily account for the big differences you are >> seeing. >> >> 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 64-bit >> 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 ILE 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-Zwy7GipZuJhWk0Htik3J/[email protected] > To subscribe, unsubscribe, or change list options, > visit: http://lists.midrange.com/mailman/listinfo/c400-l > or email: C400-L-request-Zwy7GipZuJhWk0Htik3J/[email protected] > Before posting, please take a moment to review the archives > at http://archive.midrange.com/c400-l. > -- This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list To post a message email: C400-L-Zwy7GipZuJhWk0Htik3J/[email protected] To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/c400-l or email: C400-L-request-Zwy7GipZuJhWk0Htik3J/[email protected] Before posting, please take a moment to review the archives at http://archive.midrange.com/c400-l.