#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;
	double elapsed2;
	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 %d", 15, 16);
	}

	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 %d", 15, 16);
	}

	INSTR_TIME_SET_CURRENT(stop);
	INSTR_TIME_SUBTRACT(stop, start);
	elapsed2 = INSTR_TIME_GET_MILLISEC(stop);

	printf("pg_snprintf time = %g ms total, %g ms per iteration\n",
		   elapsed2, elapsed2 / count);
	printf("ratio = %.3f\n", elapsed2 / elapsed);

	return 0;
}
