Skip to content

Instantly share code, notes, and snippets.

@salehi
Forked from methane/bench.py
Created July 20, 2023 08:41
Show Gist options
  • Save salehi/2472d40533a33120fba5300784072ef5 to your computer and use it in GitHub Desktop.
Save salehi/2472d40533a33120fba5300784072ef5 to your computer and use it in GitHub Desktop.

Revisions

  1. @methane methane revised this gist Jun 3, 2014. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  2. @methane methane revised this gist Jun 3, 2014. 3 changed files with 35 additions and 3 deletions.
    File renamed without changes.
    30 changes: 30 additions & 0 deletions PyPy.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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]
    8 changes: 5 additions & 3 deletions bench.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    from __future__ import print_function
    import time

    def query_10k(cur):
    @@ -28,6 +29,7 @@ def pymysql():
    print("PyMySQL:", query_10k(conn.cursor()), "[sec]")


    mysql_connector_python()
    mysqlclient()
    pymysql()
    for _ in range(10): # for PyPy warmup
    mysql_connector_python()
    mysqlclient()
    pymysql()
  3. @methane methane created this gist Jun 3, 2014.
    33 changes: 33 additions & 0 deletions bench.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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()
    3 changes: 3 additions & 0 deletions result.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    MySQL Connector/Python: 4.554934978485107 [sec]
    mysqlclient: 0.8555710315704346 [sec]
    PyMySQL: 5.129631996154785 [sec]