I've looked into this task for some time and found it difficult to compare
them. Attached is a version with integers as keys. I haven't done real
tests with it yet.
Regards
Daniel
//
// main.cpp
// test.cpp
//
// Created by Lucas Prieels on 12/12/17.
// Copyright © 2017 Lucas Prieels. All rights reserved.
//
#define ll long long
#include "bu.h"
#include "bu/hash.h"
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
void addValueBu(bu_hash_tbl* tab, int nbr){
int key = 0;
for (int i=0; i<nbr; i++){
bu_hash_set(tab, (const uint8_t *) &key, 4, NULL);
key++;
}
}
void addAndPopValueBu(bu_hash_tbl* tab, int nbr){
int key = 0;
for (int i=0; i<nbr; i++){
bu_hash_set(tab, (const uint8_t *) &key, 4, NULL);
bu_hash_rm(tab, (const uint8_t *) &key, 4);
key++;
}
}
void addAndRetrieveValueBu(bu_hash_tbl* tab, int nbr){
int key = 0;
for (int i=0; i<nbr; i++){
bu_hash_set(tab, (const uint8_t *) &key, 4, NULL);
char* t=(char *)bu_hash_get(tab, (const uint8_t *) &key, 4);
key++;
}
}
void bu_hash(int nb){
bu_hash_tbl* tab=bu_hash_create(nb);
cout << -1;
ll int start = bu_gettime();
addValueBu(tab, nb);
ll int time2=bu_gettime();
addAndPopValueBu(tab, nb);
ll int time3=bu_gettime();
addAndRetrieveValueBu(tab, nb);
cout << "Time of execution for bu_hash: " << endl << "Adding " << nb << " values : " << time2-start << endl << "Adding and popping " << nb << " values : " << time3-time2 << endl << "Adding and retrieving " << nb << " values : " << bu_gettime()-time3 << endl << endl;
}
void addValueSTL(unordered_map<int, void*> &m, int nb){
int key = 0;
for (int i=0; i<nb; i++){
m[key]=NULL;
key++;
}
}
void addAndPopValueSTL(unordered_map<int, void*> &m, int nb){
int key = 0;
for (int i=0; i<nb; i++){
m[key]=NULL;
m.erase(key);
key++;
}
}
void addAndRetrieveValueSTL(unordered_map<int, void*> &m, int nb){
int key = 0;
for (int i=0; i<nb; i++){
m[key]=NULL;
void* a=m[key];
key++;
}
}
void stl_map(int nb){
unordered_map<int, void*> m;
ll int start = bu_gettime();
addValueSTL(m, nb);
ll int time2=bu_gettime();
addAndPopValueSTL(m, nb);
ll int time3=bu_gettime();
addAndRetrieveValueSTL(m, nb);
cout << "Time of execution for STL map: " << endl << "Adding " << nb << " values : " << time2-start << endl << "Adding and popping " << nb << " values : " << time3-time2 << endl << "Adding and retrieving " << nb << " values : " << bu_gettime()-time3 << endl << endl;
}
int main(int ac, char *av[]) {
int nb;
cout << "How many values would you like to test? " << endl;
cin >> nb;
cout << -1;
bu_hash(nb);
stl_map(nb);
return 0;
}
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
BRL-CAD Developer mailing list
brlcad-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-devel