📄 main.c
字号:
/***************************************************************** * * * Copyright (c) 2001-2007 McObject LLC. All Right Reserved. * * * *****************************************************************//* This test allows to receive some results about the eXtremeDB performance * for all basic operations. This test inserts N objects into a class, creating * a hash index as it does insertions; then separatelly builds a tree index, * performs searches using a tree and a hash table, an a sequential search. * At last the tree is removed and all the object are deleted one-by-one. * Each Insetrtion and deletion done in a separate transaction, so the * commit time is included in the measurements. */#include <platform.h>#include <stdio.h>#include <stdlib.h>#include <string.h>//#include <mcoHA.h>#include "perf2.h"/* Make sure you've got this 16M, otherwise you'll be measuring * the performance of your disk. */#define DBSIZE ( 1024 * 16000 )#ifndef MCO_PLATFORM_X64#define PAGESIZE 128#else#define PAGESIZE 256#endifconst int MAP_ADDRESS = 0x20000000;/* 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;void _SH_(void) { char text[] = { "\nThis test allows to receive some results about the eXtremeDB\n" "performance for all basic operations. This test inserts N objects\n" "into a class, creating a hash index as it does insertions; then\n" "separatelly builds a tree index,performs searches using a tree and\n" "a hash table, an a sequential search.At last the tree is removed\n" "and all the object are deleted one-by-one. Each insertion and deletion\n" "done in a separate transaction, so the commit time is included in the\n" "measurements.\n" }; char text1[] = { "Copyright (c) 2001-2007 McObject LLC. All Right Reserved.\n\n" }; printf("%s\neXtremeDB runtime version %d.%d, build %d\n%s\n\nPress Enter to start", text, MCO_COMP_VER_MAJOR, MCO_COMP_VER_MINOR, MCO_COMP_BUILD_NUM,text1); getchar();}static void errhandler( int n ) { printf( "\neXtremeDB runtime fatal error: %d", n ); getchar(); exit( -1 );}int main( void ) { const char *dbName = "perf2"; time_t start_time; MCO_RET rc; mco_db_h db = 0; mco_trans_h t; int i; long n = 0; Record rec; mco_cursor_t c; uint4 key = 1999; void *start_mem; mco_runtime_info_t info; _SH_(); mco_get_runtime_info( &info); if ( info.mco_shm_supported ) { start_mem = (void*)MAP_ADDRESS; } else { start_mem = (void*)malloc(DBSIZE); if (!start_mem) { printf("Couldn't allocated memory\n"); exit (1); } }; mco_error_set_handler( &errhandler ); rc= mco_runtime_start(); rc = mco_db_open( dbName, perf2_get_dictionary(), start_mem, DBSIZE, (uint2) PAGESIZE ); if ( rc ) { printf( "\nerror %d creating database", rc ); if ( !info.mco_shm_supported ) free( start_mem ); exit( 1); } /* connect to the database, obtain a database handle */ mco_db_connect( dbName, &db ); /* insert Records, don't create the tree index yet */ printf("Insert "); Sleep(20); start_time = msec(); for (i=0; i < nRecords; i++) { key = (3141592621u*i + 2718281829u) % 1000000007u; rc = mco_trans_start( db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t ); if( MCO_S_OK != rc ) exit(1); rc = Record_new(t, &rec); Record_key_put(&rec, key); rc = mco_trans_commit(t); if (!rc ) n++; if (i%(nRecords/10)==0) printf ("."); } printf(" %d objects: %d milliseconds,(%d microsecs/object)\n", n, (int)(msec() - start_time), ((msec() - start_time) * 1000)/n); /* create the tree index */ Sleep(20); rc = mco_trans_start( db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t ); if( MCO_S_OK != rc ) { if ( !info.mco_shm_supported ) free( start_mem ); exit(1); }; printf("Creating tree ...... "); start_time = msec(); rc = Record_tkey_create (t); mco_trans_commit(t); if ( rc == MCO_S_OK ) { printf(" %d objects: %d milliseconds (%d microsecs/object)\n", nRecords, (int)(msec() - start_time ), ((msec() - start_time) * 1000)/nRecords); } else { printf( "Unable to create voluntary index. Error code %d\n", rc ); }; /* hash search */ Sleep(20); rc = mco_trans_start( db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t ); if( MCO_S_OK != rc ) { if ( !info.mco_shm_supported ) free( start_mem ); exit(1); }; printf("Hash search "); start_time = msec(); for (i=0; i < nRecords; i++) { key = (3141592621u*i + 2718281829u) % 1000000007u; rc = Record_hkey_find(t, key, &rec); if (i%(nRecords/10)==0) printf ("."); } printf("% d searches: %d milliseconds (%d microsecs/search)\n", nRecords, (int)(msec() - start_time ), ((msec() - start_time) * 1000)/nRecords); mco_trans_commit(t); /* tree search */ Sleep(20); printf("Tree search "); start_time = msec(); rc = mco_trans_start( db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t ); rc = Record_tkey_index_cursor(t, &c ); if ( rc == MCO_S_OK ) { for (i=0; i < nRecords; i++) { key = (3141592621u*i + 2718281829u) % 1000000007u; Record_tkey_search( t, &c, MCO_EQ, key ); if (i%(nRecords/10)==0) printf ("."); } printf(" %d searches: %d milliseconds (%d microsecs/search)\n", nRecords, (int)(msec() - start_time ), ((msec() - start_time) * 1000)/nRecords); } else { printf( "Unable to open a cursor on voluntary index. Error code %d\n", rc ); } mco_trans_commit(t); /* cursor movements */ Sleep(20); printf("Sequential "); start_time=msec(); rc = mco_trans_start( db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t ); rc = Record_tkey_index_cursor(t, &c ); if ( rc == MCO_S_OK ) { for (n = 0,rc = mco_cursor_first(t, &c); rc == MCO_S_OK; rc = mco_cursor_next(t, &c)) { if (n%(nRecords/10)==0) printf ("."); n++; } printf(" %d searches: %d milliseconds (%d microsecs/search)\n", n, (int)(msec() - start_time ), ((msec() - start_time) * 1000)/n); } else { printf( "Unable to open a cursor on voluntary index. Error code %d\n", rc ); } mco_trans_commit(t); /* removing the tree */ rc = mco_trans_start( db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t ); if( MCO_S_OK != rc ) { if ( !info.mco_shm_supported ) free( start_mem ); exit(1); }; printf("Removing the tree ...... "); start_time = msec(); rc = Record_tkey_drop (t); mco_trans_commit(t); if ( rc == MCO_S_OK ) printf(" %d milliseconds\n", (int)(msec() - start_time )); else printf( "Unable to drop a voluntary index. Error code %d\n", rc ); /* Search using hash index and remove the object ones found */ printf("Search/delete "); start_time = msec(); for (n=0,i=0; i < nRecords; i++) { key = (3141592621u*i + 2718281829u) % 1000000007u; rc = mco_trans_start( db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t ); if( MCO_S_OK != rc ) exit(1); rc = Record_hkey_find(t, key, &rec); if ( rc == MCO_S_OK ) rc = Record_delete(&rec); else break; rc = mco_trans_commit(t); if (!rc) n++; if (n%(nRecords/10)==0) printf ("."); } printf(" %d objects: %d milliseconds (%d microsecs/object)\n", n, (int)(msec() - start_time ), ((msec() - start_time) * 1000)/n); /* disconnect from the database, db is no longer valid */ mco_db_disconnect( db ); /* destroy the database */ mco_db_close( dbName ); mco_runtime_stop(); if ( !info.mco_shm_supported ) free( start_mem ); printf( "\nPress Enter to exit" ); getchar(); PROG_EXIT(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -