
please wait
If your C++ code is not slower than C then you are not using C++. |
There will be always overhead memory-wise. |
C++ is intended to be used for systems that need higher level of abstraction and there is always a price to pay for that. |
simeonz wrote: |
---|
If your C++ code is not slower than C then you are not using C++...C++ is intended to be used for systems that need higher level of abstraction and there is always a price to pay for that. |
simeonz wrote: |
---|
There will be always overhead memory-wise. |
kbw wrote: |
---|
Virtual functions imply a cost, but implementing a similar mechanism using a switch is more costly. You'd have to resort to pointers to functions to do better. |
kbw wrote: |
---|
C++ was designed to be as fast as C. |
kbw wrote: |
---|
STL is as fast as hand rolled containers/algorithms. |
kbw wrote: |
---|
C doesn't offer language support for OO. |
May be it can slow things but how it could produce such an effect that the time becomes 1/6th of the earlier time?? |
Library design is an exercise in compromise. The ideal library is small, fast, powerful, flexible, extensible, intuitive, universally available, well supported, free of use restrictions, and bug-free. It is also nonexistent. Libraries optimized for size and speed are typically not portable. Libraries with rich functionality are rarely intuitive. Bug-free libraries are limited in scope. In the real world, you can't have everything; something always has to give. Different designers assign different priorities to these criteria. They thus sacrifice different things in their designs. As a result, it is not uncommon for two libraries offering similar functionality to have quite different performance profiles. As an example, consider the iostream and stdio libraries, both of which should be available to every C++ programmer. The iostream library has several advantages over its C counterpart (see Item E2). It's type-safe, for example, and it's extensible. In terms of efficiency, however, the iostream library generally suffers in comparison with stdio, because stdio usually results in executables that are both smaller and faster than those arising from iostreams. Consider first the speed issue. One way to get a feel for the difference in performance between iostreams and stdio is to run benchmark applications using both libraries. Now, it's important to bear in mind that benchmarks lie. Not only is it difficult to come up with a set of inputs that correspond to "typical" usage of a program or library, it's also useless unless you have a reliable way of determining how "typical" you or your clients are. Nevertheless, benchmarks can provide some insight into the comparative performance of different approaches to a problem, so though it would be foolish to rely on them completely, it would also be foolish to ignore them. Let's examine a simple-minded benchmark program that exercises only the most rudimentary I/O functionality. This program reads 30,000 floating point numbers from standard input and writes them to standard output in a fixed format. The choice between the iostream and stdio libraries is made during compilation and is determined by the preprocessor symbol STDIO. If this symbol is defined, the stdio library is used, otherwise the iostream library is employed. |
|
|
I have run this program on several combinations of machines, operating systems, and compilers, and in every case the stdio version has been faster. Sometimes it's been only a little faster (about 20%), sometimes it's been substantially faster (nearly 200%), but I've never come across an iostream implementation that was as fast as the corresponding stdio implementation. In addition, the size of this trivial program's executable using stdio tends to be smaller (sometimes much smaller) than the corresponding program using iostreams. (For programs of a realistic size, this difference is rarely significant.) |
fprintf(out,"%#08x %+.2ld",idnum,late_book_fee);
|
|
EDIT: And who the hell decided to overload "bit shift left" to mean "print to file"? That's like overloading "exclusive or" to mean "exponent", or "greater than" to mean "put in file", like in the shell. |