Browse files

Test memory when the range is greater

  • Loading branch information...
1 parent 2d345e7 commit 3c3d1d4bc4b88bf631341d7cae3a653bf99bde66 @wichtounet committed Apr 4, 2012
Showing with 42 additions and 0 deletions.
  1. +42 −0 src/memory.cpp
View
42 src/memory.cpp
@@ -3,6 +3,7 @@
#include <iostream>
#include <sstream>
#include <algorithm>
+#include <set>
//For reading memory usage
#include <stdio.h>
@@ -67,12 +68,53 @@ void memory(const std::string& name, int size){
}
}
+template<typename Tree>
+void memory_high(const std::string& name, unsigned int size){
+ std::mt19937_64 engine(time(0));
+
+ std::uniform_int_distribution<int> valueDistribution(0, INT_MAX);
+ auto valueGenerator = std::bind(valueDistribution, engine);
+
+ std::set<int> elements;
+ while(elements.size() < size){
+ elements.insert(valueGenerator());
+ }
+
+ struct proc_t usage1;
+ struct proc_t usage2;
+
+ //Lookup for usage
+ look_up_our_self(&usage1);
+
+ Tree tree;
+
+ //Fill the tree
+ for(auto i : elements){
+ tree.add(i);
+ }
+
+ //Lookup for usage
+ look_up_our_self(&usage2);
+
+ std::cout << name << "-" << size << " is using " << memory(usage2.vsize - usage1.vsize) << std::endl;
+
+ //Empty the tree
+ for(auto i : elements){
+ tree.remove(i);
+ }
+}
+
void test_memory_consumption(){
std::cout << "Test the memory consumption of each version" << std::endl;
std::vector<int> sizes = {1000, 10000, 100000, 1000000, 10000000};
for(auto size : sizes){
+ memory_high<skiplist::SkipList<int, 32>>("SkipList", size);
+ memory_high<nbbst::NBBST<int, 32>>("NBBST", size);
+ }
+
+ for(auto size : sizes){
memory<skiplist::SkipList<int, 32>>("SkipList", size);
memory<nbbst::NBBST<int, 32>>("NBBST", size);
}

0 comments on commit 3c3d1d4

Please sign in to comment.