Re: How much slower are numerics?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Scott Marlowe" <smarlowe(at)g2switchworks(dot)com>
Cc: "CSN" <cool_screen_name90001(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: How much slower are numerics?
Date: 2005-10-22 03:15:13
Message-ID: 27770.1129950913@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Scott Marlowe" <smarlowe(at)g2switchworks(dot)com> writes:
>> How much slower are numerics? And why (I guess it has
>> to do with potentially different sizes)?

> I think that there was a time when numerics were MUCH slower than =
> floats, but looking at a very simple benchmark I just threw together, =
> I'd say they're pretty close nowadays.

I think your benchmark is mostly measuring insert overhead (WAL etc).

On modern hardware, I'd expect float operations to be at least an order
of magnitude faster than numerics, if you measure only the arithmetic
operation itself and not any of the generic data-movement overhead.
Here's a trivial example, which is still mostly dominated by
plpgsql's looping and assignment overhead:

regression=# create or replace function timeit(int) returns void as $$
regression$# declare x float8 := 0;
regression$# begin
regression$# for i in 1..$1 loop
regression$# x := x + 1;
regression$# end loop;
regression$# end $$ language plpgsql;
CREATE FUNCTION
regression=# \timing
Timing is on.
regression=# select timeit(1000000);
timeit
--------

(1 row)

Time: 13700.960 ms
regression=# create or replace function timeit(int) returns void as $$
regression$# declare x numeric := 0;
regression$# begin
regression$# for i in 1..$1 loop
regression$# x := x + 1;
regression$# end loop;
regression$# end $$ language plpgsql;
CREATE FUNCTION
regression=# select timeit(1000000);
timeit
--------

(1 row)

Time: 22145.408 ms

So the question is basically whether your application is sensitive to
the actual speed of arithmetic or not ...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-10-22 03:17:25 Re: Quickly calculating row size of a table?
Previous Message Michael Fuhr 2005-10-22 01:41:04 Re: Large Table Performance