diff --git a/testing/benchmarks/benchmark/bulk.py b/testing/benchmarks/benchmark/bulk.py index 33223b4..6f8a93b 100644 --- a/testing/benchmarks/benchmark/bulk.py +++ b/testing/benchmarks/benchmark/bulk.py @@ -2,36 +2,33 @@ # -*- coding: utf-8 -*- 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): - 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)] + s = randomString(100) + vals = [(s,) for i in range(100)] + range_it = range(loops) for value in range_it: + cursor = conn.cursor() 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=?", + cursor.executemany("INSERT INTO perfTestTextBatch(t0) VALUES (?)", vals) else: - cursor.executemany("INSERT INTO test_update_bulk VALUES (%s,NULL)", + cursor.executemany("INSERT INTO perfTestTextBatch(t0) VALUES (%s)", 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 + del cursor + return pyperf.perf_counter() - t0 diff --git a/testing/benchmarks/internal_bench.py b/testing/benchmarks/internal_bench.py index 375360b..8a3b0ff 100644 --- a/testing/benchmarks/internal_bench.py +++ b/testing/benchmarks/internal_bench.py @@ -4,6 +4,7 @@ import pyperf import os +from benchmarks.benchmark.bulk import bulk from benchmarks.benchmark.do_1 import do1 from benchmarks.benchmark.select_1 import select_1 from benchmarks.benchmark.do_1000_param import do_1000_param @@ -19,6 +20,8 @@ def run_test(tests, conn, paramstyle): def test_suite(paramstyle): is_mysql = int(os.environ.get('TEST_MYSQL', '1')) ts = [ + {'label': 'BULK Insert', + 'method': bulk}, {'label': 'DO 1', 'method': do1}, {'label': 'DO 1000 params', diff --git a/testing/benchmarks/setup_db.py b/testing/benchmarks/setup_db.py index 33ef989..7b25595 100644 --- a/testing/benchmarks/setup_db.py +++ b/testing/benchmarks/setup_db.py @@ -29,6 +29,18 @@ def init_db(conn, paramstyle): else: cursor.executemany("INSERT INTO num_test VALUES (%s,%s,%s,%s,%s,%s)", 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() del cursor