Question

I wrote a script to benchmark insertions and deletes.

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)

On Windows it printed

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

On Mac it printed

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

Why is it so much faster on Mac? Is it because Mac uses HFS+ and Windows uses NTFS?

Was it helpful?

Solution

Apparently SQLite performace on Mac vs Win has been a recurring issue. See this discussionfrom 2012.

One key feature seems to be sync parameters.

from the discussion:

On Windows Sqlite by default uses the real/full fsyncs to the hardware as provided by the OS, while on at least OS/X, by default it doesn't. See http://sqlite.org/pragma.html#pragma_fullfsync

Can you try running with pragma sync = off?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top