mirror of
https://github.com/mariadb-corporation/mariadb-connector-python.git
synced 2025-07-27 13:01:19 +00:00
[misc] adding bulk benchmark
This commit is contained in:
@ -2,36 +2,33 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import pyperf
|
import pyperf
|
||||||
|
import random
|
||||||
|
|
||||||
|
chars = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "\\Z", "😎", "🌶", "🎤", "🥂" ]
|
||||||
|
|
||||||
|
def randomString(length):
|
||||||
|
result = "";
|
||||||
|
for value in range(length):
|
||||||
|
result = result + chars[random.randint(0, (len(chars) - 1))]
|
||||||
|
return result;
|
||||||
|
|
||||||
|
|
||||||
def bulk(loops, conn, paramstyle):
|
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
|
# conn.autocommit= False
|
||||||
t0 = pyperf.perf_counter()
|
t0 = pyperf.perf_counter()
|
||||||
vals = [(i,) for i in range(10000)]
|
s = randomString(100)
|
||||||
|
vals = [(s,) for i in range(100)]
|
||||||
|
|
||||||
range_it = range(loops)
|
range_it = range(loops)
|
||||||
for value in range_it:
|
for value in range_it:
|
||||||
|
cursor = conn.cursor()
|
||||||
if paramstyle == 'qmark':
|
if paramstyle == 'qmark':
|
||||||
cursor.executemany("INSERT INTO test_update_bulk VALUES (?,NULL)",
|
cursor.executemany("INSERT INTO perfTestTextBatch(t0) VALUES (?)",
|
||||||
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)
|
vals)
|
||||||
else:
|
else:
|
||||||
cursor.executemany("INSERT INTO test_update_bulk VALUES (%s,NULL)",
|
cursor.executemany("INSERT INTO perfTestTextBatch(t0) VALUES (%s)",
|
||||||
vals)
|
vals)
|
||||||
conn.commit()
|
del cursor
|
||||||
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
|
return pyperf.perf_counter() - t0
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
import pyperf
|
import pyperf
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from benchmarks.benchmark.bulk import bulk
|
||||||
from benchmarks.benchmark.do_1 import do1
|
from benchmarks.benchmark.do_1 import do1
|
||||||
from benchmarks.benchmark.select_1 import select_1
|
from benchmarks.benchmark.select_1 import select_1
|
||||||
from benchmarks.benchmark.do_1000_param import do_1000_param
|
from benchmarks.benchmark.do_1000_param import do_1000_param
|
||||||
@ -19,6 +20,8 @@ def run_test(tests, conn, paramstyle):
|
|||||||
def test_suite(paramstyle):
|
def test_suite(paramstyle):
|
||||||
is_mysql = int(os.environ.get('TEST_MYSQL', '1'))
|
is_mysql = int(os.environ.get('TEST_MYSQL', '1'))
|
||||||
ts = [
|
ts = [
|
||||||
|
{'label': 'BULK Insert',
|
||||||
|
'method': bulk},
|
||||||
{'label': 'DO 1',
|
{'label': 'DO 1',
|
||||||
'method': do1},
|
'method': do1},
|
||||||
{'label': 'DO 1000 params',
|
{'label': 'DO 1000 params',
|
||||||
|
@ -29,6 +29,18 @@ def init_db(conn, paramstyle):
|
|||||||
else:
|
else:
|
||||||
cursor.executemany("INSERT INTO num_test VALUES (%s,%s,%s,%s,%s,%s)",
|
cursor.executemany("INSERT INTO num_test VALUES (%s,%s,%s,%s,%s,%s)",
|
||||||
vals)
|
vals)
|
||||||
|
|
||||||
|
cursor.execute("DROP TABLE IF EXISTS perfTestTextBatch")
|
||||||
|
try:
|
||||||
|
cursor.execute("INSTALL SONAME 'ha_blackhole'")
|
||||||
|
except Error:
|
||||||
|
pass
|
||||||
|
createTable = "CREATE TABLE perfTestTextBatch (id MEDIUMINT NOT NULL AUTO_INCREMENT,t0 text, PRIMARY KEY (id)) COLLATE='utf8mb4_unicode_ci'"
|
||||||
|
try:
|
||||||
|
cursor.execute(createTable + " ENGINE = BLACKHOLE")
|
||||||
|
except Exception:
|
||||||
|
cursor.execute(createTable)
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
del cursor
|
del cursor
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user