Created
May 25, 2013 13:37
-
-
Save marcelcaraciolo/5649061 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
import sqlite3 | |
class BenchmarkDb(object): | |
""" | |
Persistence handler for bechmark results | |
""" | |
def _create_tables(self): | |
self._cursor.execute("drop table if exists benchmarksuites") | |
self._cursor.execute("drop table if exists benchmarks") | |
self._cursor.execute("drop table if exists results") | |
self._cursor.execute('CREATE TABLE benchmarksuites(id integer \ | |
PRIMARY KEY AUTOINCREMENT, name text, description text)') | |
self._cursor.execute('CREATE TABLE \ | |
benchmarks(checksum text PRIMARY KEY, \ | |
name text, description text, suite_id integer, \ | |
FOREIGN KEY(suite_id) REFERENCES benchmarksuites(id))') | |
self._cursor.execute('CREATE TABLE results(id integer \ | |
PRIMARY KEY AUTOINCREMENT, checksum text, \ | |
timestamp timestamp, ncalls text, timing float, traceback text,\ | |
FOREIGN KEY(checksum) REFERENCES benchmarks(checksum))') | |
self._con.commit() | |
def write_benchmark(self, bm, suite=None): | |
""" | |
""" | |
if suite is not None: | |
self._cursor.execute('SELECT id FROM benchmarksuites \ | |
where name = "%s"' % suite.name) | |
row = self._cursor.fetchone() | |
else: | |
row = None | |
if row == None: | |
self._cursor.execute('INSERT INTO benchmarks VALUES (?, ?, ?, ?)', | |
(bm.checksum, bm.name, bm.description, None)) | |
else: | |
self._cursor.execute('INSERT INTO benchmarks VALUES (?, ?, ?, ?)', | |
(bm.checksum, bm.name, bm.description, row[0])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment