Created
March 24, 2019 20:19
-
-
Save cagbal/d697bd5969d16f3af0e9d8549b82fa57 to your computer and use it in GitHub Desktop.
push back vs emplace back arasındaki fark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <chrono> | |
| using namespace std; | |
| int main() | |
| { | |
| // 2 Boş vektör oluşturalım | |
| vector<pair<int, int>> cok_buyuk_vector_arka, | |
| cok_buyuk_vector_on; | |
| // 500000 tane eleman ekleyeceğiz | |
| int N = 500000; | |
| // Arkaya 50000 elemanı ekleyelim | |
| auto basla = chrono::steady_clock::now(); | |
| for (int i = 0; i < N; i++) { | |
| cok_buyuk_vector_arka.push_back(pair<int, int>(4,3)); | |
| } | |
| auto bitis = chrono::steady_clock::now(); | |
| cout << "push_back milisaniye cinsinden: "<< | |
| chrono::duration_cast<chrono::milliseconds>(bitis - basla).count() | |
| << endl; | |
| // Öne eklemeyi yapalım | |
| basla = chrono::steady_clock::now(); | |
| for (int i = 0; i < N; i++) { | |
| cok_buyuk_vector_on.emplace_back(4,3); | |
| } | |
| bitis = chrono::steady_clock::now(); | |
| cout << "emplace_back milisaniye cinsinden: "<< | |
| chrono::duration_cast<chrono::milliseconds>(bitis - basla).count() | |
| << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment