Skip to content

Instantly share code, notes, and snippets.

@cagbal
Created March 24, 2019 20:19
Show Gist options
  • Save cagbal/d697bd5969d16f3af0e9d8549b82fa57 to your computer and use it in GitHub Desktop.
Save cagbal/d697bd5969d16f3af0e9d8549b82fa57 to your computer and use it in GitHub Desktop.

Revisions

  1. cagbal created this gist Mar 24, 2019.
    40 changes: 40 additions & 0 deletions push_backvsemplace_back.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #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;
    }