Re: How much slower are numerics?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How much slower are numerics?
Дата
Msg-id 27770.1129950913@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: How much slower are numerics?  ("Scott Marlowe" <smarlowe@g2switchworks.com>)
Ответы Re: How much slower are numerics?  (Jon Lapham <lapham@jandr.org>)
Список 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 по дате отправления:

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: Large Table Performance
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Quickly calculating row size of a table?