Files
mariadb-connector-python/benchmarks/benchmark/fetch.py
2020-01-13 05:35:50 +00:00

51 lines
1.4 KiB
Python

#!/usr/bin/env python3 -O
# -*- coding: utf-8 -*-
import pyperf
def str_fetchall(loops, conn):
cursor = conn.cursor()
range_it = range(loops)
t0 = pyperf.perf_counter()
for value in range_it:
cursor.execute('select col1,col2,col3 from str_test')
row= cursor.fetchall()
del row
del cursor
return pyperf.perf_counter() - t0
def str_fetchloop(loops, conn):
cursor = conn.cursor()
range_it = range(loops)
t0 = pyperf.perf_counter()
for value in range_it:
cursor.execute('select col1,col2,col3 from str_test')
row= cursor.fetchone()
while row is not None:
row= cursor.fetchone()
del cursor
return pyperf.perf_counter() - t0
def num_fetchall(loops, conn):
cursor = conn.cursor()
range_it = range(loops)
t0 = pyperf.perf_counter()
for value in range_it:
cursor.execute('select col1,col2,col3,col4,col5 from num_test')
row= cursor.fetchall()
del row
del cursor
return pyperf.perf_counter() - t0
def num_fetchloop(loops, conn):
cursor = conn.cursor()
range_it = range(loops)
t0 = pyperf.perf_counter()
for value in range_it:
cursor.execute('select col1,col2,col3,col4,col5 from num_test')
row= cursor.fetchone()
while row is not None:
row= cursor.fetchone()
del cursor
return pyperf.perf_counter() - t0