Skip to content

Instantly share code, notes, and snippets.



Last active Nov 4, 2020
What would you like to do?
Benchmarking MySQL drivers (Python 3.4)
from __future__ import print_function
import time
def query_10k(cur):
t = time.time()
for _ in range(10000):
cur.execute("SELECT 1,2,3,4,5")
res = cur.fetchall()
assert len(res) == 1
assert res[0] == (1,2,3,4,5)
return time.time() - t
def mysql_connector_python():
import mysql.connector
conn = mysql.connector.connect(user='root', host='localhost')
print("MySQL Connector/Python:", query_10k(conn.cursor()), "[sec]")
def mysqlclient():
import MySQLdb
conn = MySQLdb.connect(user='root', host='localhost')
print("mysqlclient:", query_10k(conn.cursor()), "[sec]")
def pymysql():
import pymysql
conn = pymysql.connect(user='root', host='localhost')
print("PyMySQL:", query_10k(conn.cursor()), "[sec]")
for _ in range(10): # for PyPy warmup
MySQL Connector/Python: 4.554934978485107 [sec]
mysqlclient: 0.8555710315704346 [sec]
PyMySQL: 5.129631996154785 [sec]
MySQL Connector/Python: 2.88878798485 [sec]
mysqlclient: 3.7735979557 [sec]
PyMySQL: 2.70332789421 [sec]
MySQL Connector/Python: 1.64176392555 [sec]
mysqlclient: 3.87362599373 [sec]
PyMySQL: 1.43844795227 [sec]
MySQL Connector/Python: 2.09882998466 [sec]
mysqlclient: 3.89048695564 [sec]
PyMySQL: 1.41811800003 [sec]
MySQL Connector/Python: 2.10359406471 [sec]
mysqlclient: 3.88971209526 [sec]
PyMySQL: 1.43477678299 [sec]
MySQL Connector/Python: 1.74524617195 [sec]
mysqlclient: 3.88212299347 [sec]
PyMySQL: 1.43231987953 [sec]
MySQL Connector/Python: 1.61375522614 [sec]
mysqlclient: 3.86587405205 [sec]
PyMySQL: 1.39657282829 [sec]
MySQL Connector/Python: 1.55139803886 [sec]
mysqlclient: 3.87236499786 [sec]
PyMySQL: 1.41039204597 [sec]
MySQL Connector/Python: 1.6928999424 [sec]
mysqlclient: 3.94669413567 [sec]
PyMySQL: 1.40507411957 [sec]
MySQL Connector/Python: 1.91752696037 [sec]
mysqlclient: 4.04861402512 [sec]
PyMySQL: 1.46230983734 [sec]
MySQL Connector/Python: 1.87104988098 [sec]
mysqlclient: 4.25610113144 [sec]
PyMySQL: 1.37460494041 [sec]

This comment has been minimized.

Copy link

@kimtree kimtree commented Sep 24, 2015

CPython benchmark looks bad. Would you please give more benchmarks on CPython 3.4 and CPython 2.7.X?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.