timeprintf.c
text/x-c
Filename: timeprintf.c
Type: text/x-c
Part: 0
#include "postgres_fe.h"
#include "portability/instr_time.h"
#include "snprintf.c"
int
main(int argc, char **argv)
{
int count = 0;
char buffer[1000];
instr_time start;
instr_time stop;
double elapsed;
int i;
if (argc > 1)
count = atoi(argv[1]);
if (count <= 0)
count = 1000000;
INSTR_TIME_SET_CURRENT(start);
for (i = 0; i < count; i++)
{
snprintf(buffer, sizeof(buffer),
"%d %g %s",
42, 42.2, "01234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890");
}
INSTR_TIME_SET_CURRENT(stop);
INSTR_TIME_SUBTRACT(stop, start);
elapsed = INSTR_TIME_GET_MILLISEC(stop);
printf("snprintf time = %g ms total, %g ms per iteration\n",
elapsed, elapsed / count);
INSTR_TIME_SET_CURRENT(start);
for (i = 0; i < count; i++)
{
pg_snprintf(buffer, sizeof(buffer),
"%d %g %s",
42, 42.2, "01234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890");
}
INSTR_TIME_SET_CURRENT(stop);
INSTR_TIME_SUBTRACT(stop, start);
elapsed = INSTR_TIME_GET_MILLISEC(stop);
printf("pg_snprintf time = %g ms total, %g ms per iteration\n",
elapsed, elapsed / count);
return 0;
}