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

📄 stress.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        printf("Comparison test failed 1\n");        exit(1);    }    bvect_full1.clear();    bvect_full2.clear();    bvect_min1.set_bit(10);    bvect_min2.set_bit(10);    bvect_full1.set_bit(10);    bvect_full2.set_bit(10);    res1 = bvect_min1.compare(bvect_min2);    res2 = bvect_full1.compare(bvect_full2);    if (res1 != res2)    {        printf("Comparison test failed 1\n");        exit(1);    }    printf("Comparison 2.\n");    bvect_min1.set_bit(11);    bvect_full1.set_bit(11);    res1 = bvect_min1.compare(bvect_min2);    res2 = bvect_full1.compare(bvect_full2);    if (res1 != res2 && res1 != 1)    {        printf("Comparison test failed 2\n");        exit(1);    }    res1 = bvect_min2.compare(bvect_min1);    res2 = bvect_full2.compare(bvect_full1);    if (res1 != res2 && res1 != -1)    {        printf("Comparison test failed 2.1\n");        exit(1);    }    printf("Comparison 3.\n");    bvect_full1.optimize();    res1 = bvect_min1.compare(bvect_min2);    res2 = bvect_full1.compare(bvect_full2);    if (res1 != res2 && res1 != 1)    {        printf("Comparison test failed 3\n");        exit(1);    }    res1 = bvect_min2.compare(bvect_min1);    res2 = bvect_full2.compare(bvect_full1);    if (res1 != res2 && res1 != -1)    {        printf("Comparison test failed 3.1\n");        exit(1);    }    printf("Comparison 4.\n");    bvect_full2.optimize();    res1 = bvect_min1.compare(bvect_min2);    res2 = bvect_full1.compare(bvect_full2);    if (res1 != res2 && res1 != 1)    {        printf("Comparison test failed 4\n");        exit(1);    }    res1 = bvect_min2.compare(bvect_min1);    res2 = bvect_full2.compare(bvect_full1);    if (res1 != res2 && res1 != -1)    {        printf("Comparison test failed 4.1\n");        exit(1);    }    printf("Comparison 5.\n");    unsigned i;    for (i = 0; i < 65536; ++i)    {        bvect_full1.set_bit(i);    }    res1 = bvect_min1.compare(bvect_min2);    res2 = bvect_full1.compare(bvect_full2);    if (res1 != res2 && res1 != 1)    {        printf("Comparison test failed 5\n");        exit(1);    }    bvect_full1.optimize();    res1 = bvect_min2.compare(bvect_min1);    res2 = bvect_full2.compare(bvect_full1);    if (res1 != res2 && res1 != -1)    {        printf("Comparison test failed 5.1\n");        exit(1);    }}void DesrializationTest2(){   bvect  bvtotal;   unsigned size = BITVECT_SIZE - 10;   bvect  bv1;   bvect  bv2;   int i;   for (i = 10; i < 165536; i+=2)   {      bv1.set_bit(i);   }   bv1.optimize();   bv1.stat();   struct bvect::statistics st1;   bv1.calc_stat(&st1);   unsigned char* sermem = new unsigned char[st1.max_serialize_mem];   unsigned slen2 = bv1.serialize(sermem);   assert(slen2);   slen2 = 0;   bvtotal.deserialize(sermem);   bvtotal.optimize();   for (i = 55000; i < 165536; ++i)   {      bv2.set_bit(i);   }   bv2.optimize();   bv2.stat();   struct bvect::statistics st2;   bv2.calc_stat(&st2);   unsigned char* sermem2 = new unsigned char[st2.max_serialize_mem];   unsigned slen = bv2.serialize(sermem2);   assert(slen);   slen = 0;   bvtotal.deserialize(sermem2);   bvtotal.stat();//   bvtotal.optimize(); //  bvtotal.stat();   bvtotal.deserialize(sermem2);   bvtotal.deserialize(sermem);   delete [] sermem;   delete [] sermem2;   bvtotal.clear();   int clcnt = 0;   int repetitions = 25;   for (i = 0; i < repetitions; ++i)   {        cout << endl << "Deserialization STEP " << i << endl;        bvect_mini*   bvect_min1= new bvect_mini(size);        bvect*        bvect_full1= new bvect();        FillSetsRandomMethod(bvect_min1, bvect_full1, 1, size, 1);       struct bvect::statistics st;       bvect_full1->calc_stat(&st);       unsigned char* sermem = new unsigned char[st.max_serialize_mem];       unsigned slen = bvect_full1->serialize(sermem);       unsigned char* smem = new unsigned char[slen];       ::memcpy(smem, sermem, slen);//       cout << "Serialized vector" << endl;//       bvect_full1->stat();//       cout << "Before deserialization" << endl;//       bvtotal.stat();       bvtotal.deserialize(smem);//       cout << "After deserialization" << endl;//       bvtotal.stat();       bvtotal.optimize();//       cout << "After optimization" << endl;//       bvtotal.stat();       if (++clcnt == 5)       {          clcnt = 0;          bvtotal.clear();//          cout << "Post clear." << endl;//          bvtotal.stat();       }       delete [] sermem;       delete [] smem;       delete bvect_min1;       delete bvect_full1;   } // for i}void StressTest(int repetitions){   unsigned RatioSum = 0;   unsigned SRatioSum = 0;   unsigned DeltaSum = 0;   unsigned SDeltaSum = 0;   unsigned clear_count = 0;   bvect  bvtotal;   bvtotal.set_new_blocks_strat(bm::BM_GAP);   cout << "----------------------------StressTest" << endl;   unsigned size = BITVECT_SIZE - 10;//size = BITVECT_SIZE / 10;   int i;   for (i = 0; i < repetitions; ++i)   {        cout << endl << " - - - - - - - - - - - - STRESS STEP " << i << endl;        switch (rand() % 3)        {        case 0:            size = BITVECT_SIZE / 10;            break;        case 1:            size = BITVECT_SIZE / 2;            break;        default:            size = BITVECT_SIZE - 10;            break;        } // switch        bvect_mini*   bvect_min1= new bvect_mini(size);        bvect_mini*   bvect_min2= new bvect_mini(size);        bvect*        bvect_full1= new bvect();        bvect*        bvect_full2= new bvect();        bvect_full1->set_new_blocks_strat(i&1 ? bm::BM_GAP : bm::BM_BIT);        bvect_full2->set_new_blocks_strat(i&1 ? bm::BM_GAP : bm::BM_BIT);        int opt = rand() % 2;        unsigned start1 = 0;        switch (rand() % 3)        {        case 1:            start1 += size / 5;            break;        default:            break;        }        unsigned start2 = 0;        switch (rand() % 3)        {        case 1:            start2 += size / 5;            break;        default:            break;        }/*        if (i == 3)        {            g_cnt_check = 1;        }*/        FillSetsRandomMethod(bvect_min1, bvect_full1, start1, size, opt);        FillSetsRandomMethod(bvect_min2, bvect_full2, start2, size, opt);        unsigned arr[bm::set_total_blocks]={0,};        bm::id_t cnt = bvect_full1->count();        unsigned last_block = bvect_full1->count_blocks(arr);        unsigned sum = bm::sum_arr(&arr[0], &arr[last_block+1]);        if (sum != cnt)        {            cout << "Error in function count_blocks." << endl;            cout << "Array sum = " << sum << endl;            cout << "BitCount = " << cnt << endl;            cnt = bvect_full1->count();            for (unsigned i = 0; i <= last_block; ++i)            {                if (arr[i])                {                    cout << "[" << i << ":" << arr[i] << "]";                }            }            cout << endl;            cout << "================" << endl;            bvect_full1->stat();            exit(1);        }        CheckCountRange(*bvect_full1, start1, BITVECT_SIZE, arr);        CheckIntervals(*bvect_full1, BITVECT_SIZE);                CheckCountRange(*bvect_full2, start2, BITVECT_SIZE);        CheckCountRange(*bvect_full1, 0, start1, arr);        CheckCountRange(*bvect_full2, 0, start2);/*                cout << "!!!!!!!!!!!!!!!" << endl;        CheckVectors(*bvect_min1, *bvect_full1, size);        cout << "!!!!!!!!!!!!!!!" << endl;        CheckVectors(*bvect_min2, *bvect_full2, size);        cout << "!!!!!!!!!!!!!!!" << endl;                  bvect_full1->stat();         cout << " --" << endl;         bvect_full2->stat();*/        int operation = rand()%4;//operation = 2;        switch(operation)        {        case 0:            cout << "Operation OR" << endl;            bvect_min1->combine_or(*bvect_min2);            break;        case 1:            cout << "Operation SUB" << endl;            bvect_min1->combine_sub(*bvect_min2);            break;        case 2:            cout << "Operation XOR" << endl;            bvect_min1->combine_xor(*bvect_min2);            break;        default:            cout << "Operation AND" << endl;            bvect_min1->combine_and(*bvect_min2);            break;        }        int cres1 = bvect_min1->compare(*bvect_min2);        delete bvect_min2;        switch(operation)        {        case 0:            {            cout << "Operation OR" << endl;            bm::id_t predicted_count = bm::count_or(*bvect_full1, *bvect_full2);                        bvect_full1->bit_or(*bvect_full2);                        bm::id_t count = bvect_full1->count();            if (count != predicted_count)            {                cout << "Predicted count error!" << endl;                cout << "Count = " << count << "Predicted count = " << predicted_count << endl;                exit(1);            }                        }            break;        case 1:            {            cout << "Operation SUB" << endl;                        bm::id_t predicted_count = bm::count_sub(*bvect_full1, *bvect_full2);                        bvect_full1->bit_sub(*bvect_full2);                        bm::id_t count = bvect_full1->count();            if (count != predicted_count)            {                cout << "Predicted count error!" << endl;                cout << "Count = " << count << "Predicted count = " << predicted_count << endl;                exit(1);            }                                    }            break;        case 2:            {            cout << "Operation XOR" << endl;                       bm::id_t predicted_count = bm::count_xor(*bvect_full1, *bvect_full2);                        bvect_full1->bit_xor(*bvect_full2);                        bm::id_t count = bvect_full1->count();            if (count != predicted_count)            {                cout << "Predicted count error!" << endl;                cout << "Count = " << count << "Predicted count = " << predicted_count << endl;                exit(1);            }                        }                        break;        default:            {            cout << "Operation AND" << endl;            bm::id_t predicted_count = bm::count_and(*bvect_full1, *bvect_full2);            bvect_full1->bit_and(*bvect_full2);            bm::id_t count = bvect_full1->count();            if (count != predicted_count)            {                cout << "Predicted count error!" << endl;                cout << "Count = " << count << "Predicted count = " << predicted_count << endl;                exit(1);            }            }            break;        }        cout << "Operation comparison" << endl;        CheckVectors(*bvect_min1, *bvect_full1, size);        int cres2 = bvect_full1->compare(*bvect_full2);        CheckIntervals(*bvect_full1, BITVECT_SIZE);        if (cres1 != cres2)        {            cout << cres1 << " " << cres2 << endl;            cout << bvect_full1->get_first() << " " << bvect_full1->count() << endl;            cout << bvect_full2->get_first() << " " << bvect_full2->count() << endl;           // bvect_full1->stat(1000);            cout << endl;           // bvect_full2->stat(1000);            printf("Bitset comparison operation failed.\n");            exit(1);        }        delete bvect_full2;        struct bvect::statistics st1;        bvect_full1->calc_stat(&st1);        bvect_full1->optimize();        bvect_full1->optimize_gap_size();        struct bvect::statistics st2;        bvect_full1->calc_stat(&st2);        unsigned Ratio = (st2.memory_used * 100)/st1.memory_used;        RatioSum+=Ratio;        DeltaSum+=st1.memory_used - st2.memory_used;        cout << "Optimization statistics: " << endl               << "   MemUsedBefore=" << st1.memory_used             << "   MemUsed=" << st2.memory_used              << "   Ratio=" << Ratio << "%"             << "   Delta=" << st1.memory_used - st2.memory_used             << endl;                        cout << "Optimization comparison" << endl;        CheckVectors(*bvect_min1, *bvect_full1, size);        bvect_full1->set_gap_levels(gap_len_table_min<true>::_len);        CheckVectors(*bvect_min1, *bvect_full1, size);        CheckIntervals(*bvect_full1, BITVECT_SIZE);        //CheckCountRange(*bvect_full1, 0, size);        // Serialization        bvect_full1->calc_stat(&st2);        cout << "Memory allocation: " << st2.max_serialize_mem << endl;        unsigned char* sermem = new unsigned char[st2.max_serialize_mem];//    bvect_full1->stat();        cout << "Serialization...";        unsigned slen = bvect_full1->serialize(sermem);        cout << "Ok" << endl;        delete bvect_full1;        unsigned SRatio = (slen*100)/st2.memory_used;        SRatioSum+=SRatio;        SDeltaSum+=st2.memory_used - slen;        cout << "Serialized mem_max = " << st2.max_serialize_mem              << " size= " << slen              << " Ratio=" << SRatio << "%"             << " Delta=" << st2.memory_used - slen             << e

⌨️ 快捷键说明

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