当前位置: 首页>>代码示例>>C++>>正文


C++ DB::db_insert方法代码示例

本文整理汇总了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();

		}

	}

}
开发者ID:GhostatSpirit,项目名称:Database_bplustree,代码行数:33,代码来源:Database.cpp

示例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;

}
开发者ID:GhostatSpirit,项目名称:Database_bplustree,代码行数:64,代码来源:Database.cpp


注:本文中的DB::db_insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。