我一直试图看看使用内存中的sqlite和基于磁盘的sqlite是否有任何性能改进.基本上我想交换启动时间和内存来获得非常快速的查询,这些查询在应用程序过程中没有遇到磁盘.
但是,以下基准测试只能提高1.5倍的速度.在这里,我正在生成1M行随机数据并将其加载到同一个表的磁盘和基于内存的版本中.然后我在两个dbs上运行随机查询,返回大小约为300k的集合.我预计基于内存的版本要快得多,但如上所述,我只能获得1.5倍的加速.
我尝试了几种其他大小的dbs和查询集; 内存:优势也似乎上升为行的分贝数增加了.我不确定为什么优势如此之小,尽管我有一些假设:
我在这里做错了吗?关于原因的任何想法:内存:不会产生几乎即时的查找?这是基准:
==> sqlite_memory_vs_disk_benchmark.py <==
#!/usr/bin/env python
"""Attempt to see whether :memory: offers significant performance benefits.
"""
import os
import time
import sqlite3
import numpy as np
def load_mat(conn,mat):
c = conn.cursor()
#Try to avoid hitting disk, trading safety for speed.
#http://stackoverflow.com/questions/304393
c.execute('PRAGMA temp_store=MEMORY;')
c.execute('PRAGMA journal_mode=MEMORY;')
# Make a demo table
c.execute('create table if not exists demo (id1 int, id2 int, val real);')
c.execute('create index id1_index on demo …Run Code Online (Sandbox Code Playgroud)