?? c_shm_merge_t.cpp
字號:
#include <share_mem/c_shm.h>
#include <share_mem/c_shm_merge.h>
#include <collect/global.h>
#include <cc++/thread.h>
int itemComp1( const void *arg1, const void *arg2 )
{
return strcmp( ((SHM_MERGE_LIST*)arg1)->main, ((SHM_MERGE_LIST*)arg2)->main);
}
int itemComp2( const void *arg1, const void *arg2 )
{
return strcmp( (char*)arg1, (char*)arg2 );
}
int main(int argc, char *argv[])
{
if( argc < 2 )
{
printf("Usage: %s option \n", argc );
printf( "測試添加數據 c_shm_merge_t 1 share_area_id mem_name \n"
"測試顯示數據 c_shm_merge_t 2 share_area_id mem_name acc_nbr \n"
"測試顯示數據 c_shm_merge_t 3 share_area_id mem_name \n");
exit(1);
}
int opt = atoi(argv[1]);
dbConnect( "DB_CONFIG_COLLECT_IBAS" );
c_shm m_serv(atoi(argv[2]));
c_shm_mem* shm_mem;
c_shm_merge* p_shm_merge;
int test = 0;
double dbltest = 0;
char cvalue1[200],cvalue2[200],cvalue3[200];
int ival1, ival2, ival3;
char temp1[6500000][20], temp2[6500000][4], temp3[6500000][4];
int count, i, j, returntmp;
char add_record[6500000][28];
struct timeval first, second, lapsed;
int record_count;
void* p_field;
void* pe1;
int seq = 0;
char* c_find;
SHM_MERGE_LIST shm_find;
SHM_MERGE_LIST* p_find;
int item_size = sizeof(SHM_MERGE_LIST);
SHM_MERGE_LIST_ITEM* p_list;
switch(opt)
{
case 1:
//添加數據
m_serv.getshm();
p_shm_merge = (c_shm_merge*)m_serv.get_mem(argv[3]);
cout<<"get ok!!!!"<<endl;
//p_shm_merge = (c_shm_merge*)shm_mem;
p_shm_merge->setMainKey(0);
p_shm_merge->setItemKey(1);
p_shm_merge->setItem(2);
g_statement.setSQLString("select acc_nbr,acct_item_type_id,amount from ibasuser.acct_item where rownum < 300" );
//where rownum < 30 where acc_nbr = '83489853' or acc_nbr = '36243782'
g_statement.execute();
i = 0;
count = 0;
SysTime::getTimeOfDay( &first ) ;
while( g_statement>>temp1[count]>>ival2>>ival1 )
{
memcpy(temp3[count], &ival1, sizeof(int));
memcpy(temp2[count], &ival2, sizeof(int));
//cout<<temp1[count]<<"|"<<*((int*)(temp2[count]))<<"|"<<ival1<<endl;
//strcpy( add_record[count], temp1[count]);
//memcpy( &(add_record[count][20]), &ival2, 4);
//memcpy( &(add_record[count][24]), &ival1, 4);
//cout<<add_record[count]<<"\t"<<*(int*)&(add_record[count][20])<<"\t"<<*(int*)&(add_record[count][24])<<endl;
count ++;
}
cout<<"load data ok!"<<endl;
SysTime::getTimeOfDay( &second ) ;
if (first.tv_usec > second.tv_usec)
{
second.tv_usec += 1000000;
second.tv_sec--;
}
lapsed.tv_usec = second.tv_usec - first.tv_usec;
lapsed.tv_sec = second.tv_sec - first.tv_sec;
cout<<"發生秒數:"<<lapsed.tv_sec<<endl;
cout<<"發生微秒數:"<<lapsed.tv_usec<<endl;
system("date");
SysTime::getTimeOfDay( &first ) ;
for( j = 0; j < 1; j ++ )
{
for ( i = 0 ; i < count ; i ++ )
{
p_shm_merge->SetData(0, temp1[i]);
p_shm_merge->SetData(1, temp2[i]);
p_shm_merge->SetData(2, temp3[i]);
if( p_shm_merge->appendElement( ) < 0 )
//if( p_shm_merge->appendElement( add_record[i] ) < 0 )
{
cout<<"load count error1:"<<i<<endl;
return -1;
}
}
system("date");
}
cout<<"load count:"<<i<<endl;
/*
while( g_statement>>cvalue1 )
{
p_shm_merge->SetData(i, cvalue1);
i ++;
if( i >= p_shm_merge->p_share_mem_info->field_count )
{
count ++;
i = 0;
if( p_shm_merge->appendElement( ) < 0 )
{
cout<<"load count error1:"<<count<<endl;
return -1;
}
}
}
if ( i > 0 )
{
count ++;
if( p_shm_merge->appendElement( ) < 0 )
{
cout<<"load count error2:"<<count<<endl;
return -1;
}
}
cout<<"load count:"<<count<<endl;
*/
SysTime::getTimeOfDay( &second ) ;
if (first.tv_usec > second.tv_usec)
{
second.tv_usec += 1000000;
second.tv_sec--;
}
lapsed.tv_usec = second.tv_usec - first.tv_usec;
lapsed.tv_sec = second.tv_sec - first.tv_sec;
cout<<"添加數據 發生秒數:"<<lapsed.tv_sec<<endl;
cout<<"發生微秒數:"<<lapsed.tv_usec<<endl;
/*
cout<<"display item list:"<<endl;
for ( j = 0 ; j < 60 ; j ++ )
{
cout<<j<<"\t"
<<p_shm_merge->p_merge_addition->p_merge_list_item[j].key<<"\t"
<<p_shm_merge->p_merge_addition->p_merge_list_item[j].fee<<"\t"
<<p_shm_merge->p_merge_addition->p_merge_list_item[j].next_pos<<endl;
}
cout<<"display accr list 0 :"<<endl;
for ( j = 0 ; j < 20 ; j ++ )
{
cout<<j<<"\t"
<<p_shm_merge->p_merge_item[0]->p_merge_list[j].main<<"\t"
<<p_shm_merge->p_merge_item[0]->p_merge_list[j].item_pos<<endl;
}
*/
/*cout<<"display accr list 1:"<<endl;
for ( j = 0 ; j < 20 ; j ++ )
{
cout<<j<<"\t"
<<p_shm_merge->p_merge_item[1]->p_merge_list[j].main<<"\t"
<<p_shm_merge->p_merge_item[1]->p_merge_list[j].item_pos<<endl;
}*/
cout<<"display record_count"<<endl;
for( i = 0 ; i < 10; i ++ )
cout<<i<<":"<<p_shm_merge->p_merge_item[i]->p_merge_info->add_record_count<<"\t"
<<p_shm_merge->p_merge_item[i]->p_merge_info->record_count<<"\t"
<<p_shm_merge->p_merge_item[i]->p_merge_info->unsort_find_count<<endl;
break;
case 2:
//顯示數據
m_serv.getshm();
p_shm_merge = (c_shm_merge*)m_serv.get_mem(argv[3]);
cout<<"get ok!!!!"<<endl;
//p_shm_merge = (c_shm_merge*)shm_mem;
p_shm_merge->setMainKey(0);
p_shm_merge->setItemKey(1);
p_shm_merge->setItem(2);
SysTime::getTimeOfDay( &first ) ;
//p_shm_merge->displayElement( "33039162" );
//p_shm_merge->displayElement( argv[4] );
p_shm_merge->getMainElement( argv[4] );
p_list = p_shm_merge->getNext();
while( p_list != NULL )
{
for(i=0; i<p_list->ele_count; i++)
{
printf("key:%d, fee:%d, nextpos:%d\n", p_list->acctFee[i].key, p_list->acctFee[i].fee, p_list->next_pos);
}
p_list = p_shm_merge->getNext();
}
SysTime::getTimeOfDay( &second ) ;
if (first.tv_usec > second.tv_usec)
{
second.tv_usec += 1000000;
second.tv_sec--;
}
lapsed.tv_usec = second.tv_usec - first.tv_usec;
lapsed.tv_sec = second.tv_sec - first.tv_sec;
cout<<"顯示數據 發生秒數:"<<lapsed.tv_sec<<endl;
cout<<"發生微秒數:"<<lapsed.tv_usec<<endl;
break;
case 3:
//測試速度
m_serv.getshm();
p_shm_merge = (c_shm_merge*)m_serv.get_mem(argv[3]);
cout<<"get ok!!!!"<<endl;
//p_shm_merge = (c_shm_merge*)shm_mem;
p_shm_merge->setMainKey(0);
p_shm_merge->setItemKey(1);
p_shm_merge->setItem(2);
g_statement.setSQLString("select acc_nbr,acct_item_type_id,amount from ibasuser.acct_item ");
//where rownum < 20 where acc_nbr = '83489853' or acc_nbr = '36243782'
g_statement.execute();
i = 0;
count = 0;
SysTime::getTimeOfDay( &first ) ;
while( g_statement>>temp1[count]>>ival2>>ival1 )
{
memcpy(temp3[count], &ival1, sizeof(int));
memcpy(temp2[count], &ival2, sizeof(int));
//cout<<temp1[count]<<"|"<<itemp2[count]<<"|"<<ival1<<endl;
count ++;
}
cout<<"load data ok!"<<endl;
SysTime::getTimeOfDay( &second ) ;
if (first.tv_usec > second.tv_usec)
{
second.tv_usec += 1000000;
second.tv_sec--;
}
lapsed.tv_usec = second.tv_usec - first.tv_usec;
lapsed.tv_sec = second.tv_sec - first.tv_sec;
cout<<"發生秒數:"<<lapsed.tv_sec<<endl;
cout<<"發生微秒數:"<<lapsed.tv_usec<<endl;
//count = 6234484;
system("date");
SysTime::getTimeOfDay( &first ) ;
for( j = 0; j < 5; j ++ )
{
//memcpy( shm_find.main, "36243781", MAX_MAIN_LENGTH);
for ( i = 0 ; i < count ; i ++ )
{
seq = p_shm_merge->getMergeItemSeq( temp1[i] );
p_find = p_shm_merge->p_merge_item[seq]->find( temp1[i] );
//p_find = p_shm_merge->p_merge_item[0]->find( temp1[i] );
//p_find = (SHM_MERGE_LIST*)bsearch(&shm_find, p_shm_merge->p_merge_item[8]->p_merge_list, p_shm_merge->p_merge_item[0]->p_merge_info->record_count, item_size, itemComp1);
if( p_find != NULL )
{
record_count++;
}
//if( i%1000000 == 0 )
//{
// system("date");
//}
}
system("date");
}
cout<<"find:"<<record_count<<endl;
SysTime::getTimeOfDay( &second ) ;
if (first.tv_usec > second.tv_usec)
{
second.tv_usec += 1000000;
second.tv_sec--;
}
lapsed.tv_usec = second.tv_usec - first.tv_usec;
lapsed.tv_sec = second.tv_sec - first.tv_sec;
cout<<"發生秒數:"<<lapsed.tv_sec<<endl;
cout<<"發生微秒數:"<<lapsed.tv_usec<<endl;
for ( i = 0; i < p_shm_merge->p_merge_item[0]->p_merge_info->record_count; i ++ )
{
strcpy( temp3[i], p_shm_merge->p_merge_item[8]->p_merge_list[i].main );
}
SysTime::getTimeOfDay( &first ) ;
for( j = 0; j < 5; j ++ )
{
//memcpy( shm_find.main, "36243781", MAX_MAIN_LENGTH);
for ( i = 0 ; i < count ; i ++ )
{
//seq = p_shm_merge->getMergeItemSeq( temp1[i] );
//p_find = p_shm_merge->p_merge_item[0]->find( temp1[5] );
c_find = (char*)bsearch(&(temp1[i]), temp3, p_shm_merge->p_merge_item[0]->p_merge_info->record_count, 30, itemComp2);
if( c_find != NULL )
{
record_count++;
}
//if( i%1000000 == 0 )
//{
// system("date");
//}
}
system("date");
}
cout<<"find:"<<record_count<<endl;
SysTime::getTimeOfDay( &second ) ;
if (first.tv_usec > second.tv_usec)
{
second.tv_usec += 1000000;
second.tv_sec--;
}
lapsed.tv_usec = second.tv_usec - first.tv_usec;
lapsed.tv_sec = second.tv_sec - first.tv_sec;
cout<<"發生秒數:"<<lapsed.tv_sec<<endl;
cout<<"發生微秒數:"<<lapsed.tv_usec<<endl;
cout<<"test ok:"<<i<<endl;
break;
default:
printf("沒有這個操作符\n");
break;
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -