Skip to content

Instantly share code, notes, and snippets.

@abubelinha
Forked from methane/bench.py
Created January 23, 2021 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abubelinha/ebddc9e0d9d360c47ea3ccfa8c35a858 to your computer and use it in GitHub Desktop.
Save abubelinha/ebddc9e0d9d360c47ea3ccfa8c35a858 to your computer and use it in GitHub Desktop.
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()
mysqlclient()
pymysql()
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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment