2013/6/22 Albus X <albus...@gmail.com>
> Hello. I experienced a strange efficiency problem in my code and after
> some debuging I find that std::sprintf is very slow. Indeed it's even
> different from the sprintf function in <stdio.h>.
>
> When doing the following test:
>
> #include <stdio.h>
> // #include <cstdio>
> // using std::sprintf;
>
> int main () {
> int i;
> for (i = 0; i < 500000; i++){
> char x[100];
> sprintf(x, "x%dx%dx", i, i<<2);
> }
> }
>
> the std::sprintf in <cstdio> is 15 times slower. Here is the timing.
>
> $ time ./stdio
>
> real 0m0.557s
> user 0m0.046s
> sys 0m0.046s
>
> $ time ./cstdio
>
> real 0m7.465s
> user 0m0.031s
> sys 0m0.077s
>
> I also timed with different mingw-w64 build (rubenvb, drangon, and
> mingw-builds), and find that all 32bit version using <cstdio> timed
> 4.x seconds and 64bit versions 7.x~8.x seconds. And all versions using
> <stdio.h> timed around 0.4~0.6 second.
>
> In gdb I find that the sprintf implementation calls msvcrt's sprintf
> after some jumps while std::sprintf calls some mingw function.
>
> Why is that two function different? If there is a reason then why is
> std::sprintf so slow?
>
This is most likely to accomodate libstdc++'s POSIX printf requirements.
This however does not explain why the MinGW-w64 implementation is so slow.
IMHO, this needs to be looked into and optimized. Could you test an old
build that uses the v2.x runtime to see if that changes anything.
Unfortunately, I wouldn't be able to point you to one of my builds that
uses this. I guess GCC 4.7.2 or 4.7.1 releases might use the stable
2.0[7,8] release.
Surely there must be some public domain printf we can rip off of the
internet ;-P
Ruben
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Windows:
>
> Build for Windows Store.
>
> http://p.sf.net/sfu/windows-dev2dev
> _______________________________________________
> Mingw-w64-public mailing list
> Mingw-w64-public@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public