📄 testindex.cpp
字号:
//-< TESTINDEX.CPP >-------------------------------------------------*--------*// FastDB Version 1.0 (c) 1999 GARRET * ? *// (Main Memory Database Management System) * /\| *// * / \ *// Created: 10-Dec-98 K.A. Knizhnik * / [] \ *// Last update: 20-Jan-99 K.A. Knizhnik * GARRET *//-------------------------------------------------------------------*--------*// Performance test for index and sequential searches// Performance test for index searches//-------------------------------------------------------------------*--------*#include "fastdb.h"#include <stdio.h>USE_FASTDB_NAMESPACEconst int nRecords = 100000;const int arraySize = 100;class Record { public: db_int8 intKey; char const* strKey; TYPE_DESCRIPTOR((KEY(intKey, HASHED), KEY(strKey, INDEXED)));};REGISTER(Record);#ifdef _WIN32#define GET_TIME() GetTickCount()#else#define GET_TIME() time(NULL)#endifint main(int argc, char* argv[]){ int i, j, n; char strKey[32]; db_int8 intKey; dbArray<db_int8> keyArr; dbDatabase db; if (db.open("testindex")) { dbQuery q1, q2, q3; dbCursor<Record> cursor1; dbCursor<Record> cursor2; q1 = "intKey=",intKey; q2 = "strKey=",strKey;#if defined(_MSC_VER) && _MSC_VER+0 < 1300 q3.add("strKey=").append(dbQueryElement::qVarArrayOfInt8, &keyArr);#else q3 = "intKey in",keyArr;#endif db_nat8 key = 1999; unsigned start = GET_TIME(); for (i = 0; i < nRecords; i++) { Record rec; key = (3141592621u*key + 2718281829u) % 1000000007u; sprintf(strKey, INT8_FORMAT ".", key); rec.strKey = strKey; rec.intKey = (db_int8)key; insert(rec); } db.commit(); printf("Elapsed time for inserting %d record: %d\n", nRecords, int(GET_TIME() - start)); start = GET_TIME(); key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621u*key + 2718281829u) % 1000000007u; sprintf(strKey, INT8_FORMAT ".", key); intKey = (db_int8)key; n = cursor1.select(q1); assert(n == 1); n = cursor2.select(q1); assert(n == 1); assert(cursor1.currentId() == cursor2.currentId()); } printf("Elapsed time for %d index searches: %d\n", nRecords*2, int(GET_TIME() - start)); start = GET_TIME(); key = 1999; keyArr.resize(arraySize); db_int8* items = (db_int8*)keyArr.base(); for (i = 0; i < nRecords/arraySize; i++) { for (j = 0; j < arraySize; j++) { key = (3141592621u*key + 2718281829u) % 1000000007u; items[j] = (db_int8)key; } n = cursor1.select(q3); assert(n == arraySize); } printf("Elapsed time for %d 'in' searches: %d\n", nRecords/arraySize, int(GET_TIME() - start)); start = GET_TIME(); key = 1999; for (i = 0; i < nRecords; i++) { key = (3141592621u*key + 2718281829u) % 1000000007u; intKey = (db_int8)key; n = cursor1.select(q1, dbCursorForUpdate); assert(n == 1); cursor1.remove(); } printf("Elapsed time for deleting all %d records: %d\n", nRecords, int(GET_TIME() - start)); db.close(); return EXIT_SUCCESS; } else { printf("Failed to open database\n"); return EXIT_FAILURE; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -