Ejemplo n.º 1
0
    void randomizedTest() {
        const int cycles = 10000;
        const int valueRange = 1000;
        const int removeProbability = 40; //Percent

        TestSet set;
        srand(time(nullptr));
        for(int a = 0; a < cycles; ++a) {
            if(a % (cycles / 10) == 0) {
                qDebug() << "cycle" << a;
            }

            bool remove = (rand() % 100) < removeProbability;
            if(remove && set.size()) {
                set.remove(set.getItem(rand() % set.size()));
            }else{
                int value = (rand() % valueRange) + 1;
                set.add(value);
            }
            set.verify();
        }
        qDebug() << "Performance embedded list: insertion:" << toSeconds(emb_insertion) << "removal:" << toSeconds(emb_removal) << "contains:" << toSeconds(emb_contains) << "iteration:" << toSeconds(emb_iteration);
        qDebug() << "Performance std::set: insertion:" << toSeconds(std_insertion) << "removal:" << toSeconds(std_removal) << "contains:" << toSeconds(std_contains) << "iteration:" << toSeconds(std_iteration);
    }