All pastes #839977 Raw Edit

Miscellany

public text v1 · immutable
#839977 ·published 2007-12-31 11:30 UTC
rendered paste body
#include <list>
#include <set>
#include <algorithm>
using namespace std;

#define CSIZE 1000
#define ADDSIZE 40
#define REPEAT_ADD 1000
#define REPEAT_FIND 100

#define TESTINSERT(x,y) s = clock(); for(j = 0; j < REPEAT_ADD; j++) { x.clear(); for(i = 0; i < ADDSIZE; i++) x.y(c[i]);} e = clock(); printf("Time: %f\n", (float)(e-s)/(float)CLK_TCK);
 

void main()
{
    list<int> a;
    set<int> b;

    srand(clock());
    int c[CSIZE], i,j;
    for(i = 0; i < CSIZE; i++)
        c[i] = rand() % 100;

    clock_t s, e;

    TESTINSERT(a,push_back);
    TESTINSERT(b,insert);

    int found;
    s = clock();
    for(j = 0; j < REPEAT_FIND; j++)
    {
        found = 0;
        for(i = 0; i < CSIZE; i++)
        {
            list<int>::iterator itr = find(a.begin(), a.end(), c[i]);
            if(itr != a.end()) found++;
        }
    }
    e = clock();
    printf("Time: %f Found: %d\n", (float)(e-s)/(float)CLK_TCK, found);

    s = clock();
    for(j = 0; j < REPEAT_FIND; j++)
    {
        found = 0;
        for(i = 0; i < CSIZE; i++)
        {
            set<int>::iterator itr = b.find(c[i]);
            if(itr != b.end()) found++;
        }
    }
    e = clock();
    printf("Time: %f Found: %d\n", (float)(e-s)/(float)CLK_TCK, found);

    getch();
}