File: test_benchmarks.py

package info (click to toggle)
pg8000 1.31.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 836 kB
  • sloc: python: 8,273; sh: 25; makefile: 9
file content (30 lines) | stat: -rw-r--r-- 814 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pytest

from pg8000.dbapi import connect


@pytest.mark.parametrize(
    "txt",
    (
        ("int2", "cast(id / 100 as int2)"),
        "cast(id as int4)",
        "cast(id * 100 as int8)",
        "(id % 2) = 0",
        "N'Static text string'",
        "cast(id / 100 as float4)",
        "cast(id / 100 as float8)",
        "cast(id / 100 as numeric)",
        "timestamp '2001-09-28'",
    ),
)
def test_round_trips(db_kwargs, benchmark, txt):
    def torun():
        with connect(**db_kwargs) as con:
            query = f"""SELECT {txt}, {txt}, {txt}, {txt}, {txt}, {txt}, {txt}
                FROM (SELECT generate_series(1, 10000) AS id) AS tbl"""
            cursor = con.cursor()
            cursor.execute(query)
            cursor.fetchall()
            cursor.close()

    benchmark(torun)