Search Postgresql Archives

Re: How much slower are numerics?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Scott Marlowe" <smarlowe@xxxxxxxxxxxxxxxxx> 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

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux