GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


vector vs c-array test by godecho
1
 
#include <iostream>
#include <vector>
#include <ctime>


using::std::vector;
using::std::cout;
using::std::endl;

int main(int argc, char **argv)
{

        const unsigned int ARRAY_SIZE = 10000000;

        unsigned int            c_array[ARRAY_SIZE];
        vector<unsigned int>    v_array;

        v_array.resize(ARRAY_SIZE);


        unsigned int    c_start,
                        c_end,
                        v_start,
                        v_end;

        unsigned int temp = 0;

        c_start = clock();
        for(int x = 0; x < ARRAY_SIZE; ++x)
        {
                temp += c_array[x];                     // generic lame operation
        }
        c_end = clock();

        v_start = clock();
        for(int x = 0; x < ARRAY_SIZE; ++x)
        {
                temp += v_array[x];                     // generic lame operation
        }
        v_end = clock();

        cout << "speed for standard c-array: "  << c_end - c_start << endl;
        cout << "speed for stl array: "         << v_end - v_start << endl;


        return 0;
}