Skip to content

Instantly share code, notes, and snippets.

@jubnzv
Created August 23, 2020 18:28
Show Gist options
  • Save jubnzv/b890f024288bcd084f406ac5368d7220 to your computer and use it in GitHub Desktop.
Save jubnzv/b890f024288bcd084f406ac5368d7220 to your computer and use it in GitHub Desktop.
#include <chrono>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
class A {
public:
A(int Data) : Data(Data) {}
private:
int Data;
};
int main(int argc, char *argv[])
{
std::map<short, std::shared_ptr<A>> elements;
for (short i = 0; i < std::numeric_limits<short>::max(); i++) {
elements.emplace(i, std::make_shared<A>(i));
}
{
auto start__ = std::chrono::high_resolution_clock::now();
std::size_t count = 0;
for (const auto el : elements) {
count += 1;
}
auto end__ = std::chrono::high_resolution_clock::now();
std::cout << __func__ << ":" << __LINE__ << ": "
<< std::chrono::duration_cast<std::chrono::nanoseconds>(
end__ - start__)
.count()
<< "ns" << std::endl;
}
{
auto start__ = std::chrono::high_resolution_clock::now();
std::size_t count = 0;
for (const auto &el : elements) {
count += 1;
}
auto end__ = std::chrono::high_resolution_clock::now();
std::cout << __func__ << ":" << __LINE__ << ": "
<< std::chrono::duration_cast<std::chrono::nanoseconds>(
end__ - start__)
.count()
<< "ns" << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment