#include <set>
#include <chrono>
#include <iostream>
using Time = std::chrono::high_resolution_clock;
using ms = std::chrono::milliseconds;
int main()
{
std::set<int> initialSet;
for (int i = 0; i < 5000000; ++i) {
initialSet.insert(i);
}
std::set<int> setFilledWithForInsert;
{
const auto start = Time::now();
for (const int value: initialSet) {
setFilledWithForInsert.insert(value);
}
std::cout << "Insert: " << std::chrono::duration_cast<ms>(Time::now() - start).count() << "\n";
}
std::set<int> setFilledWithForEmplaceHint;
{
const auto start = Time::now();
auto it = setFilledWithForEmplaceHint.cend();
for (const int value: initialSet) {
it = setFilledWithForEmplaceHint.emplace_hint(it, value);
}
std::cout << "EmplaceHint: " << std::chrono::duration_cast<ms>(Time::now() - start).count() << "\n";
}
std::set<int> setFilledWithForInsertHint;
{
const auto start = std::chrono::system_clock::now();
auto it = setFilledWithForEmplaceHint.cend();
for (const int value: initialSet) {
it = setFilledWithForInsertHint.insert(it, value);
}
std::cout << "InsertHint: " << std::chrono::duration_cast<ms>(Time::now() - start).count() << "\n";
}
std::set<int> setFilledWithIterators;
{
const auto start = std::chrono::system_clock::now();
setFilledWithIterators.insert(initialSet.cbegin(), initialSet.cend());
std::cout << "InsertIterators: " << std::chrono::duration_cast<ms>(Time::now() - start).count() << "\n";
}
return 0;
}