为什么在插入数据库时​​python比c ++快?

时间:2018-09-13 18:41:30

标签: python c++ sqlite

我有一个由100个元素组成的数组,称为“项”

Python(大约需要1秒钟):

for item in items:
           cur.execute("INSERT INTO list VALUES (?)",(item,))
db.commit()

C ++(9秒):

for ( auto it = items.begin(); it != items.end(); ++it  ) {
    qry.prepare("INSERT INTO list VALUES (?)");
    std::string item = *it;
    qry.addBindValue(item);
    qry.exec();

没有prepare的C ++(9秒):

for ( auto it = items.begin(); it != items.end(); ++it  ) {
    std::string item = *it;
    qry.exec("INSERT INTO list VALUES ('"+item+"')");

基本上我的问题是,是否有一种方法可以在C ++中像在Python中一样快地使用insert

0 个答案:

没有答案