Skip to content

Instantly share code, notes, and snippets.

@Enhex
Created August 1, 2015 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Enhex/9c8cf1f614267565189b to your computer and use it in GitHub Desktop.
Save Enhex/9c8cf1f614267565189b to your computer and use it in GitHub Desktop.
#include <chrono>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <Urho3D/Urho3D.h>
#include <Urho3D/Container/Vector.h>
#include <Urho3D/Container/HashMap.h>
#include <Urho3D/Container/Str.h>
using namespace std;
using namespace std::chrono;
int main()
{
auto start = high_resolution_clock::now();
auto finish = high_resolution_clock::now();
{
// Vector int insert
int n = 100000;
cout << "vector int insert " << n << " elements" << endl;
// std
cout << "std:" << endl;
start = high_resolution_clock::now();
vector<int> std;
for (int i = 0; i < n; ++i)
std.emplace_back(i);
finish = high_resolution_clock::now();
auto std_time = duration_cast<microseconds>(finish - start).count();
cout << std_time << "us" << endl;
// urho
cout << "urho:" << endl;
start = high_resolution_clock::now();
Urho3D::Vector<int> urho;
for (int i = 0; i < n; ++i)
urho.Push(i);
finish = high_resolution_clock::now();
auto urho_time = duration_cast<microseconds>(finish - start).count();
cout << urho_time << "us" << endl << endl;
if (std_time < urho_time)
{
auto ratio = (double)urho_time / std_time;
auto percent = (ratio-1) * 100;
cout << "std is " << percent << "% faster";
}
else if (std_time > urho_time)
{
auto ratio = (double)std_time / urho_time;
auto percent = (ratio - 1.0) * 100;
cout << "urho is " << percent << "% faster";
}
cout << endl << endl;
}
{
// Vector string insert
int n = 100000;
cout << "vector string create & insert " << n << " elements" << endl;
// std
cout << "std:" << endl;
start = high_resolution_clock::now();
vector<string> std;
for (int i = 0; i < n; ++i)
std.emplace_back(to_string(i));
finish = high_resolution_clock::now();
auto std_time = duration_cast<microseconds>(finish - start).count();
cout << std_time << "us" << endl;
// urho
cout << "urho:" << endl;
start = high_resolution_clock::now();
Urho3D::Vector<Urho3D::String> urho;
for (int i = 0; i < n; ++i)
urho.Push(Urho3D::String(i));
finish = high_resolution_clock::now();
auto urho_time = duration_cast<microseconds>(finish - start).count();
cout << urho_time << "us" << endl << endl;
if (std_time < urho_time)
{
auto ratio = (double)urho_time / std_time;
auto percent = (ratio - 1) * 100;
cout << "std is " << percent << "% faster";
}
else if (std_time > urho_time)
{
auto ratio = (double)std_time / urho_time;
auto percent = (ratio - 1.0) * 100;
cout << "urho is " << percent << "% faster";
}
cout << endl << endl;
}
{
// hash map insert
int n = 100000;
cout << "hash map int insert " << n << " elements" << endl;
// std
cout << "std:" << endl;
start = high_resolution_clock::now();
unordered_map<int, int> std;
for (int i = 0; i < n; ++i)
std[i] = i;
finish = high_resolution_clock::now();
auto std_time = duration_cast<microseconds>(finish - start).count();
cout << std_time << "us" << endl;
// urho
cout << "urho:" << endl;
start = high_resolution_clock::now();
Urho3D::HashMap<int, int> urho;
for (int i = 0; i < n; ++i)
urho[i] = i;
finish = high_resolution_clock::now();
auto urho_time = duration_cast<microseconds>(finish - start).count();
cout << urho_time << "us" << endl << endl;
if (std_time < urho_time)
{
auto ratio = (double)urho_time / std_time;
auto percent = (ratio - 1) * 100;
cout << "std is " << percent << "% faster";
}
else if (std_time > urho_time)
{
auto ratio = (double)std_time / urho_time;
auto percent = (ratio - 1.0) * 100;
cout << "urho is " << percent << "% faster";
}
cout << endl << endl;
}
{
// hash map insert
int n = 100000;
cout << "hash map string create & insert " << n << " elements" << endl;
// std
cout << "std:" << endl;
start = high_resolution_clock::now();
unordered_map<string, string> std;
for (int i = 0; i < n; ++i)
{
auto s = to_string(i);
std[s] = s;
}
finish = high_resolution_clock::now();
auto std_time = duration_cast<microseconds>(finish - start).count();
cout << std_time << "us" << endl;
// urho
cout << "urho:" << endl;
start = high_resolution_clock::now();
Urho3D::HashMap<Urho3D::String, Urho3D::String> urho;
for (int i = 0; i < n; ++i)
{
auto s = Urho3D::String(i);
urho[s] = s;
}
finish = high_resolution_clock::now();
auto urho_time = duration_cast<microseconds>(finish - start).count();
cout << urho_time << "us" << endl << endl;
if (std_time < urho_time)
{
auto ratio = (double)urho_time / std_time;
auto percent = (ratio - 1) * 100;
cout << "std is " << percent << "% faster";
}
else if (std_time > urho_time)
{
auto ratio = (double)std_time / urho_time;
auto percent = (ratio - 1.0) * 100;
cout << "urho is " << percent << "% faster";
}
cout << endl << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment