为什么Windows 7上的插入和删除操作比Mac 10.9长100倍以上? [英] Why do insertions and deletes take over 100 times longer on windows 7 than Mac 10.9?

查看:44
本文介绍了为什么Windows 7上的插入和删除操作比Mac 10.9长100倍以上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个脚本来对插入和删除进行基准测试.

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)

在Windows上它已打印

On Windows it printed

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?

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

推荐答案

显然,Mac vs Win上的SQLite性能一直是一个反复出现的问题.请参见2012年以来的 .

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

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

One key feature seems to be sync parameters.

来自讨论:

在Windows上,Sqlite默认使用对硬件的真实/完整fsync由操作系统提供,但至少在OS/X上为默认设置.请参见 http://sqlite.org/pragma.html#pragma_fullfsync

您可以尝试在pragma sync = off下运行吗?

Can you try running with pragma sync = off?

这篇关于为什么Windows 7上的插入和删除操作比Mac 10.9长100倍以上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆