This is more related to Postgresql than to Python, I hope this is ok.
I want to measure Postgres queries N times, much like Python timeit
(https://docs.python.org/3/library/timeit.html). I know about EXPLAIN
ANALYZE and psql \timing, but there's quite a bit of variation in the
times. Is there a timeit-like function in Postgresql?
Timing things that are fairly simple is hard enough to do repeatedly, but when it involves access to slower media and especially to network connections to servers, the number of things that can change are enormous. There are all kinds of caching atvarious levels depending on your hardware and resource contention with other programs running here and there as well as on various network-like structures and busses or just hard disks. Asking for anything to be repeated multiple times in a row as a
I am wondering if an approach to running something N times that may average things out a bit is to simply put in a pause. Have your program wait a few minutes between attempts and perhaps even do other things within your loop that make it likely someof the resources you want not to be in a queue have a chance to be flushed as other things take their place.
On Sep 15, 2023 19:45, "Peter J. Holzer via Python-list"
<python-list@python.org> wrote:
On 2023-09-15 17:42:06 +0200, Albert-Jan Roskam via Python-list wrote:
> This is more related to Postgresql than to Python, I hope this is
ok.
> I want to measure Postgres queries N times, much like Python timeit
> (https://docs.python.org/3/library/timeit.html). I know about
EXPLAIN
> ANALYZE and psql \timing, but there's quite a bit of variation in
the
> times. Is there a timeit-like function in Postgresql?
Why not simply call it n times from Python?
(But be aware that calling the same query n times in a row is likely to
be
unrealistically fast because most of the data will already be in
memory.)
=====
Thanks, I'll give this a shot. Hopefully the caching is not an issue if I
don't re-use the same database connection.
On Sep 15, 2023 19:45, "Peter J. Holzer via Python-list"
<python-list@python.org> wrote:
On 2023-09-15 17:42:06 +0200, Albert-Jan Roskam via Python-list wrote:
>Â Â Â This is more related to Postgresql than to Python, I hope this is
ok.
>Â Â Â I want to measure Postgres queries N times, much like Python timeit
>Â Â Â (https://docs.python.org/3/library/timeit.html). I know about
EXPLAIN
>Â Â Â ANALYZE and psql \timing, but there's quite a bit of variation in
the
>Â Â Â times. Is there a timeit-like function in Postgresql?
Why not simply call it n times from Python?
(But be aware that calling the same query n times in a row is likely to
be
unrealistically fast because most of the data will already be in
memory.)
=====
Thanks, I'll give this a shot. Hopefully the caching is not an issue if I
don't re-use the same database connection.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 60:40:58 |
Calls: | 6,712 |
Files: | 12,243 |
Messages: | 5,355,759 |