⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 patricia_sql.cpp

📁 全新的纯内存式实时数据库
💻 CPP
字号:
/******************************************************************* *                                                                 * *  testperf.cpp                                                      * *                                                                 * *  This file is a part of the eXtremeDB source code               * *  Copyright (c) 2001-2007 McObject LLC                           *  *  All Rights Reserved                                            * *                                                                 * *******************************************************************/#include "mcosql.h"#include "patriciadb.h"#include "platform.h"using namespace McoSql;#ifndef MCO_PLATFORM_X64size_t const PAGE_SIZE = 128; // define eXtremeDB page sizeconst size_t DATABASE_SIZE = 256*1024 * 1024;#elsesize_t const PAGE_SIZE = 256;const size_t DATABASE_SIZE = 256* 1024 * 1024;#endif/* If you change the number of objects inserted, make sure that you * first have enough memory (DBSIZE), and also decalred hash table * size appropriatelly (hkey[estimated_numeber_of_entries] in perf2.mco */const int nRecords = 100000;const int IPMaskBits = 17;int main() {    int i;    char buf[128];    time_t start_time;    McoSqlEngine engine;    uint64_t key;    int routeTableSize = 1 << IPMaskBits;    int* routeTable = new int[routeTableSize];    memset(routeTable, 0, sizeof(int)*routeTableSize);    engine.open("patriciadb", patriciadb_get_dictionary(), DATABASE_SIZE, PAGE_SIZE);                /* insert Records */    printf("Insert ");    start_time = msec();    key = 1999;    for (i=0; i < nRecords; i++) {        key = (3141592621u*key + 2718281829u) % 1000000007u;        unsigned int  ip = (unsigned int)key;        routeTable[ip >> (32 - IPMaskBits)] += 1;        sprintf(buf, "%" INT8_FORMAT "u*", key);        engine.executeStatement("insert into Call (id,ip,phone) values (%i,%u,%s)", i, ip, buf);        if (i%(nRecords/10)==0) {            printf (".");        }            }        printf(" %d objects: %d milliseconds (%d microsecs/object)\n",           nRecords, (int)(msec() - start_time), (int)(((msec() - start_time) * 1000)/nRecords));        /* hash search */    printf("IP lookup");	long tt=0;    start_time = msec();    for (i = 0; i < routeTableSize; i++) {		DataSource* source = engine.executeQuery("select ip from Call where ip exact_match %i count %i", i, IPMaskBits);		int n;		Cursor* iterator = source->records();		for (n = 0; iterator->hasNext(); n++) { 			Record* rec = iterator->next();			uint64_t val = rec->get(0)->intValue();			assert((val >> (32 - IPMaskBits)) == i);		}		assert(n == routeTable[i]);		source->release();		tt++;		//tt+=n?n:1;        if (i%(routeTableSize/10)==0) {            printf (".");        }    }//      printf("% d lookups: %d milliseconds (%d microsecs/search)\n",//             routeTableSize, (int)(msec() - start_time ), (int)(((msec() - start_time) * 1000)/routeTableSize));     printf("% d lookups: %d milliseconds (%d microsecs/search)\n",		 tt, (int)(msec() - start_time ), (int)(((msec() - start_time) * 1000)/tt));            /* tree search */    printf("Phone prefix lookup ");    start_time = msec();    key = 1999;    for (i = 0; i < nRecords; i++) {        key = (3141592621u*key + 2718281829u) % 1000000007u;        sprintf(buf, "%" INT8_FORMAT "u*%" INT8_FORMAT "u", key, key);        DataSource* source = engine.executeQuery("select id from Call where phone prefix_match %s", buf);        Cursor* iterator = source->records();        assert(iterator->hasNext());        Record* rec = iterator->next();        assert(rec->get(0)->intValue() == i);        //assert(!iterator->hasNext());        source->release();        if (i%(nRecords/10)==0) {            printf (".");        }            }    printf(" %d lookups: %d milliseconds (%d microsecs/search)\n",           nRecords, (int)(msec() - start_time ), (int)(((msec() - start_time) * 1000)/nRecords));        engine.close();    printf( "\nPress Enter to exit" );    getchar();    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -