Python的MySQL驅動pymysql與mysqlclient性能對比

Python版本3.6python

測試語句:mysql

select * from FOO;

 

mysql終端直接執行:git

46410 rows in set (0.10 sec)

 

 

python程序需安裝profilehooks進行調用耗時分析github

 

pymysql驅動測試程序:sql

# 安裝:pip install pymysql

from profilehooks import profile
import pymysql.cursors
import pymysql
connection = pymysql.connect(host='localhost', user='root', db='foo')
c = connection.cursor()

@profile(immediate=True)
def read_by_pymysql():
    c.execute("select * from FOO;")
    res = c.fetchall()



read_by_pymysql()

分析結果:耗時2.4s,與原始mysql讀取差一個數量級性能

 

 

mysqlclient驅動測試程序:測試

# 安裝:pip install mysqlclient 或 pip install git+https://github.com/PyMySQL/mysqlclient-python.git

from profilehooks import profile
import MySQLdb

connection = MySQLdb.connect(host='localhost', user='root', db='foo')
c = connection.cursor()

@profile(immediate=True)
def read_by_mysqlclient():
    c.execute("select * from FOO;")
    res = c.fetchall()



read_by_mysqlclient()

 

分析結果:耗時0.4s, 和mysql直接執行基本在同一量級fetch

 

 

綜上,mysqlclient的性能要好於pymsqlcode

相關文章
相關標籤/搜索