|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72997 - in sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark: . detail
From: cpp.cabrera_at_[hidden]
Date: 2011-07-10 21:21:59
Author: alejandro
Date: 2011-07-10 21:21:57 EDT (Sun, 10 Jul 2011)
New Revision: 72997
URL: http://svn.boost.org/trac/boost/changeset/72997
Log:
Added preliminary insertion benchmarks. Need more benchmarks on more types using more data structures.
Added:
sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/
sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/bloom_insert.cpp (contents, props changed)
sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/detail/
sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/detail/benchmark.hpp (contents, props changed)
sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/detail/generator.hpp (contents, props changed)
sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/detail/pow.hpp (contents, props changed)
sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/stdhash_insert.cpp (contents, props changed)
sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/stdset_insert.cpp (contents, props changed)
Added: sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/bloom_insert.cpp
==============================================================================
--- (empty file)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/bloom_insert.cpp 2011-07-10 21:21:57 EDT (Sun, 10 Jul 2011)
@@ -0,0 +1,49 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Alejandro Cabrera 2011.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/bloom_filter for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "detail/pow.hpp"
+#include "detail/generator.hpp"
+#include "detail/benchmark.hpp"
+
+#include <boost/bloom_filter/bloom.hpp>
+#include <boost/progress.hpp>
+#include <iostream>
+using namespace std;
+using boost::detail::Pow;
+using boost::detail::benchmark;
+using boost::detail::generator;
+using boost::bloom_filter::bloom_filter;
+
+int main()
+{
+ static const size_t REPEAT = Pow<10, 3>::val; // 1000
+ static const size_t OPS = Pow<10, 6>::val; // 1,000,000 inserts
+ static const size_t BITS = Pow<2, 21>::val; // 2MB
+
+ boost::progress_display progress(REPEAT);
+ double total_time = 0.0;
+
+ for (size_t i = 0; i < REPEAT; ++i, ++progress) {
+ benchmark<int, OPS,
+ generator<int>,
+ bloom_filter<int, BITS> > bench;
+
+ bench.run();
+
+ total_time += bench.time();
+ }
+
+ cout << REPEAT << " trials of " << OPS << " insertions took "
+ << total_time << " seconds" << endl;
+
+ return 0;
+}
Added: sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/detail/benchmark.hpp
==============================================================================
--- (empty file)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/detail/benchmark.hpp 2011-07-10 21:21:57 EDT (Sun, 10 Jul 2011)
@@ -0,0 +1,46 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Alejandro Cabrera 2011.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/bloom_filter for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_DETAIL_BENCHMARK_HPP
+#define BOOST_DETAIL_BENCHMARK_HPP
+
+#include <boost/timer.hpp>
+#include <cstddef>
+
+namespace boost {
+ namespace detail {
+ template <typename T,
+ size_t OpCount,
+ class Generator,
+ class Container>
+ class benchmark {
+ public:
+ benchmark() : test_time(0.0) {}
+
+ double time() const { return test_time; }
+
+ void run() {
+ boost::timer timer;
+ for (size_t i = 0; i < OpCount; ++i) {
+ container.insert(gen());
+ }
+ test_time = timer.elapsed();
+ }
+
+ private:
+ Container container;
+ Generator gen;
+ double test_time;
+ };
+ }
+}
+#endif
Added: sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/detail/generator.hpp
==============================================================================
--- (empty file)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/detail/generator.hpp 2011-07-10 21:21:57 EDT (Sun, 10 Jul 2011)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Alejandro Cabrera 2011.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/bloom_filter for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_DETAIL_GENERATOR_HPP
+#define BOOST_DETAIL_GENERATOR_HPP
+
+#include <boost/random/linear_congruential.hpp>
+
+namespace boost {
+ namespace detail {
+ template <typename T>
+ struct generator {
+ T operator()() {
+ return gen();
+ }
+
+ private:
+ boost::minstd_rand gen;
+ };
+ }
+}
+#endif
Added: sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/detail/pow.hpp
==============================================================================
--- (empty file)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/detail/pow.hpp 2011-07-10 21:21:57 EDT (Sun, 10 Jul 2011)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Alejandro Cabrera 2011.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/bloom_filter for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_DETAIL_POW_HPP
+#define BOOST_DETAIL_POW_HPP
+
+#include <cstddef>
+
+namespace boost {
+ namespace detail {
+ template <size_t Base, size_t Exponent>
+ struct Pow {
+ static const size_t val = Base * Pow<Base, Exponent - 1>::val;
+ };
+
+ template <size_t Base>
+ struct Pow<Base, 1> {
+ static const size_t val = Base;
+ };
+ }
+}
+#endif
Added: sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/stdhash_insert.cpp
==============================================================================
--- (empty file)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/stdhash_insert.cpp 2011-07-10 21:21:57 EDT (Sun, 10 Jul 2011)
@@ -0,0 +1,48 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Alejandro Cabrera 2011.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/bloom_filter for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "detail/pow.hpp"
+#include "detail/generator.hpp"
+#include "detail/benchmark.hpp"
+
+#include <iostream>
+
+#include <boost/progress.hpp>
+#include <boost/unordered_set.hpp>
+using namespace std;
+using boost::detail::Pow;
+using boost::detail::benchmark;
+using boost::detail::generator;
+
+int main()
+{
+ static const size_t REPEAT = Pow<10, 3>::val; // 1000
+ static const size_t OPS = Pow<10, 6>::val; // 1,000,000 inserts
+
+ boost::progress_display progress(REPEAT);
+ double total_time = 0.0;
+
+ for (size_t i = 0; i < REPEAT; ++i, ++progress) {
+ benchmark<int, OPS,
+ generator<int>,
+ boost::unordered_set<int> > bench;
+
+ bench.run();
+
+ total_time += bench.time();
+ }
+
+ cout << REPEAT << " trials of " << OPS << " insertions took "
+ << total_time << " seconds" << endl;
+
+ return 0;
+}
Added: sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/stdset_insert.cpp
==============================================================================
--- (empty file)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/benchmark/stdset_insert.cpp 2011-07-10 21:21:57 EDT (Sun, 10 Jul 2011)
@@ -0,0 +1,48 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Alejandro Cabrera 2011.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/bloom_filter for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "detail/pow.hpp"
+#include "detail/generator.hpp"
+#include "detail/benchmark.hpp"
+
+#include <set>
+#include <iostream>
+
+#include <boost/progress.hpp>
+using namespace std;
+using boost::detail::Pow;
+using boost::detail::benchmark;
+using boost::detail::generator;
+
+int main()
+{
+ static const size_t REPEAT = Pow<10, 3>::val; // 1000
+ static const size_t OPS = Pow<10, 6>::val; // 1,000,000 inserts
+
+ boost::progress_display progress(REPEAT);
+ double total_time = 0.0;
+
+ for (size_t i = 0; i < REPEAT; ++i, ++progress) {
+ benchmark<int, OPS,
+ generator<int>,
+ std::set<int> > bench;
+
+ bench.run();
+
+ total_time += bench.time();
+ }
+
+ cout << REPEAT << " trials of " << OPS << " insertions took "
+ << total_time << " seconds" << endl;
+
+ return 0;
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk