Ai
1 Star 0 Fork 0

zdevt/cpptest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sqlite32.cpp 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
zdevt 提交于 2023-08-13 12:48 +08:00 . up
#include <iostream>
#include <string>
#include <sstream>
#include <time.h>
#include <strings.h>
#include <string.h>
#include "sqlite3.h"
const int nCount = 500000;
int main ( int argc, char** argv )
{
sqlite3* db;
sqlite3_open ( "testdb.db", &db );
sqlite3_exec ( db, "PRAGMA synchronous = OFF; ", 0, 0, 0 );
sqlite3_exec ( db, "drop table if exists t1", 0, 0, 0 );
sqlite3_exec ( db, "create table t1(id integer,x integer,y integer ,weight real)", 0, 0, 0 );
clock_t t1 = clock();
sqlite3_exec ( db, "begin;", 0, 0, 0 );
sqlite3_stmt* stmt;
const char* sql = "insert into t1 values(?,?,?,?)";
sqlite3_prepare_v2 ( db, sql, strlen ( sql ), &stmt, 0 );
for ( int i = 0; i < nCount; ++i )
{
// std::stringstream ssm;
// ssm<<"insert into t1 values("<<i<<","<<i*2<<","<<i/2<<","<<i*i<<")";
// sqlite3_exec(db,ssm.str().c_str(),0,0,0);
sqlite3_reset ( stmt );
sqlite3_bind_int ( stmt, 1, i );
sqlite3_bind_int ( stmt, 2, i * 2 );
sqlite3_bind_int ( stmt, 3, i / 2 );
sqlite3_bind_double ( stmt, 4, i * i );
sqlite3_step ( stmt );
}
sqlite3_finalize ( stmt );
sqlite3_exec ( db, "commit;", 0, 0, 0 );
clock_t t2 = clock();
sqlite3_close ( db );
std::cout << 1000.0 / ( ( t2 - t1 ) / 1000.0 ) *nCount << " rec/s" << std::endl;
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zdevt/cpptest.git
git@gitee.com:zdevt/cpptest.git
zdevt
cpptest
cpptest
master

搜索帮助