File: bulk.py

package info (click to toggle)
mariadb-connector-python 1.1.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 812 kB
  • sloc: python: 6,246; ansic: 4,971; sh: 23; makefile: 14
file content (34 lines) | stat: -rw-r--r-- 1,006 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
31
32
33
34
#!/usr/bin/env python3 -O
# -*- 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):

#    conn.autocommit= False
    t0 = pyperf.perf_counter()
    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 perfTestTextBatch(t0) VALUES (?)",
                               vals)
        else:
            cursor.executemany("INSERT INTO perfTestTextBatch(t0) VALUES (%s)",
                               vals)
        del cursor

    return pyperf.perf_counter() - t0