-
-
Save salehi/2472d40533a33120fba5300784072ef5 to your computer and use it in GitHub Desktop.
Benchmarking MySQL drivers (Python 3.4)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]") | |
| mysql_connector_python() | |
| mysqlclient() | |
| pymysql() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MySQL Connector/Python: 4.554934978485107 [sec] | |
| mysqlclient: 0.8555710315704346 [sec] | |
| PyMySQL: 5.129631996154785 [sec] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment