測試環境:
intel xeon 2.4g四核心 2.5g記憶體
server 2003 enterprise edition service pack 2
oracle9i enterprise edition 9.2.0.1.0
python-2.5.2
元件cx_oracle-4.3.1-win32-9i-py25
建立測試表:
create table test
(test_id number(10, 0),
test_name varchar2(50),
test_time timestamp,
test_value number(10, 3)
);
連線oracle過程略。
幾個測試用的方法:
拼sql入庫:
def ******insert(total):
time.sleep(3)
currentstr = time.strftime("%y-%m-%d %h:%m:%s")
connora = cx_oracle.connect(connstr)
begin = time.time()
cursorora = connora.cursor()
for i in range(1, total+1):
sqlstr = "insert into test (test_id, test_name, test_time, test_value) values (%s, '%s', to_date('%s','yyyy-mm-dd hh24:mi:ss'), %s)"%(i, genstring(5), currentstr, gendouble())
cursorora.execute(sqlstr)
connora.commit()
end = time.time()
print "count:%s time:%s"%(total, end - begin)
cursorora.close()
connora.close()
測試結果:
[i]count:20480 time:34.7809998989
count:20480 time:34.8599998951
count:20480 time:35.6400001049
count:20480 time:35.375
count:20480 time:35.9060001373
count:20480 time:34.9690001011
count:20480 time:35.7179999352
count:20480 time:35.1879999638
count:20480 time:36.4690001011
count:20480 time:35.1870000362[/i]
總結:平均入庫速度每1萬條17.29秒
繫結引數法入庫:
def traditionalinsert(total):
time.sleep(3)
cst = time.localtime()
current = datetime.datetime(cst[0], cst[1], cst[2], cst[3], cst[4], cst[5])
connora = cx_oracle.connect(connstr)
begin = time.time()
cursorora = connora.cursor()
cursorora.prepare("insert into test (test_id, test_name, test_time, test_value) values (:1, :2, :3, :4)")
for i in range(1, total+1):
cursorora.execute(none, (i, genstring(5), current, gendouble()))
connora.commit()
end = time.time()
print "count:%s time:%s"%(total, end - begin)
cursorora.close()
connora.close()
測試結果:
[i]count:51200 time:28.2030000687
count:51200 time:28.5160000324
count:51200 time:26.7349998951
count:51200 time:27.0309998989
count:51200 time:27.3910000324
count:51200 time:35.4370000362
count:51200 time:26.9070000648
count:51200 time:29.375
count:51200 time:27.7350001335
count:51200 time:27.5309998989[/i]
總結:平均入庫速度每1萬條5.56秒
陣列繫結法入庫:
測試結果:
[i]count:1024000 time:36.5779998302
count:1024000 time:35.375
count:1024000 time:37.6559998989
count:1024000 time:34.9060001373
count:1024000 time:36.5779998302
count:1024000 time:37.625
count:1024000 time:35.2809998989
count:1024000 time:36.1570000648
count:1024000 time:36.4219999313
count:1024000 time:37.1879999638[/i]
總結:平均入庫速度每100萬條35.52秒
陣列繫結法的注意事項:陣列長度最好要小於65535。
python中有乙個timeit專門用來測試**執行時間的,有空可以用一用。
聽說有個cython外掛程式,**稍加改動就可以大幅提高速度,有空可以試試。
Oracle入庫速度測試 C 版
測試環境 intel xeon 2.4g四核心 2.5g記憶體 server 2003 enterprise edition service pack 2 oracle9i enterprise edition 9.2.0.1.0 microsoft visual studio 2008 元件ora...
oracle資料入庫
oracle資料入庫 注意 先要處理檔案中的分隔符 將資料分列 建立為標準的sql語句 1.在oracle資料庫中建立要入庫的表如果有該錶則不用建立 注 建立欄位的資料型別要符合實際邏輯 varchar2欄位最大為4000 2.把csv檔案放入到伺服器上的資料夾中 要和ctl檔案放到一塊 3.cmd...
oracle資料入庫
oracle資料入庫 注意 先要處理檔案中的分隔符 將資料分列 建立為標準的sql語句 1.在oracle資料庫中建立要入庫的表如果有該錶則不用建立 注 建立欄位的資料型別要符合實際邏輯 varchar2欄位最大為4000 2.把csv檔案放入到伺服器上的資料夾中 要和ctl檔案放到一塊 3.cmd...