Re: How much slower are numerics? - Mailing list pgsql-general

From Tom Lane
Subject Re: How much slower are numerics?
Date
Msg-id 27770.1129950913@sss.pgh.pa.us
Whole thread Raw
In response to Re: How much slower are numerics?  ("Scott Marlowe" <smarlowe@g2switchworks.com>)
Responses Re: How much slower are numerics?  (Jon Lapham <lapham@jandr.org>)
List pgsql-general
"Scott Marlowe" <smarlowe@g2switchworks.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

pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Large Table Performance
Next
From: Tom Lane
Date:
Subject: Re: Quickly calculating row size of a table?