Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <vector>
- using namespace std;
- int main()
- {
- clock_t t1;
- clock_t t2;
- t1 = clock();
- for( int t = 0; t < 1000; t++ )
- {
- vector<int> a;
- a.reserve(100000);
- for( int i = 0; i < 100000; i++ )
- a.push_back(i);
- }
- t2 = clock();
- cout << (t2-t1) / (double)CLOCKS_PER_SEC << endl;
- t1 = clock();
- for( int t = 0; t < 1000; t++ )
- {
- vector<int> a;
- for( int i = 0; i < 100000; i++ )
- a.push_back(i);
- }
- t2 = clock();
- cout << (t2-t1) / (double)CLOCKS_PER_SEC << endl;
- return 0;
- }
- /*
- TESTED OUTPUT:
- (with -O3)
- 0.27953
- 0.599311
- (default)
- 1.56081
- 1.9982
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement