diff options
author | michele.simionato <devnull@localhost> | 2008-12-16 07:10:04 +0000 |
---|---|---|
committer | michele.simionato <devnull@localhost> | 2008-12-16 07:10:04 +0000 |
commit | 1e91027df00128d4dbb67bde30cc10db0eefe529 (patch) | |
tree | 0ee7fe6519e8f96a1b7b939e099499131c6d33f0 /sqlplain | |
parent | c3cda745e6a7893fac41ca52472aee35eb73318a (diff) | |
download | micheles-1e91027df00128d4dbb67bde30cc10db0eefe529.tar.gz |
Added a test to check the performance difference in insertion
Diffstat (limited to 'sqlplain')
-rw-r--r-- | sqlplain/tests/test_million.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/sqlplain/tests/test_million.py b/sqlplain/tests/test_million.py new file mode 100644 index 0000000..d5d325f --- /dev/null +++ b/sqlplain/tests/test_million.py @@ -0,0 +1,45 @@ +import os, tempfile +from random import random +from datetime import date, timedelta +from sqlplain import do, util, table + +db = util.create_db('postgres_test', force=True) + +CREATE_PRICE_TABLE = ''' + CREATE TABLE price( + code CHAR(4), + date DATE, + price FLOAT + ); + ALTER TABLE price ADD PRIMARY KEY (code, date); +''' + +insert_price = table.insert_row('price', 'code date price') + +rows, fname = [], '' + +def create_values(ncodes, ndates): + global fname + tmp, fname = tempfile.mkstemp() + today = date.today() + for i in range(ncodes): + for j in range(ndates): + code = '%04d' % i + day = today - timedelta(j) + value = 1 + random() + rows.append((code, day, value)) + os.write(tmp, '%s,%s,%s\n' % (code, day, value)) + os.close(tmp) + return rows + +def setup(): + db.execute(CREATE_PRICE_TABLE) + create_values(10, 10) + +def test_insert(): + for row in rows: + insert_price(db, row) + +def test_bulk_insert(): + do('TRUNCATE TABLE price') + util.bulk_insert(db, file(fname), 'price', sep=',') |