[Assorted-commits] SF.net SVN: assorted:[1148] container-bench
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-01-28 07:07:57
|
Revision: 1148 http://assorted.svn.sourceforge.net/assorted/?rev=1148&view=rev Author: yangzhang Date: 2009-01-28 07:07:48 +0000 (Wed, 28 Jan 2009) Log Message: ----------- added c++ container benchmark Added Paths: ----------- container-bench/ container-bench/trunk/ container-bench/trunk/README container-bench/trunk/src/ container-bench/trunk/src/Makefile container-bench/trunk/src/bench.cc container-bench/trunk/tools/ container-bench/trunk/tools/analysis.py Added: container-bench/trunk/README =================================================================== --- container-bench/trunk/README (rev 0) +++ container-bench/trunk/README 2009-01-28 07:07:48 UTC (rev 1148) @@ -0,0 +1,24 @@ +Overview +-------- + +Benchmark of various associative containers for C++. + +Part of the [H-Store] project, to determine the performance behavior of various +readily available options. + +Setup +----- + +Requirements: + +- [Boost] 1.37 +- [C++ Commons] + +[Boost]: http://boost.org/ +[C++ Commons]: http://assorted.sf.net/cpp-commons/ + +Analysis tools requirements: + +- [Matplotlib] 0.98.3 + +[Matplotlib]: http://matplotlib.sf.net/ Added: container-bench/trunk/src/Makefile =================================================================== --- container-bench/trunk/src/Makefile (rev 0) +++ container-bench/trunk/src/Makefile 2009-01-28 07:07:48 UTC (rev 1148) @@ -0,0 +1,9 @@ +CXXFLAGS += -O3 -Wall +BINS := bench + +all: $(BINS) + +clean: + rm -f $(BINS) + +.PHONY: clean Added: container-bench/trunk/src/bench.cc =================================================================== --- container-bench/trunk/src/bench.cc (rev 0) +++ container-bench/trunk/src/bench.cc 2009-01-28 07:07:48 UTC (rev 1148) @@ -0,0 +1,96 @@ +#include <map> +#include <iostream> +#include <vector> +#include <commons/rand.h> +#include <commons/time.h> +#include <stx/btree_map.h> +#include <boost/foreach.hpp> +#include <tr1/unordered_map> +#define foreach BOOST_FOREACH +using namespace std; +using namespace commons; +using namespace stx; +using namespace tr1; + +enum { len = 1000000 }; +int *xs; + +template<typename T> +inline void +load(T &m, const string &label) +{ + long long start = current_time_millis(); + for (int i = 0; i < len; i++) { + m[i] = xs[i]; + } + long long end = current_time_millis(); + cout << label << ": " << end - start << " ms" << endl; +} + +template<typename T> +inline void +scan(T &m, const string &label) +{ + long long start = current_time_millis(); + typedef pair<int, int> pii; + foreach (pii p, m) { + xs[p.first] = p.second; + } + long long end = current_time_millis(); + cout << label << ": " << end - start << " ms" << endl; +} + +template<typename T> +inline void +index(T &m, const string &label) +{ + long long start = current_time_millis(); + typedef pair<int, int> pii; + for (int i = 0; i < len; i++) { + xs[i] = m[i]; + } + long long end = current_time_millis(); + cout << label << ": " << end - start << " ms" << endl; +} + +int main(int argc, char **argv) { + int mode = atoi(argv[1]); + int nreps = 2; + + xs = new int[len]; + for (int i = 0; i < len; i++) { + xs[i] = rand(); + } + + for (int r = 0; r < nreps; r++) { + if (mode & 0x1) { + map<int, int> m; + load(m, "map init"); + load(m, "map reload"); + scan(m, "map scan"); + index(m, "map index"); + } + if (mode & 0x2) { + // default trait: 256B/node -> 32pairs/node + btree_map<int, int> m; + load(m, "btree init"); + load(m, "btree reload"); + scan(m, "btree scan"); + index(m, "btree index"); + } + if (mode & 0x4) { + unordered_map<int, int> m; + load(m, "hash init"); + load(m, "hash reload"); + scan(m, "hash scan"); + index(m, "hash index"); + } + if (mode & 0x8) { + int *m = new int[len]; + load(m, "arr init"); + load(m, "arr reload"); + index(m, "arr index"); + } + } + return 0; +} Added: container-bench/trunk/tools/analysis.py =================================================================== --- container-bench/trunk/tools/analysis.py (rev 0) +++ container-bench/trunk/tools/analysis.py 2009-01-28 07:07:48 UTC (rev 1148) @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +from __future__ import with_statement +import sys +from pylab import * + +pairs = ( line.split(': ') for line in sys.stdin if ': ' in line ) +pairs = [ (a, int(b.split()[0])) for (a,b) in pairs ] + +labels, data = zip(*pairs) +xs = arange(len(data))+.5 +width = .5 +bar(xs, data, width = width) + +xlim(0, xs[-1] + width*2) +xticks(xs + width/2, labels, rotation = 90) +title("Performance of associative containers") +# show only bottom/left ticks +gca().get_xaxis().tick_bottom() +gca().get_yaxis().tick_left() + +savefig('results.png') Property changes on: container-bench/trunk/tools/analysis.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |