本文整理汇总了C++中DB::db_fetch方法的典型用法代码示例。如果您正苦于以下问题:C++ DB::db_fetch方法的具体用法?C++ DB::db_fetch怎么用?C++ DB::db_fetch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB::db_fetch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_fetch
void test_fetch(unsigned long last_key, DB& database) {
std::cout << "fetching: " << last_key - 100 << " - " << last_key << std::endl;
unsigned long count = 0;
auto start = std::chrono::steady_clock::now();
for (unsigned long i = last_key - 99; i <= last_key; ++i) {
string key_str = to_string(i);
string val = database.db_fetch(key_str);
if (val == "") {
cout << "cannot fetch: " << key_str;
}
count++;
}
auto end = std::chrono::steady_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start) / count;
std::cout << "It took me " << elapsed.count() << " microseconds in average." << std::endl;
cout << endl;
}
示例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;
}