Skip to content

Instantly share code, notes, and snippets.

@kumagi
Created June 16, 2012 11:21
Show Gist options
  • Save kumagi/2941063 to your computer and use it in GitHub Desktop.
Save kumagi/2941063 to your computer and use it in GitHub Desktop.
nanahan vs boost benchmark
#include <boost/chrono.hpp>
#include <boost/unordered_map.hpp>
#include "map.hpp"
using namespace boost;
using namespace chrono;
using namespace nanahan;
int main(void)
{
unordered_map<int, int> bmap;
Map<int, int> nmap;
static const size_t num = 30000000;
//*
std::cout << "insert:" << std::endl;
{
system_clock::time_point start = system_clock::now();
for (size_t i =0; i < num; ++i){
nmap.insert(std::make_pair(i,i));
}
duration<double> sec = system_clock::now() - start;
std::cout << " nanahan\t" << sec.count() << " seconds\n";
}
//*/
//*
{
system_clock::time_point start = system_clock::now();
for (size_t i =0; i < num; ++i){
bmap.insert(std::make_pair(i,i));
}
duration<double> sec = system_clock::now() - start;
std::cout << " boost \t" << sec.count() << " seconds\n";
}
//*
std::cout << "find:" << std::endl;
{
system_clock::time_point start = system_clock::now();
for (size_t i =0; i < num; ++i){
nmap.find(i);
}
duration<double> sec = system_clock::now() - start;
std::cout << " nanahan\t" << sec.count() << " seconds\n";
}
{
system_clock::time_point start = system_clock::now();
for (size_t i =0; i < num; ++i){
bmap.find(i);
}
duration<double> sec = system_clock::now() - start;
std::cout << " boost \t" << sec.count() << " seconds\n";
}
std::cout << "erase:" << std::endl;
{
system_clock::time_point start = system_clock::now();
for (size_t i =0; i < num; ++i){
nmap.erase(nmap.find(i));
}
duration<double> sec = system_clock::now() - start;
std::cout << " nanahan\t" << sec.count() << " seconds\n";
}
//*/
//*
{
system_clock::time_point start = system_clock::now();
for (size_t i =0; i < num; ++i){
bmap.erase(bmap.find(i));
}
duration<double> sec = system_clock::now() - start;
std::cout << " boost \t" << sec.count() << " seconds\n";
}
//*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment