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 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

Reply via email to