Skip to content

Commit

Permalink
Including std::vector and std::deque in memory profile for reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
bingmann committed May 4, 2013
1 parent adb11e3 commit 205d7c4
Show file tree
Hide file tree
Showing 10 changed files with 93,095 additions and 85,226 deletions.
52 changes: 47 additions & 5 deletions memprofile/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <sys/time.h>
#include <sys/wait.h>
#include <assert.h>
#include <unistd.h>

#include <fstream>
#include <iostream>
Expand All @@ -32,6 +33,9 @@
#include <tr1/unordered_map>
#include <stx/btree_multimap.h>

#include <vector>
#include <deque>

#include "memprofile.h"

// *** Settings
Expand Down Expand Up @@ -91,6 +95,39 @@ struct TestFactory_Map

// --------------------------------------------------------------------------------

/// Test a generic array type with insertions
template <typename ArrayType>
struct Test_Array_Insert
{
Test_Array_Insert(unsigned int) {}

inline void run(unsigned int items)
{
ArrayType array;

srand(randseed);
for(unsigned int i = 0; i < items; i++) {
unsigned int r = rand();
array.push_back( std::make_pair(r,r) );
}

assert( array.size() == items );
}
};

/// Construct different array types for a generic test class
template < template<typename ArrayType> class TestClass >
struct TestFactory_Array
{
/// Test the vector from STL
typedef TestClass< std::vector< std::pair<unsigned int, unsigned int> > > StdVector;

/// Test the deque from STL
typedef TestClass< std::deque< std::pair<unsigned int, unsigned int> > > StdDeque;
};

// --------------------------------------------------------------------------------

template <typename TestClass>
void write_memprofile(const char* filename)
{
Expand Down Expand Up @@ -121,12 +158,17 @@ void write_memprofile(const char* filename)
/// Create memory usage profiles
int main()
{
typedef TestFactory_Map<Test_Map_Insert> testfactory_type;
typedef TestFactory_Map<Test_Map_Insert> testmap_type;

write_memprofile< testmap_type::StdMap >("memprofile-stdmap.txt");
write_memprofile< testmap_type::HashMap >("memprofile-hashmap.txt");
write_memprofile< testmap_type::UnorderedMap >("memprofile-unorderedmap.txt");
write_memprofile< testmap_type::BtreeMap >("memprofile-btreemap.txt");

typedef TestFactory_Array<Test_Array_Insert> testarray_type;

write_memprofile< testfactory_type::StdMap >("memprofile-stdmap.txt");
write_memprofile< testfactory_type::HashMap >("memprofile-hashmap.txt");
write_memprofile< testfactory_type::UnorderedMap >("memprofile-unorderedmap.txt");
write_memprofile< testfactory_type::BtreeMap >("memprofile-btreemap.txt");
write_memprofile< testarray_type::StdVector >("memprofile-vector.txt");
write_memprofile< testarray_type::StdDeque >("memprofile-deque.txt");

return 0;
}
6 changes: 5 additions & 1 deletion memprofile/memprofile.gnuplot
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set style line 1 linecolor rgbcolor "#FF0000" linewidth 1.6 pointsize 0.7
set style line 2 linecolor rgbcolor "#00C000" linewidth 1.6 pointsize 0.7
set style line 3 linecolor rgbcolor "#0000FF" linewidth 1.6 pointsize 0.7
set style line 4 linecolor rgbcolor "#E000E0" linewidth 1.6 pointsize 0.7
set style line 5 linecolor rgbcolor "#00C0FF" linewidth 1.6 pointsize 0.7
set style line 6 linecolor rgbcolor "#FFC000" linewidth 1.6 pointsize 0.7
set style increment user

set terminal pdf size 5, 3.5
Expand All @@ -21,4 +23,6 @@ set ylabel "Memory Usage [MiB]"
plot "memprofile-stdmap.txt" using 1:($2 / 1024/1024) title "std::multimap" with lines, \
"memprofile-hashmap.txt" using 1:($2 / 1024/1024) title "__gnu_cxx::hash_multimap" with lines, \
"memprofile-unorderedmap.txt" using 1:($2 / 1024/1024) title "std::tr1::unordered_multimap" with lines, \
"memprofile-btreemap.txt" using 1:($2 / 1024/1024) title "stx::btree_multimap" with lines
"memprofile-btreemap.txt" using 1:($2 / 1024/1024) title "stx::btree_multimap" with lines, \
"memprofile-vector.txt" using 1:($2 / 1024/1024) title "std::vector" with lines, \
"memprofile-deque.txt" using 1:($2 / 1024/1024) title "std::deque" with lines
Loading

0 comments on commit 205d7c4

Please sign in to comment.