memtest.c
text/x-csrc
#include "postgres.h"
#include "funcapi.h"
#include "utils/builtins.h"
PG_MODULE_MAGIC;
extern Datum pgmemtest(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(pgmemtest);
Datum
pgmemtest(PG_FUNCTION_ARGS)
{
int result;
struct timeval start_tp, stop_tp;
int n;
void *x;
gettimeofday(&start_tp, NULL);
for( n = 0 ; n < 10000000; n++) {
x = palloc(373);
pfree(x);
}
gettimeofday(&stop_tp, NULL);
result = (stop_tp.tv_sec - start_tp.tv_sec) * 1000000;
result += (stop_tp.tv_usec - start_tp.tv_usec);
PG_RETURN_INT32(result);
}