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

📄 testperf.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 "testperfdb.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 = 1024 * 32000;#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;int main() {    int i;    char buf[64];    time_t start_time;    McoSqlEngine engine;    uint64_t key;    engine.open("testperfdb", testperfdb_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;        sprintf(buf, "%" INT8_FORMAT "u", key);        engine.executeStatement("insert into T (intKey,strKey) values (%l,%s)", key, 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("Hash search ");    start_time = msec();    key = 1999;    for (i=0; i < nRecords; i++) {        key = (3141592621u*key + 2718281829u) % 1000000007u;        DataSource* source = engine.executeQuery("select * from T where intKey=%l", key);        Cursor* iterator = source->records();        assert(iterator->hasNext());        Record* rec = iterator->next();        assert(rec->get(0)->intValue() == (int64_t)key);        assert(!iterator->hasNext());        source->release();        if (i%(nRecords/10)==0) {            printf (".");        }    }    printf("% d searches: %d milliseconds (%d microsecs/search)\n",           nRecords, (int)(msec() - start_time ), (int)(((msec() - start_time) * 1000)/nRecords));            /* tree search */    printf("Tree search ");    start_time = msec();    key = 1999;    for (i=0; i < nRecords; i++) {        key = (3141592621u*key + 2718281829u) % 1000000007u;        sprintf(buf, "%" INT8_FORMAT "u", key);        DataSource* source = engine.executeQuery("select * from T where strKey=%s", buf);        Cursor* iterator = source->records();        assert(iterator->hasNext());        Record* rec = iterator->next();        assert(rec->get(0)->intValue() == (int64_t)key);        assert(!iterator->hasNext());        source->release();        if (i%(nRecords/10)==0) {            printf (".");        }            }    printf(" %d searches: %d milliseconds (%d microsecs/search)\n",           nRecords, (int)(msec() - start_time ), (int)(((msec() - start_time) * 1000)/nRecords));        /* cursor movements */    printf("Sequential ");    start_time=msec();    DataSource* source = engine.executeQuery("select * from T order by strKey");    Cursor* iterator = source->records();    int n = 0;    buf[0] = '\0';    while (iterator->hasNext()) {         Record* rec = iterator->next();        String* str = (String*)rec->get(1);        assert(str->compare(buf) > 0);                str->toString(buf, sizeof buf);        n += 1;    }    source->release();    assert(n == nRecords);    printf(" %d searches: %d milliseconds (%d microsecs/search)\n",           n, (int)(msec() - start_time ), (int)(((msec() - start_time) * 1000)/n));        /* Search using hash index and remove the object ones found */    printf("Search/delete ");        start_time = msec();    key = 1999;    for (i=0; i < nRecords; i++) {        key = (3141592621u*key + 2718281829u) % 1000000007u;        engine.executeStatement("delete from T where intKey=%l", key);        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));        engine.close();    printf( "\nPress Enter to exit" );    getchar();    return 0;}

⌨️ 快捷键说明

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