Created
September 13, 2016 10:41
-
-
Save tistaharahap/bc3caf46ca5ba0086e66c44c704647b4 to your computer and use it in GitHub Desktop.
This file contains 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
from pyhs import Manager | |
import MySQLdb | |
import time | |
def run_handlersocket(maximum): | |
hs = Manager() # Assuming that Handlersocket is available at 127.0.0.1 | |
print '**/ Benchmarking Handlersocket - START /**\n' | |
_start = time.time() | |
for i in xrange(1, maximum): | |
user = hs.find('fun', 'user', '>=', ['user_id', 'user_name', 'user_email', 'created'], ['tistaharahap'], 'usernames', 1) | |
_end = time.time() | |
elapsed_time = _end - _start | |
print 'Elapsed time: %.2f seconds' % (elapsed_time) | |
print 'Speed : %.2f queries/second' % (maximum / elapsed_time) | |
print '**/ Benchmarking Handlersocket - END /**\n' | |
def run_mysql(maximum): | |
print '**/ Benchmarking MySQL - START /**\n' | |
db = MySQLdb.connect('localhost', 'root', '', 'fun') | |
cursor = db.cursor() | |
query = 'SELECT user_id, user_name, user_email, created FROM user WHERE user_name = "tistaharahap" LIMIT 1' | |
_start = time.time() | |
for i in xrange(1, maximum): | |
cursor.execute(query) | |
user = cursor.fetchone() | |
_end = time.time() | |
elapsed_time = _end - _start | |
print 'Elapsed time: %.2f seconds' % (elapsed_time) | |
print 'Speed : %.2f queries/second' % (maximum / elapsed_time) | |
print '**/ Benchmarking MySQL - END /**\n' | |
def main(): | |
maximum = 100000 | |
run_handlersocket(maximum) | |
run_mysql(maximum) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment