Last active
December 13, 2015 19:08
-
-
Save keitheis/4959972 to your computer and use it in GitHub Desktop.
It tests the speed of building SQL by different ways, really.
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sql | |
from sqlalchemy import MetaData, Table, Column, String, DateTime | |
metadata = MetaData() | |
users = Table('users', metadata, | |
Column('id', String, primary_key=True), | |
Column('name', String), | |
Column('email', String), | |
Column('created', DateTime)) | |
def use_sqlalchemy(): | |
return str(users.select().where(users.c.id == '20130215')) | |
def use_sqlalchemy_mosql(): | |
return str(sql.select('users', {'id': '20130215'})) | |
def use_sqlalchemy_sql(): | |
return str("SELECT * FROM users WHERE id = '20130215';") | |
if __name__ == '__main__': | |
from timeit import timeit | |
print use_sqlalchemy() | |
print use_sqlalchemy_mosql() | |
print use_sqlalchemy_sql() | |
n = 30000 | |
print '* Using SQLAlchemy' | |
print timeit(use_sqlalchemy, number=n) | |
print '* Using SQLAlchemy with MoSQL:' | |
print timeit(use_sqlalchemy_mosql, number=n) | |
print '* Using SQLAlchemy with pure SQL:' | |
print timeit(use_sqlalchemy_sql, number=n) | |
""" | |
Output: | |
SELECT users.id, users.name, users.email, users.created | |
FROM users | |
WHERE users.id = :id_1 | |
SELECT * FROM users WHERE id = '20130215'; | |
SELECT * FROM users WHERE id = '20130215'; | |
* Using SQLAlchemy | |
7.11727309227 | |
* Using SQLAlchemy with MoSQL: | |
1.16956305504 | |
* Using SQLAlchemy with pure SQL: | |
0.00899291038513 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment