Post by unknownPost by Andre KaufmannIf the implementation of itoa is faster, then it could be used instead
of sprintf - couldn't it ?
No.
iostream allows for formatting. itoa doesn't.
Why do I have to pay for something I don't use (in this case):
if (no_formatting_specified) UseItoa(value)
else ......
Post by unknown[...]
I tend towards, all code should be fast, even if it makes
no noticable difference. That's why I coded my business
apps in 100% ASM for 20 years.
Huh. Sarcasm ? If it's not significant I don't optimize.
I only optimize if my code got significantly slow.
And somehow I find iostreams performance to be significant for most of
my applications.
I remember having ported some Delphi code to C++ years ago and I used
iostreams. Then I wondered why the code got that slow. I did something
quite simple, reading hex values from files up to 500K in size.
Post by unknownPost by Andre KaufmannAm I the only one, who thinks it to be ridiculous, that one
implementation is 5 times slower than the equivalent C# code ?
(I always thought code for a virtual machine to have much more overhead
than C++ code)
StreamWriter is not C++ standard, has no legacy, and can
No it's C# standard - and what does that mean ?
There aren't that many C++ standard library distributions, so why can't
they be optimized.
Another example is the new tr1::tuple implementation. I checked how many
times the object is constructed and copied. 3-4 times the objects
returned with a tuple are copy constructed and destroyed. Returning
simple reference pointers in a tuple might cause the reference counter
to be incremented / decremented multiple times.
But since C++ currently lacks move semantics, I think it can't be
Post by unknownbe optimized at Microsoft's discretion.
In particular, it can buffer as much data as it wishes
before commiting the data to file.
Ehm, iostreams can't ? I just wonder what "<< flush" is for ?
Post by unknownThere also appears to be no formatting options available,
making it faster.
Once again an example for: Don't pay for something you don't use:
Write a formatted string with C# to a file:
Function: StreamWriter.Write(Format, [Objects....]):
Example: w.Write("{0:D6} {1} {2} {0}", 1, 2, 3);
Output: 000001 2 3 000001
And by the way: using the format function instead of the overloaded one,
C# is still faster than some iostream implementations (and C# uses
unicode strings - therefore has more overhead)
But let's forget about C# - I don't want to start a C# is better than
C++ discussion thread / war.
Post by unknownPost by Andre KaufmannSide note: itoa could also be somewhat faster too, if the radix
parameter would be specialized.
Yes, by a few cycles, not more than 1 or 2% faster.
Sorry to disappoint you. It can be up to 200%-300% times faster,
depending on the platform and the compiler.
And don't assume anything regarding performance - you just have to
follow 3 rules regarding performance:
a) measure
b) measure
c) once again measure
Why can a specialized radix itoa faster ?
It's quite simple if the radix is used in a "/" and "%" operation -
division / remainder. If the compiler can determine the radix it will
convert the division to a fix-comma multiplication and shift operations.
In combination these are still faster than a division.
But I agree, compared to the total runtime it might have a negligible
influence on the performance of a typical C++ application. On the other
side, it's quite simple to specialize itoa for the 2 most used radixes:
10, 16
I'm >not< arguing C++ and the C++ library to be generally slow. For
example I'm perfectly happy with the performance of the STL (and the
handling).
Andre