|
1 | 1 | import time
|
2 | 2 |
|
3 | 3 | import aiomysql
|
4 |
| -import faker |
5 | 4 |
|
6 | 5 | import asyncmy
|
7 |
| -from benchmark import INSERT_COUNT, conn_mysqlclient, conn_pymysql, connection_kwargs |
8 |
| - |
9 |
| -faker = faker.Faker() |
10 |
| -data = [ |
11 |
| - ( |
12 |
| - 1, |
13 |
| - faker.date_time().date(), |
14 |
| - faker.date_time(), |
15 |
| - 1, |
16 |
| - faker.name(), |
17 |
| - 1, |
18 |
| - ) |
19 |
| - for _ in range(INSERT_COUNT) |
20 |
| -] |
21 |
| -sql = """INSERT INTO test.asyncmy(`decimal`, `date`, `datetime`, `float`, `string`, `tinyint`) VALUES (%s,%s,%s,%s,%s,%s)""" |
| 6 | +from benchmark import COUNT, conn_mysqlclient, conn_pymysql, connection_kwargs, data, sql |
| 7 | +from benchmark.decorators import cleanup |
22 | 8 |
|
23 | 9 |
|
| 10 | +@cleanup |
24 | 11 | async def insert_asyncmy():
|
25 | 12 | conn = await asyncmy.connect(**connection_kwargs)
|
26 | 13 | async with conn.cursor() as cur:
|
27 | 14 | t = time.time()
|
28 | 15 | ret = await cur.executemany(sql, data)
|
29 |
| - assert ret == INSERT_COUNT |
| 16 | + assert ret == COUNT |
30 | 17 | return time.time() - t
|
31 | 18 |
|
32 | 19 |
|
| 20 | +@cleanup |
33 | 21 | async def insert_aiomysql():
|
34 | 22 | conn = await aiomysql.connect(**connection_kwargs)
|
35 | 23 | async with conn.cursor() as cur:
|
36 | 24 | t = time.time()
|
37 | 25 | ret = await cur.executemany(sql, data)
|
38 |
| - assert ret == INSERT_COUNT |
| 26 | + assert ret == COUNT |
39 | 27 | return time.time() - t
|
40 | 28 |
|
41 | 29 |
|
| 30 | +@cleanup |
42 | 31 | def insert_mysqlclient():
|
43 | 32 | cur = conn_mysqlclient.cursor()
|
44 | 33 | t = time.time()
|
45 | 34 | ret = cur.executemany(sql, data)
|
46 |
| - assert ret == INSERT_COUNT |
| 35 | + assert ret == COUNT |
47 | 36 | return time.time() - t
|
48 | 37 |
|
49 | 38 |
|
| 39 | +@cleanup |
50 | 40 | def insert_pymysql():
|
51 | 41 | cur = conn_pymysql.cursor()
|
52 | 42 | t = time.time()
|
53 | 43 | ret = cur.executemany(sql, data)
|
54 |
| - assert ret == INSERT_COUNT |
| 44 | + assert ret == COUNT |
55 | 45 | return time.time() - t
|
0 commit comments