本文整理汇总了C++中DB::db_insert方法的典型用法代码示例。如果您正苦于以下问题:C++ DB::db_insert方法的具体用法?C++ DB::db_insert怎么用?C++ DB::db_insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB::db_insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insert_number
void insert_number(unsigned long count, DB& database) {
unsigned long fail_count = 0;
auto write_start = std::chrono::steady_clock::now();
for (unsigned long i = 1; i <= count ; i++) {
char buf[50];
sprintf_s<50>(buf, "%lu", i);
if (database.db_insert(buf, buf) != 0) {
++fail_count;
}
if (i % 10000 == 0) {
// print out the elapsed time
auto write_end = std::chrono::steady_clock::now();
auto write_elapsed = std::chrono::duration_cast<std::chrono::seconds>(write_end - write_start);
cout << "written: " << i - 9999 << " - " << i << endl;
cout << "used time: " << write_elapsed.count() << " (seconds)" << endl;
cout << endl;
string key_str(buf);
test_fetch(i, database);
write_start = std::chrono::steady_clock::now();
}
}
}
示例2: test
void test() {
DB db = "testdb";
std::time_t startALL, finishALL;
double duration = 0;
char buf[50];
int nrec = 1000;
vector<int> v;
for (int i = 0; i<nrec; i++) { v.push_back(i); }
startALL = clock();
for (int i = 0; i<nrec; i++) {
sprintf_s<50>(buf, "%d", i);
db.db_insert(buf, buf);
//cout<<i<<endl;
}
for (int i = 0; i<nrec; i++) {
sprintf_s<50>(buf, "%d", i);
cout << db.db_fetch(buf);
//cout<<i<<endl;
}
cout << "test: part A completed" << endl;
for (int i = 0; i<5 * nrec; i++) {
int randnum = rand() % v.size();
sprintf_s<50>(buf,"%d", v[randnum]);
if (i % 37 == 0) { db.db_delete(buf); }
else if (i % 11 == 0) {
int temp = v[randnum] + nrec;
sprintf_s<50>(buf, "%d", temp);
db.db_insert(buf, buf);
v.push_back(temp);
cout << db.db_fetch(buf) << endl;
}
else if (i % 17 == 0) {
sprintf_s<50>(buf, "%d", v[randnum]);
db.db_replace(buf, "??");
}
}
cout << "test: part B completed" << endl;
for (int i : v) {
int randnum = rand() % v.size();
sprintf_s<50>(buf, "%d", v[randnum]);
db.db_delete(buf);
for (int i = 0; i<10; i++) {
randnum = rand() % nrec;
sprintf_s<50>(buf, "%d", randnum);
cout << db.db_fetch(buf) << endl;
}
}
cout << "ok";
finishALL = clock();
duration = (finishALL - startALL) / (double)CLOCKS_PER_SEC;
cout << "test used time: " << duration << endl;
}