I have an array of 100 elements called "items"
Python (take about 1 sec):
for item in items:
cur.execute("INSERT INTO list VALUES (?)",(item,))
db.commit()
C++ (9 sec):
for ( auto it = items.begin(); it != items.end(); ++it ) {
qry.prepare("INSERT INTO list VALUES (?)");
std::string item = *it;
qry.addBindValue(item);
qry.exec();
C++ without prepare
(9 sec):
for ( auto it = items.begin(); it != items.end(); ++it ) {
std::string item = *it;
qry.exec("INSERT INTO list VALUES ('"+item+"')");
Basically my question is whether there is a way to use insert
in C++ as fast as in Python.