Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Tablice.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <cstdlib>
- #include <string>
- #include <time.h>
- #include <algorithm>
- #include <vector>
- #include <Windows.h>
- #include <ctime>
- using namespace std;
- /*
- Dla 1k elementów czas wyniósł 133ms
- Dla 10k elementów czas wyniósł 1109ms
- Dla 100k elementów czas wyniósł 10488ms
- Dla 1mln elementów czas wyniósł 106828ms
- Dla 10mln elementów czas wyniósł 990203ms
- */
- double start() {
- double czas;
- czas = clock();
- return czas;
- }
- double koniec(double start) {
- double czas;
- czas = clock() - start;
- return czas / CLOCKS_PER_SEC;
- }
- int main()
- {
- double czas;
- int min = 20, max = -20;
- vector < int > tab;
- srand(time(NULL));
- czas = start();
- for (int i = 0; i < 10000000; i++) {
- tab.push_back(rand() % 41 - 20);
- cout << tab[i] << " ";
- if (min > tab[i])
- min = tab[i];
- if (max < tab[i])
- max = tab[i];
- }
- czas = koniec(czas);
- cout << endl;
- cout << "Tworzenie tablicy zajelo " << czas << " sekund" << endl;
- cout << "Max=" << max << endl;
- cout << "Min=" << min << endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement