Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <list>
- #include <cstdlib>
- #include <ctime>
- #define SIZE 100
- #define ACCESSES 1000000
- void testArray(){
- int t = time(0);
- std::cout << "array: ";
- int a[SIZE];
- for (int i = 0; i != ACCESSES; ++i)
- a[rand() % SIZE] = rand();
- std::cout << time(0) - t << "s" << std::endl;
- }
- void testVector(){
- int t = time(0);
- std::cout << "vector: ";
- std::vector<int> a(SIZE);
- for (int i = 0; i != ACCESSES; ++i)
- a[rand() % SIZE] = rand();
- std::cout << time(0) - t << "s" << std::endl;
- }
- void testList(){
- int t = time(0);
- std::cout << "list: ";
- std::list<int> a(SIZE);
- for (int i = 0; i != ACCESSES; ++i){
- int index = rand() % SIZE;
- std::list<int>::iterator it = a.begin();
- for (int counter = 0; counter != index; ++counter, ++it)
- ;
- *it = rand();
- }
- std::cout << time(0) - t << "s" << std::endl;
- }
- int main(){
- for (int i = 0; i != 4; ++i){
- testArray();
- testVector();
- testList();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement