相关疑难解决方法(0)

为什么SQLAlchemy使用sqlite插入比直接使用sqlite3慢25倍?

为什么这个简单的测试用例使用SQLAlchemy插入100,000行比直接使用sqlite3驱动程序慢25倍?我在实际应用程序中看到了类似的减速.难道我做错了什么?

#!/usr/bin/env python
# Why is SQLAlchemy with SQLite so slow?
# Output from this program:
# SqlAlchemy: Total time for 100000 records 10.74 secs
# sqlite3:    Total time for 100000 records  0.40 secs


import time
import sqlite3

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String,  create_engine 
from sqlalchemy.orm import scoped_session, sessionmaker

Base = declarative_base()
DBSession = scoped_session(sessionmaker())

class Customer(Base):
    __tablename__ = "customer"
    id = Column(Integer, primary_key=True)
    name = Column(String(255))

def init_sqlalchemy(dbname = 'sqlite:///sqlalchemy.db'):
    engine  = create_engine(dbname, echo=False) …
Run Code Online (Sandbox Code Playgroud)

python sqlite orm sqlalchemy

76
推荐指数
2
解决办法
3万
查看次数

标签 统计

orm ×1

python ×1

sqlalchemy ×1

sqlite ×1