为什么在Windows 7上插入和删除的时间比Mac 10.9长100多倍?

我写了一个脚本来testing插入和删除。

import os, time abspath = os.path.abspath(os.path.dirname(__file__)) dbname = 'test.sqlite' # dbname = ':memory:' databaseFileName = os.path.join(abspath, dbname) if os.path.exists(databaseFileName): os.remove(databaseFileName) from sqlalchemy import \ Table, Column, MetaData, create_engine,\ Integer, DateTime engine = create_engine('sqlite:///' + dbname) metadata = MetaData() test = Table ('test', metadata, Column('id', Integer, primary_key=True) ) metadata.create_all(engine) conn = engine.connect() numRecords = 100 start = time.clock() for i in range(numRecords): conn.execute(test.insert()) print 'It took %s seconds to insert %s records' % ((time.clock() - start), numRecords) start = time.clock() for i in range(1, numRecords+1): conn.execute(test.delete().where(test.c.id == i)) print 'It took %s seconds to delete %s records' % ((time.clock() - start), numRecords) 

Windows上打印

 It took 5.32831616059 seconds to insert 100 records It took 6.76065831351 seconds to delete 100 records 

在Mac上打印

 It took 0.036788 seconds to insert 100 records It took 0.041629 seconds to delete 100 records 

为什么在Mac上这么快? 是因为Mac使用HFS +而Windows使用NTFS吗?

Solutions Collecting From Web of "为什么在Windows 7上插入和删除的时间比Mac 10.9长100多倍?"

显然,在Mac和Win上的SQLite性能一直是一个反复出现的问题。 请参阅2012年的讨论。

一个关键功能似乎是同步参数。

从讨论:

在Windows Sqlite默认情况下使用OS提供的硬件的真实/完整的fsyncs,而在OS / X上,默认情况下不会。 请参阅http://sqlite.org/pragma.html#pragma_fullfsync

你可以尝试与编译指示同步=关闭?