Files
mariadb-connector-python/testing/benchmarks/benchmark/bulk.py
Georg Richter cdd42743cc Coding style fixes (PEP8)
Fixed various coding style stuff detected by flake8.
Added .pre-commit-config.yaml:
With command pre_commit install a hook for flake8 will be
installed.
2022-08-07 16:47:26 +02:00

38 lines
1.3 KiB
Python

#!/usr/bin/env python3 -O
# -*- coding: utf-8 -*-
import pyperf
def bulk(loops, conn, paramstyle):
cursor = conn.cursor()
cursor.execute("CREATE TEMPORARY TABLE test_update_bulk ("
"a int primary key, b int)")
# conn.autocommit= False
t0 = pyperf.perf_counter()
vals = [(i,) for i in range(10000)]
range_it = range(loops)
for value in range_it:
if paramstyle == 'qmark':
cursor.executemany("INSERT INTO test_update_bulk VALUES (?,NULL)",
vals)
conn.commit()
cursor.executemany("UPDATE test_update_bulk SET b=2 WHERE a=?",
vals)
conn.commit()
cursor.executemany("DELETE FROM test_update_bulk WHERE a=?",
vals)
else:
cursor.executemany("INSERT INTO test_update_bulk VALUES (%s,NULL)",
vals)
conn.commit()
cursor.executemany("UPDATE test_update_bulk SET b=2 WHERE a=%s",
vals)
conn.commit()
cursor.executemany("DELETE FROM test_update_bulk WHERE a=%s",
vals)
conn.commit()
cursor.execute("DROP TABLE IF EXISTS test_update_bulk")
del cursor
return pyperf.perf_counter() - t0