Hi Mattias,
Could you share your micro benchmark data ?
In my testing, getenv() is very fast.
*) unset PRINTF_EXPONENT_DIGITS
preheat 10000 times, then perform 1000000 times (use 4.67777 seconds)
getenv cost: 4.67777 us
*) set PRINTF_EXPONENT_DIGITS=3
preheat 10000 times, then perform 1000000 times (use 3.41991 seconds)
getenv: 3.41991 us
My CPU is Core2 E6550 at 2.33 GHz.
On Wed, Apr 1, 2015 at 10:26 AM, Dongsheng Song <dongsheng.s...@gmail.com>
wrote:
> Cache getenv() looks a good idea !
> Patch is OK for me.
>
> On Wed, Apr 1, 2015 at 4:16 AM, Mattias Engdegård <matti...@acm.org>
> wrote:
>
>> The functions in the __mingw_printf family are very slow because of the
>> getenv(”PRINTF_EXPONENT_DIGITS”) call that is made every time, even when
>> that information isn’t actually needed.
>>
>> Please consider this patch. It only calls getenv once, caching the result
>> (as is traditionally done in libraries that use environment variables this
>> way). It also only computes the minimum exponent digits when actually
>> needed, at most once per format call.
>>
>> With this patch, __mingw_sprintf(buf, ”x”) goes from being several orders
>> of magnitude slower than the MSVCRT sprintf, to about 66% faster. You don’t
>> see this kind of improvement every day.
>>
>
>
#include <winsock2.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#define NUMBER_PREHEAT 10000
#define NUMBER_PERFORM 1000000
int main(int argc, char *argv[])
{
int i;
double t;
LARGE_INTEGER freq, pc, pc2;
QueryPerformanceFrequency(&freq);
for (i = 0; i < NUMBER_PREHEAT; i++) {
getenv("PRINTF_EXPONENT_DIGITS");
}
QueryPerformanceCounter(&pc);
for (i = 0; i < NUMBER_PERFORM; i++) {
getenv("PRINTF_EXPONENT_DIGITS");
}
QueryPerformanceCounter(&pc2);
t = (pc2.QuadPart - pc.QuadPart) / (double) freq.QuadPart;
fprintf(stdout, "preheat %d times, then perform %d times (use %.5lf seconds)\n", NUMBER_PREHEAT, NUMBER_PERFORM, t);
fprintf(stdout, "getenv cost: %.5lf us\n", t * 1000000.0 / NUMBER_PERFORM);
return 0;
}
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public