Skip site navigation (1) Skip section navigation (2)

Re: pl/pgsql and returns timestamp type

From: Hubert depesz Lubaczewski <depesz(at)depesz(dot)pl>
To: Terry Yapt <yapt(at)technovell(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: pl/pgsql and returns timestamp type
Date: 2002-09-14 12:15:24
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
On Tue, Sep 10, 2002 at 07:58:22PM +0200, Terry Yapt wrote:
> I am only testing different datatypes.  In the example I would like to
> know how many time was spent by the function execution.

since we were bothered with this too (and measuring outside of function
was not an option - we had to test how much particular parts of function
takes time, we (friend of mine to be exact) wrote this code:

--- getcpuclock.c ---
#include <postgres.h>
#include <fmgr.h>


Datum getcpuclock(PG_FUNCTION_ARGS)
	uint64	tsc;

	asm  (
		: "cx"  (&tsc)
		: "ax", "dx"

--- getcpuclock.c ---

this compiled into .so, and installed into postgres with
CREATE FUNCTION getcpuclock() RETURNS INT8 AS '/home/users/pgdba/work/lib/' LANGUAGE 'C';

(or equivalent with corrected paths)
will give you function which returns number of processor ticks from last
this is not easily convertible into seconds or anything else, but
provides very good accuracy, and is more or less perfect when measuring
how much time you spend on different tasks.

hope this helps a bit.


hubert depesz lubaczewski                
Mój Boże, spraw abym milczał, dopóki się nie upewnię,  że  naprawdę  mam
coś do powiedzenia.                                      (c) 1998 depesz

In response to

pgsql-novice by date

Next:From: J Matt ClarkDate: 2002-09-14 21:13:59
Subject: ODBC type "PG_TYPE_LO_NAME"
Previous:From: sdeelDate: 2002-09-14 04:41:49
Subject: how to process?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group