Skip to content

Commit cb238ce

Browse files
committed
[misc] adding bulk benchmark
1 parent 4c75199 commit cb238ce

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

testing/benchmarks/benchmark/bulk.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,33 @@
22
# -*- coding: utf-8 -*-
33

44
import pyperf
5+
import random
6+
7+
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", "😎", "🌶", "🎤", "🥂" ]
8+
9+
def randomString(length):
10+
result = "";
11+
for value in range(length):
12+
result = result + chars[random.randint(0, (len(chars) - 1))]
13+
return result;
514

615

716
def bulk(loops, conn, paramstyle):
8-
cursor = conn.cursor()
9-
cursor.execute("CREATE TEMPORARY TABLE test_update_bulk ("
10-
"a int primary key, b int)")
17+
1118
# conn.autocommit= False
1219
t0 = pyperf.perf_counter()
13-
vals = [(i,) for i in range(10000)]
20+
s = randomString(100)
21+
vals = [(s,) for i in range(100)]
22+
1423
range_it = range(loops)
1524
for value in range_it:
25+
cursor = conn.cursor()
1626
if paramstyle == 'qmark':
17-
cursor.executemany("INSERT INTO test_update_bulk VALUES (?,NULL)",
18-
vals)
19-
conn.commit()
20-
cursor.executemany("UPDATE test_update_bulk SET b=2 WHERE a=?",
21-
vals)
22-
conn.commit()
23-
cursor.executemany("DELETE FROM test_update_bulk WHERE a=?",
27+
cursor.executemany("INSERT INTO perfTestTextBatch(t0) VALUES (?)",
2428
vals)
2529
else:
26-
cursor.executemany("INSERT INTO test_update_bulk VALUES (%s,NULL)",
27-
vals)
28-
conn.commit()
29-
cursor.executemany("UPDATE test_update_bulk SET b=2 WHERE a=%s",
30+
cursor.executemany("INSERT INTO perfTestTextBatch(t0) VALUES (%s)",
3031
vals)
31-
conn.commit()
32-
cursor.executemany("DELETE FROM test_update_bulk WHERE a=%s",
33-
vals)
34-
conn.commit()
35-
cursor.execute("DROP TABLE IF EXISTS test_update_bulk")
36-
del cursor
32+
del cursor
33+
3734
return pyperf.perf_counter() - t0

testing/benchmarks/internal_bench.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pyperf
55
import os
66

7+
from benchmarks.benchmark.bulk import bulk
78
from benchmarks.benchmark.do_1 import do1
89
from benchmarks.benchmark.select_1 import select_1
910
from benchmarks.benchmark.do_1000_param import do_1000_param
@@ -19,6 +20,8 @@ def run_test(tests, conn, paramstyle):
1920
def test_suite(paramstyle):
2021
is_mysql = int(os.environ.get('TEST_MYSQL', '1'))
2122
ts = [
23+
{'label': 'BULK Insert',
24+
'method': bulk},
2225
{'label': 'DO 1',
2326
'method': do1},
2427
{'label': 'DO 1000 params',

testing/benchmarks/setup_db.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ def init_db(conn, paramstyle):
2929
else:
3030
cursor.executemany("INSERT INTO num_test VALUES (%s,%s,%s,%s,%s,%s)",
3131
vals)
32+
33+
cursor.execute("DROP TABLE IF EXISTS perfTestTextBatch")
34+
try:
35+
cursor.execute("INSTALL SONAME 'ha_blackhole'")
36+
except Error:
37+
pass
38+
createTable = "CREATE TABLE perfTestTextBatch (id MEDIUMINT NOT NULL AUTO_INCREMENT,t0 text, PRIMARY KEY (id)) COLLATE='utf8mb4_unicode_ci'"
39+
try:
40+
cursor.execute(createTable + " ENGINE = BLACKHOLE")
41+
except Exception:
42+
cursor.execute(createTable)
43+
3244
conn.commit()
3345
del cursor
3446

0 commit comments

Comments
 (0)