|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r71455 - in sandbox/local/libs/local: doc/html example
From: lorcaminiti_at_[hidden]
Date: 2011-04-23 22:24:06
Author: lcaminiti
Date: 2011-04-23 22:24:05 EDT (Sat, 23 Apr 2011)
New Revision: 71455
URL: http://svn.boost.org/trac/boost/changeset/71455
Log:
Added profiling.
Added:
sandbox/local/libs/local/doc/html/BOOST_LOCAL_FUNCTION_NAME_OPTIMIZED.html (contents, props changed)
sandbox/local/libs/local/example/profile_boost_lambda.cpp (contents, props changed)
sandbox/local/libs/local/example/profile_boost_local.cpp (contents, props changed)
sandbox/local/libs/local/example/profile_boost_local_for_loop.cpp (contents, props changed)
sandbox/local/libs/local/example/profile_boost_local_optimized.cpp (contents, props changed)
sandbox/local/libs/local/example/profile_boost_phoenix.cpp (contents, props changed)
sandbox/local/libs/local/example/profile_global_functor.cpp (contents, props changed)
sandbox/local/libs/local/example/profile_helpers.hpp (contents, props changed)
sandbox/local/libs/local/example/profile_local_functor.cpp (contents, props changed)
sandbox/local/libs/local/example/profile_msvc-8.0_debug.png (contents, props changed)
sandbox/local/libs/local/example/profile_msvc-8.0_release.png (contents, props changed)
Added: sandbox/local/libs/local/doc/html/BOOST_LOCAL_FUNCTION_NAME_OPTIMIZED.html
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/doc/html/BOOST_LOCAL_FUNCTION_NAME_OPTIMIZED.html 2011-04-23 22:24:05 EDT (Sat, 23 Apr 2011)
@@ -0,0 +1,49 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Macro BOOST_LOCAL_FUNCTION_NAME_OPTIMIZED</title>
+<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="index.html" title="Boost.Local 0.2.0">
+<link rel="up" href="reference.html#header.boost.local.function_hpp" title="Header <boost/local/function.hpp>">
+<link rel="prev" href="BOOST_LOCAL_FUNCTION_NAME.html" title="Macro BOOST_LOCAL_FUNCTION_NAME">
+<link rel="next" href="BOOST_LOCAL_TYPEOF.html" title="Macro BOOST_LOCAL_TYPEOF">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="BOOST_LOCAL_FUNCTION_NAME.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="reference.html#header.boost.local.function_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="BOOST_LOCAL_TYPEOF.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+<div class="refentry">
+<a name="BOOST_LOCAL_FUNCTION_NAME_OPTIMIZED"></a><div class="titlepage"></div>
+<div class="refnamediv">
+<h2><span class="refentrytitle">Macro BOOST_LOCAL_FUNCTION_NAME_OPTIMIZED</span></h2>
+<p>BOOST_LOCAL_FUNCTION_NAME_OPTIMIZED</p>
+</div>
+<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
+<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: <<a class="link" href="reference.html#header.boost.local.function_hpp" title="Header <boost/local/function.hpp>">boost/local/function.hpp</a>>
+
+</span>BOOST_LOCAL_FUNCTION_NAME_OPTIMIZED(name)</pre></div>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2009 -2011 Lorenzo Caminiti<p>
+ Use, modification, and distribution is subject to the Boost Software License,
+ Version 1.0 (see accompanying file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="BOOST_LOCAL_FUNCTION_NAME.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="reference.html#header.boost.local.function_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="BOOST_LOCAL_TYPEOF.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>
Added: sandbox/local/libs/local/example/profile_boost_lambda.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/profile_boost_lambda.cpp 2011-04-23 22:24:05 EDT (Sat, 23 Apr 2011)
@@ -0,0 +1,35 @@
+
+#include <boost/chrono.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <iostream>
+#include <vector>
+#include <algorithm>
+#include "profile_helpers.hpp"
+
+int main(int argc, char* argv[]) {
+ unsigned long size = 0, trials = 0;
+ begin(argc, argv, size, trials);
+
+ double sum = 0.0;
+ int factor = 1;
+
+ std::vector<double> v(size);
+ std::fill(v.begin(), v.end(), 1.0);
+
+ boost::chrono::duration<double> trials_sec;
+ for (unsigned long i = 0; i < trials; ++i) {
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+
+ using boost::lambda::_1;
+ std::for_each(v.begin(), v.end(), (
+ sum += factor * _1
+ ));
+
+ trials_sec += boost::chrono::system_clock::now() - start;
+ }
+
+ end(size, trials, sum, trials_sec.count());
+ return 0;
+}
+
Added: sandbox/local/libs/local/example/profile_boost_local.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/profile_boost_local.cpp 2011-04-23 22:24:05 EDT (Sat, 23 Apr 2011)
@@ -0,0 +1,39 @@
+
+#include <boost/chrono.hpp>
+#include <boost/local/function.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+#include "profile_helpers.hpp"
+
+int main(int argc, char* argv[]) {
+ unsigned long size = 0, trials = 0;
+ begin(argc, argv, size, trials);
+
+ double sum = 0.0;
+ int factor = 1;
+
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ void BOOST_LOCAL_FUNCTION_PARAMS( (const double& num)
+ (bind& sum) (const bind& factor) ) {
+ sum += factor * num;
+ } BOOST_LOCAL_FUNCTION_NAME(add)
+ boost::chrono::duration<double> decl_sec =
+ boost::chrono::system_clock::now() - start;
+
+ std::vector<double> v(size);
+ std::fill(v.begin(), v.end(), 1.0);
+
+ boost::chrono::duration<double> trials_sec;
+ for (unsigned long i = 0; i < trials; ++i) {
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ std::for_each(v.begin(), v.end(), add);
+ trials_sec += boost::chrono::system_clock::now() - start;
+ }
+
+ end(size, trials, sum, trials_sec.count(), decl_sec.count());
+ return 0;
+}
+
Added: sandbox/local/libs/local/example/profile_boost_local_for_loop.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/profile_boost_local_for_loop.cpp 2011-04-23 22:24:05 EDT (Sat, 23 Apr 2011)
@@ -0,0 +1,39 @@
+
+#include <boost/chrono.hpp>
+#include <boost/local/function.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+#include "profile_helpers.hpp"
+
+int main(int argc, char* argv[]) {
+ unsigned long size = 0, trials = 0;
+ begin(argc, argv, size, trials);
+
+ double sum = 0.0;
+ int factor = 1;
+
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ void BOOST_LOCAL_FUNCTION_PARAMS( (const double& num)
+ (bind& sum) (const bind& factor) ) {
+ sum += factor * num;
+ } BOOST_LOCAL_FUNCTION_NAME(add) // Not optimized but compile w/ COMPLIANT.
+ boost::chrono::duration<double> decl_sec =
+ boost::chrono::system_clock::now() - start;
+
+ std::vector<double> v(size);
+ std::fill(v.begin(), v.end(), 1.0);
+
+ boost::chrono::duration<double> trials_sec;
+ for (unsigned long i = 0; i < trials; ++i) {
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ for (unsigned long j = 0; j < v.size(); ++j) add(v[j]); // No for_each.
+ trials_sec += boost::chrono::system_clock::now() - start;
+ }
+
+ end(size, trials, sum, trials_sec.count(), decl_sec.count());
+ return 0;
+}
+
Added: sandbox/local/libs/local/example/profile_boost_local_optimized.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/profile_boost_local_optimized.cpp 2011-04-23 22:24:05 EDT (Sat, 23 Apr 2011)
@@ -0,0 +1,39 @@
+
+#include <boost/chrono.hpp>
+#include <boost/local/function.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+#include "profile_helpers.hpp"
+
+int main(int argc, char* argv[]) {
+ unsigned long size = 0, trials = 0;
+ begin(argc, argv, size, trials);
+
+ double sum = 0.0;
+ int factor = 1;
+
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ void BOOST_LOCAL_FUNCTION_PARAMS( (const double& num)
+ (bind& sum) (const bind& factor) ) {
+ sum += factor * num;
+ } BOOST_LOCAL_FUNCTION_NAME_OPTIMIZED(add)
+ boost::chrono::duration<double> decl_sec =
+ boost::chrono::system_clock::now() - start;
+
+ std::vector<double> v(size);
+ std::fill(v.begin(), v.end(), 1.0);
+
+ boost::chrono::duration<double> trials_sec;
+ for (unsigned long i = 0; i < trials; ++i) {
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ for (unsigned long j = 0; j < v.size(); ++j) add(v[j]); // No for_each.
+ trials_sec += boost::chrono::system_clock::now() - start;
+ }
+
+ end(size, trials, sum, trials_sec.count(), decl_sec.count());
+ return 0;
+}
+
Added: sandbox/local/libs/local/example/profile_boost_phoenix.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/profile_boost_phoenix.cpp 2011-04-23 22:24:05 EDT (Sat, 23 Apr 2011)
@@ -0,0 +1,36 @@
+
+#include <boost/chrono.hpp>
+#include <boost/spirit/include/phoenix.hpp>
+#include <iostream>
+#include <vector>
+#include <algorithm>
+#include "profile_helpers.hpp"
+
+int main(int argc, char* argv[]) {
+ unsigned long size = 0, trials = 0;
+ begin(argc, argv, size, trials);
+
+ double sum = 0.0;
+ int factor = 1;
+
+ std::vector<double> v(size);
+ std::fill(v.begin(), v.end(), 1.0);
+
+ boost::chrono::duration<double> trials_sec;
+ for (unsigned long i = 0; i < trials; ++i) {
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+
+ using boost::phoenix::ref;
+ using boost::phoenix::arg_names::_1;
+ std::for_each(v.begin(), v.end(), (
+ ref(sum) += factor * _1
+ ));
+
+ trials_sec += boost::chrono::system_clock::now() - start;
+ }
+
+ end(size, trials, sum, trials_sec.count());
+ return 0;
+}
+
Added: sandbox/local/libs/local/example/profile_global_functor.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/profile_global_functor.cpp 2011-04-23 22:24:05 EDT (Sat, 23 Apr 2011)
@@ -0,0 +1,46 @@
+
+#include <boost/chrono.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+#include "profile_helpers.hpp"
+
+struct add_global_functor {
+ add_global_functor(double& sum_, const int& factor_):
+ sum(sum_), factor(factor_) {}
+ inline void operator()(const double& num) {
+ sum += factor * num;
+ }
+private:
+ double& sum;
+ const int& factor;
+};
+
+int main(int argc, char* argv[]) {
+ unsigned long size = 0, trials =0;
+ begin(argc, argv, size, trials);
+
+ double sum = 0.0;
+ int factor = 1;
+
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ add_global_functor add(sum, factor);
+ boost::chrono::duration<double> decl_sec =
+ boost::chrono::system_clock::now() - start;
+
+ std::vector<double> v(size);
+ std::fill(v.begin(), v.end(), 1.0);
+
+ boost::chrono::duration<double> trials_sec;
+ for (unsigned long i = 0; i < trials; ++i) {
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ std::for_each(v.begin(), v.end(), add);
+ trials_sec += boost::chrono::system_clock::now() - start;
+ }
+
+ end(size, trials, sum, trials_sec.count(), decl_sec.count());
+ return 0;
+}
+
Added: sandbox/local/libs/local/example/profile_helpers.hpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/profile_helpers.hpp 2011-04-23 22:24:05 EDT (Sat, 23 Apr 2011)
@@ -0,0 +1,44 @@
+
+#ifndef PROFILE_HELPERS_HPP_
+#define PROFILE_HELPERS_HPP_
+
+#include <iostream>
+#include <cassert>
+
+void begin(int argc, char* argv[], unsigned long& size, unsigned long& trials) {
+ size = 100000000; // Defaults.
+ trials = 100; // Default.
+ if (argc != 1 && argc != 2 && argc != 3) {
+ std::cerr << "ERROR: Incorrect argument(s)" << std::endl;
+ std::cerr << "Usage: " << argv[0] << " [SIZE] [TRIALS]" <<
+ std::endl;
+ std::cerr << "Defaults: SIZE = " << double(size) << ", TRIALS = " <<
+ double(trials) << std::endl;
+ exit(1);
+ }
+ if (argc >= 2) size = atol(argv[1]);
+ if (argc >= 3) trials = atol(argv[2]);
+
+ std::clog << "vector size = " << double(size) << std::endl;
+ std::clog << "number of trials = " << double(trials) << std::endl;
+ std::clog << "number of calls = " << double(size) * double(trials) <<
+ std::endl;
+}
+
+void end(const unsigned long& size, const unsigned long& trials,
+ const double& sum, const double& trials_sec,
+ const double& decl_sec = 0.0) {
+ std::clog << "sum = " << sum << std::endl;
+ std::clog << "declaration run-time [s] = " << decl_sec << std::endl;
+ std::clog << "trials run-time [s] = " << trials_sec << std::endl;
+
+ double avg_sec = decl_sec + trials_sec / trials;
+ std::clog << "average run-time [s] = declaration run-time + trials " <<
+ "run-time / number of trials = " << std::endl;
+ std::cout << avg_sec << std::endl; // To cout so it can be parsed easily.
+
+ assert(sum == double(size) * double(trials));
+}
+
+#endif // #include guard
+
Added: sandbox/local/libs/local/example/profile_local_functor.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/profile_local_functor.cpp 2011-04-23 22:24:05 EDT (Sat, 23 Apr 2011)
@@ -0,0 +1,44 @@
+
+#include <boost/chrono.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+#include "profile_helpers.hpp"
+
+int main(int argc, char* argv[]) {
+ unsigned long size = 0, trials = 0;
+ begin(argc, argv, size, trials);
+
+ double sum = 0.0;
+ int factor = 1;
+
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ struct add_local_functor {
+ add_local_functor(double& sum_, const int& factor_):
+ sum(sum_), factor(factor_) {}
+ inline void operator()(const double& num) {
+ sum += factor * num;
+ }
+ private:
+ double& sum;
+ const int& factor;
+ } add(sum, factor);
+ boost::chrono::duration<double> decl_sec =
+ boost::chrono::system_clock::now() - start;
+
+ std::vector<double> v(size);
+ std::fill(v.begin(), v.end(), 1.0);
+
+ boost::chrono::duration<double> trials_sec;
+ for (unsigned long i = 0; i < trials; ++i) {
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ for (unsigned long j = 0; j < v.size(); ++j) add(v[j]); // No for_each.
+ trials_sec += boost::chrono::system_clock::now() - start;
+ }
+
+ end(size, trials, sum, trials_sec.count(), decl_sec.count());
+ return 0;
+}
+
Added: sandbox/local/libs/local/example/profile_msvc-8.0_debug.png
==============================================================================
Binary file. No diff available.
Added: sandbox/local/libs/local/example/profile_msvc-8.0_release.png
==============================================================================
Binary file. No diff available.
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