|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r76713 - sandbox/local_function/libs/local_function/example
From: lorcaminiti_at_[hidden]
Date: 2012-01-26 17:18:29
Author: lcaminiti
Date: 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
New Revision: 76713
URL: http://svn.boost.org/trac/boost/changeset/76713
Log:
Profiling.
Added:
sandbox/local_function/libs/local_function/example/add_global_functor.cpp (contents, props changed)
sandbox/local_function/libs/local_function/example/add_local_functor.cpp (contents, props changed)
sandbox/local_function/libs/local_function/example/add_phoenix.cpp (contents, props changed)
sandbox/local_function/libs/local_function/example/chrono.py (contents, props changed)
sandbox/local_function/libs/local_function/example/expensive_copy_lambda.cpp (contents, props changed)
sandbox/local_function/libs/local_function/example/expensive_copy_local_function.cpp (contents, props changed)
sandbox/local_function/libs/local_function/example/noncopyable_lambda.cpp (contents, props changed)
sandbox/local_function/libs/local_function/example/noncopyable_local_function.cpp (contents, props changed)
sandbox/local_function/libs/local_function/example/phoenix_factorial.cpp (contents, props changed)
sandbox/local_function/libs/local_function/example/phoenix_local_factorial.cpp (contents, props changed)
sandbox/local_function/libs/local_function/example/profile.xls (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_gcc_cpp11_debug.png (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_gcc_cpp11_release.png (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_gcc_debug.png (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_gcc_release.png (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_global_functor.cpp (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_lambda.cpp (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_legend_global_functor.png (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_legend_lambda.png (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_legend_local_function.png (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_legend_local_function_inline.png (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_legend_local_functor.png (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_legend_phoenix.png (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_local_function.cpp (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_local_function_inline.cpp (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_msvc_debug.png (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_msvc_release.png (contents, props changed)
sandbox/local_function/libs/local_function/example/profile_phoenix.cpp (contents, props changed)
Removed:
sandbox/local_function/libs/local_function/example/boost_phoenix_factorial.cpp
sandbox/local_function/libs/local_function/example/boost_phoenix_local_factorial.cpp
sandbox/local_function/libs/local_function/example/profile_boost_closure.cpp
sandbox/local_function/libs/local_function/example/profile_boost_closure_inline.cpp
sandbox/local_function/libs/local_function/example/profile_boost_phoenix.cpp
Text files modified:
sandbox/local_function/libs/local_function/example/Jamfile.v2 | 54 ++++++++++++++++++++++-----------------
sandbox/local_function/libs/local_function/example/profile_helpers.hpp | 2
sandbox/local_function/libs/local_function/example/profile_local_functor.cpp | 6 +--
3 files changed, 34 insertions(+), 28 deletions(-)
Modified: sandbox/local_function/libs/local_function/example/Jamfile.v2
==============================================================================
--- sandbox/local_function/libs/local_function/example/Jamfile.v2 (original)
+++ sandbox/local_function/libs/local_function/example/Jamfile.v2 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -1,9 +1,7 @@
import testing ;
-project : requirements
- <library>/boost//unit_test_framework
-;
+project : requirements <library>/boost//unit_test_framework ;
# @todo profiling
# @todo impl_factorial
@@ -29,24 +27,34 @@
run n2529_this.cpp ;
run n2550_find_if.cpp ;
-#exe profile_boost_closure : profile_boost_closure.cpp :
-# <library>/boost/chrono//boost_chrono
-# <library>/boost/system//boost_system
-# <link>static
-#;
-#exe profile_boost_closure_inline : profile_boost_closure_inline.cpp :
-# <library>/boost/chrono//boost_chrono
-# <library>/boost/system//boost_system
-# <link>static
-#;
-#exe profile_local_functor : profile_local_functor.cpp :
-# <library>/boost/chrono//boost_chrono
-# <library>/boost/system//boost_system
-# <link>static
-#;
-#exe profile_boost_phoenix : profile_boost_phoenix.cpp :
-# <library>/boost/chrono//boost_chrono
-# <library>/boost/system//boost_system
-# <link>static
-#;
+exe profile_local_function : profile_local_function.cpp
+ : <library>/boost/chrono//boost_chrono
+ <library>/boost/system//boost_system
+ <link>static
+ ;
+exe profile_local_function_inline : profile_local_function_inline.cpp
+ : <library>/boost/chrono//boost_chrono
+ <library>/boost/system//boost_system
+ <link>static
+ ;
+exe profile_lambda : profile_lambda.cpp
+ : <library>/boost/chrono//boost_chrono
+ <library>/boost/system//boost_system
+ <link>static
+ ;
+exe profile_local_functor : profile_local_functor.cpp
+ : <library>/boost/chrono//boost_chrono
+ <library>/boost/system//boost_system
+ <link>static
+ ;
+exe profile_global_functor : profile_global_functor.cpp
+ : <library>/boost/chrono//boost_chrono
+ <library>/boost/system//boost_system
+ <link>static
+ ;
+exe profile_phoenix : profile_phoenix.cpp
+ : <library>/boost/chrono//boost_chrono
+ <library>/boost/system//boost_system
+ <link>static
+ ;
Added: sandbox/local_function/libs/local_function/example/add_global_functor.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/add_global_functor.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,36 @@
+
+// Copyright (C) 2009-2011 Lorenzo Caminiti
+// 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).
+
+#define BOOST_TEST_MODULE AddGlobalFunctor
+#include <boost/test/unit_test.hpp>
+#include <algorithm>
+
+//[add_global_functor
+// Unfortunately, cannot be defined locally (so not real alternative).
+struct global_add { // Unfortunately, boilerplate code to program the class.
+ global_add(int& _sum, int _factor): sum(_sum), factor(_factor) {}
+
+ inline void operator()(int num) { // Body uses C++ statement syntax.
+ sum += factor * num;
+ }
+private: // Unfortunately, cannot bind so repeat variable types.
+ int& sum; // Access `sum` by reference.
+ const int& factor; // Make `factor` constant.
+};
+
+BOOST_AUTO_TEST_CASE( add_global_functor ) {
+ int sum = 0, factor = 10;
+
+ global_add add(sum, factor);
+
+ add(1);
+ int nums[] = {2, 3};
+ std::for_each(nums, nums + 2, add); // Passed as template parameter.
+
+ BOOST_CHECK( sum == 60 );
+}
+//]
+
Added: sandbox/local_function/libs/local_function/example/add_local_functor.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/add_local_functor.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,34 @@
+
+// Copyright (C) 2009-2011 Lorenzo Caminiti
+// 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).
+
+#define BOOST_TEST_CASE AddLocalFunctor
+#include <boost/test/unit_test.hpp>
+
+BOOST_AUTO_TEST_CASE( add_local_functor )
+//[add_local_functor
+{
+ int sum = 0, factor = 10;
+
+ struct local_add { // Unfortunately, boilerplate code to program the class.
+ local_add(int& _sum, int _factor): sum(_sum), factor(_factor) {}
+
+ inline void operator()(int num) { // Body uses C++ statement syntax.
+ sum += factor * num;
+ }
+ private: // Unfortunately, cannot bind so repeat variable types.
+ int& sum; // Access `sum` by reference.
+ const int& factor; // Make `factor` constant.
+ } add(sum, factor);
+
+ add(1);
+ int nums[] = {2, 3};
+ // Unfortunately, cannot pass as template parameter to `std::for_each`.
+ for(size_t i = 0; i < 2; ++i) add(nums[i]);
+
+ BOOST_CHECK( sum == 60 );
+}
+//]
+
Added: sandbox/local_function/libs/local_function/example/add_phoenix.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/add_phoenix.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,28 @@
+
+// Copyright (C) 2009-2011 Lorenzo Caminiti
+// 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).
+
+#include <boost/spirit/include/phoenix.hpp>
+#define BOOST_TEST_MODULE AddPhoenix
+#include <boost/test/unit_test.hpp>
+#include <algorithm>
+
+BOOST_AUTO_TEST_CASE( add_phoenix )
+//[add_phoenix
+{
+ int sum = 0, factor = 10;
+ int nums[] = {1, 2, 3};
+
+ // Passed to template, `factor` by constant, and defined in expression.
+ using namespace boost::phoenix;
+ std::for_each(nums, nums + 3, let(_f = cref(factor))[
+ // Unfortunately, body cannot use C++ statement syntax.
+ ref(sum) += _f * _1 // Access `sum` by reference.
+ ]);
+
+ BOOST_CHECK( sum == 60 );
+}
+//]
+
Deleted: sandbox/local_function/libs/local_function/example/boost_phoenix_factorial.cpp
==============================================================================
--- sandbox/local_function/libs/local_function/example/boost_phoenix_factorial.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
+++ (empty file)
@@ -1,34 +0,0 @@
-
-#include <boost/phoenix/core.hpp>
-#include <boost/phoenix/function.hpp>
-#define BOOST_TEST_MODULE ExampleBoostPhoenixFactorial
-#include <boost/test/unit_test.hpp>
-
-//[example_boost_phoenix_factorial
-struct factorial_impl { // Phoenix function from global functor.
- template<typename Sig>
- struct result;
-
- template<typename This, typename Arg>
- struct result<This (Arg)> : result<This (Arg const&)> {};
-
- template<typename This, typename Arg>
- struct result<This (Arg&)> { typedef Arg type; };
-
- template<typename Arg> // Polymorphic.
- Arg operator()(Arg n) const {
- return (n <= 0) ? 1 : n * (*this)(n - 1);
- }
-};
-
-BOOST_AUTO_TEST_CASE( example_boost_phoenix_factorial ) {
- using boost::phoenix::arg_names::arg1;
-
- boost::phoenix::function<factorial_impl> factorial;
-
- int i = 4;
- BOOST_CHECK( factorial(i)() == 24 ); // Call.
- BOOST_CHECK( factorial(arg1)(i) == 24 ); // Lazy call.
-}
-//]
-
Deleted: sandbox/local_function/libs/local_function/example/boost_phoenix_local_factorial.cpp
==============================================================================
--- sandbox/local_function/libs/local_function/example/boost_phoenix_local_factorial.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
+++ (empty file)
@@ -1,25 +0,0 @@
-
-#include <boost/local_function.hpp>
-#include <boost/function.hpp>
-#include <boost/phoenix/core.hpp>
-#include <boost/phoenix/function.hpp>
-#define BOOST_TEST_MODULE ExampleBoostPhoenixFactorialLocal
-#include <boost/test/unit_test.hpp>
-
-//[example_boost_phoenix_local_factorial
-BOOST_AUTO_TEST_CASE( example_boost_phoenix_factorial_local ) {
- using boost::phoenix::arg_names::arg1;
-
- int BOOST_LOCAL_FUNCTION(int n) { // Monomorphic.
- return (n <= 0) ? 1 : n * factorial_impl(n - 1);
- } BOOST_LOCAL_FUNCTION_NAME(recursive factorial_impl)
-
- boost::phoenix::function< boost::function<int (int)> >
- factorial(factorial_impl); // Phoenix function from local function.
-
- int i = 4;
- BOOST_CHECK( factorial(i)() == 24 ); // Call.
- BOOST_CHECK( factorial(arg1)(i) == 24 ); // Lazy call.
-}
-//]
-
Added: sandbox/local_function/libs/local_function/example/chrono.py
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/chrono.py 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,19 @@
+
+# Copyright (C) 2009-2011 Lorenzo Caminiti
+# 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).
+
+import sys
+import time
+import os
+
+cmd = ""
+for arg in sys.argv[1:]: cmd += str(arg) + " "
+
+start = time.time()
+ret = os.system(cmd)
+sec = time.time() - start
+
+if (ret == 0): print "\n" + str(sec) + "s"
+
Added: sandbox/local_function/libs/local_function/example/expensive_copy_lambda.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/expensive_copy_lambda.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,39 @@
+
+// Copyright (C) 2009-2011 Lorenzo Caminiti
+// 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).
+
+#include <boost/config.hpp>
+#ifndef BOOST_NO_LAMBDAS
+
+#include <iostream>
+#include <cassert>
+
+//[expensive_copy_lambda
+struct n {
+ int i;
+ n(int _i): i(_i) {}
+ n(n const& x): i(x.i) { // Some time consuming copy.
+ for (unsigned i = 0; i < 10000; ++i) std::cout << '.';
+ }
+};
+
+int main(void) {
+ n x(-1);
+
+ auto f = [x]() { // Problem: Expensive copy, but if bind
+ assert( x.i == -1); // by `&x` then `x` is not constant.
+ };
+ f();
+
+ return 0;
+}
+//]
+
+#else // NO_LAMBDAS
+
+int main(void) { return 0; } // Trivial program.
+
+#endif // NO_LAMBDAS
+
Added: sandbox/local_function/libs/local_function/example/expensive_copy_local_function.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/expensive_copy_local_function.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,31 @@
+
+// Copyright (C) 2009-2011 Lorenzo Caminiti
+// 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).
+
+#include <boost/local/function.hpp>
+#include <iostream>
+#include <cassert>
+
+//[expensive_copy_local_function
+struct n {
+ int i;
+ n(int _i): i(_i) {}
+ n(n const& x): i(x.i) { // Some time consuming copy.
+ for (unsigned i = 0; i < 10000; ++i) std::cout << '.';
+ }
+};
+
+int main(void) {
+ n x(-1);
+
+ void BOOST_LOCAL_FUNCTION(const bind& x) { // OK: No copy
+ assert( x.i == -1 ); // and constant.
+ } BOOST_LOCAL_FUNCTION_NAME(f)
+ f();
+
+ return 0;
+}
+//]
+
Added: sandbox/local_function/libs/local_function/example/noncopyable_lambda.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/noncopyable_lambda.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,27 @@
+
+// Copyright (C) 2009-2011 Lorenzo Caminiti
+// 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).
+
+#include <boost/noncopyable.hpp>
+#include <cassert>
+
+//[noncopyable_lambda
+struct n: boost::noncopyable {
+ int i;
+ n(int _i): i(_i) {}
+};
+
+int main(void) {
+ n x(-1);
+
+ auto f = [x](void) { // Error: x is non-copyable, but if
+ assert( x.i == -1 ); // bind `&x` then `x` is not constant.
+ };
+ f();
+
+ return 0;
+}
+//]
+
Added: sandbox/local_function/libs/local_function/example/noncopyable_local_function.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/noncopyable_local_function.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,28 @@
+
+// Copyright (C) 2009-2011 Lorenzo Caminiti
+// 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).
+
+#include <boost/local_function.hpp>
+#include <boost/noncopyable.hpp>
+#include <cassert>
+
+//[noncopyable_local_function
+struct n: boost::noncopyable {
+ int i;
+ n(int _i): i(_i) {}
+};
+
+int main() {
+ n x(-1);
+
+ void BOOST_LOCAL_FUNCTION(const bind& x) { // OK: No copy
+ assert( x == -1 ); // and constant.
+ } BOOST_LOCAL_FUNCTION_NAME(f)
+ f();
+
+ return 0;
+}
+//]
+
Added: sandbox/local_function/libs/local_function/example/phoenix_factorial.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/phoenix_factorial.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,34 @@
+
+#include <boost/phoenix/core.hpp>
+#include <boost/phoenix/function.hpp>
+#define BOOST_TEST_MODULE ExampleBoostPhoenixFactorial
+#include <boost/test/unit_test.hpp>
+
+//[example_boost_phoenix_factorial
+struct factorial_impl { // Phoenix function from global functor.
+ template<typename Sig>
+ struct result;
+
+ template<typename This, typename Arg>
+ struct result<This (Arg)> : result<This (Arg const&)> {};
+
+ template<typename This, typename Arg>
+ struct result<This (Arg&)> { typedef Arg type; };
+
+ template<typename Arg> // Polymorphic.
+ Arg operator()(Arg n) const {
+ return (n <= 0) ? 1 : n * (*this)(n - 1);
+ }
+};
+
+BOOST_AUTO_TEST_CASE( example_boost_phoenix_factorial ) {
+ using boost::phoenix::arg_names::arg1;
+
+ boost::phoenix::function<factorial_impl> factorial;
+
+ int i = 4;
+ BOOST_CHECK( factorial(i)() == 24 ); // Call.
+ BOOST_CHECK( factorial(arg1)(i) == 24 ); // Lazy call.
+}
+//]
+
Added: sandbox/local_function/libs/local_function/example/phoenix_local_factorial.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/phoenix_local_factorial.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,25 @@
+
+#include <boost/local_function.hpp>
+#include <boost/function.hpp>
+#include <boost/phoenix/core.hpp>
+#include <boost/phoenix/function.hpp>
+#define BOOST_TEST_MODULE ExampleBoostPhoenixFactorialLocal
+#include <boost/test/unit_test.hpp>
+
+//[example_boost_phoenix_local_factorial
+BOOST_AUTO_TEST_CASE( example_boost_phoenix_factorial_local ) {
+ using boost::phoenix::arg_names::arg1;
+
+ int BOOST_LOCAL_FUNCTION(int n) { // Monomorphic.
+ return (n <= 0) ? 1 : n * factorial_impl(n - 1);
+ } BOOST_LOCAL_FUNCTION_NAME(recursive factorial_impl)
+
+ boost::phoenix::function< boost::function<int (int)> >
+ factorial(factorial_impl); // Phoenix function from local function.
+
+ int i = 4;
+ BOOST_CHECK( factorial(i)() == 24 ); // Call.
+ BOOST_CHECK( factorial(arg1)(i) == 24 ); // Lazy call.
+}
+//]
+
Added: sandbox/local_function/libs/local_function/example/profile.xls
==============================================================================
Binary file. No diff available.
Deleted: sandbox/local_function/libs/local_function/example/profile_boost_closure.cpp
==============================================================================
--- sandbox/local_function/libs/local_function/example/profile_boost_closure.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
+++ (empty file)
@@ -1,45 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// 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).
-
-//[example_profile_boost_closure_cpp
-#include <boost/closure.hpp>
-#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;
- profile::args(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_CLOSURE(const double& num, bind& sum, const bind& factor) {
- sum += factor * num;
- } BOOST_CLOSURE_END(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;
- }
-
- profile::print(size, trials, sum, trials_sec.count(), decl_sec.count());
- return 0;
-}
-//]
-
Deleted: sandbox/local_function/libs/local_function/example/profile_boost_closure_inline.cpp
==============================================================================
--- sandbox/local_function/libs/local_function/example/profile_boost_closure_inline.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
+++ (empty file)
@@ -1,45 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// 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).
-
-//[example_profile_boost_closure_inline_cpp
-#include <boost/closure.hpp>
-#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;
- profile::args(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_CLOSURE(const double& num, bind& sum, const bind& factor) {
- sum += factor * num;
- } BOOST_CLOSURE_END(inline add) // inlined
- 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;
- }
-
- profile::print(size, trials, sum, trials_sec.count(), decl_sec.count());
- return 0;
-}
-//]
-
Deleted: sandbox/local_function/libs/local_function/example/profile_boost_phoenix.cpp
==============================================================================
--- sandbox/local_function/libs/local_function/example/profile_boost_phoenix.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
+++ (empty file)
@@ -1,46 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// 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).
-
-//[example_profile_boost_phoenix_cpp
-#include <boost/spirit/home/phoenix/statement/sequence.hpp>
-#include <boost/spirit/home/phoenix/core/reference.hpp>
-#include <boost/spirit/home/phoenix/core/argument.hpp>
-#include <boost/spirit/home/phoenix/operator/arithmetic.hpp>
-#include <boost/chrono.hpp>
-#include <iostream>
-#include <vector>
-#include <algorithm>
-#include "profile_helpers.hpp"
-
-int main(int argc, char* argv[]) {
- unsigned long size = 0, trials = 0;
- profile::args(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;
- }
-
- profile::print(size, trials, sum, trials_sec.count());
- return 0;
-}
-//]
-
Added: sandbox/local_function/libs/local_function/example/profile_gcc_cpp11_debug.png
==============================================================================
Binary file. No diff available.
Added: sandbox/local_function/libs/local_function/example/profile_gcc_cpp11_release.png
==============================================================================
Binary file. No diff available.
Added: sandbox/local_function/libs/local_function/example/profile_gcc_debug.png
==============================================================================
Binary file. No diff available.
Added: sandbox/local_function/libs/local_function/example/profile_gcc_release.png
==============================================================================
Binary file. No diff available.
Added: sandbox/local_function/libs/local_function/example/profile_global_functor.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/profile_global_functor.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,51 @@
+
+// Copyright (C) 2009-2011 Lorenzo Caminiti
+// 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).
+
+#include <boost/chrono.hpp>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+#include "profile_helpers.hpp"
+
+struct global_add {
+ global_add(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;
+ profile::args(argc, argv, size, trials);
+
+ double sum = 0.0;
+ int factor = 1;
+
+ boost::chrono::system_clock::time_point start =
+ boost::chrono::system_clock::now();
+ global_add 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;
+ }
+
+ profile::display(size, trials, sum, trials_sec.count(), decl_sec.count());
+ return 0;
+}
+
Modified: sandbox/local_function/libs/local_function/example/profile_helpers.hpp
==============================================================================
--- sandbox/local_function/libs/local_function/example/profile_helpers.hpp (original)
+++ sandbox/local_function/libs/local_function/example/profile_helpers.hpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -32,7 +32,7 @@
std::endl;
}
-void print(const unsigned long& size, const unsigned long& trials,
+void display(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;
Added: sandbox/local_function/libs/local_function/example/profile_lambda.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/profile_lambda.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,45 @@
+
+// Copyright (C) 2009-2011 Lorenzo Caminiti
+// 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).
+
+#include <boost/config.hpp>
+#ifndef BOOST_NO_LAMBDAS
+
+#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;
+ profile::args(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();
+ std::for_each(v.begin(), v.end(), [&sum, factor](const double& num) {
+ sum += factor * num;
+ });
+ trials_sec += boost::chrono::system_clock::now() - start;
+ }
+
+ profile::display(size, trials, sum, trials_sec.count());
+ return 0;
+}
+
+#else // NO_LAMBDAS
+
+int main(void) { return 0; } // Trivial program.
+
+#endif // NO_LAMBDAS
+
Added: sandbox/local_function/libs/local_function/example/profile_legend_global_functor.png
==============================================================================
Binary file. No diff available.
Added: sandbox/local_function/libs/local_function/example/profile_legend_lambda.png
==============================================================================
Binary file. No diff available.
Added: sandbox/local_function/libs/local_function/example/profile_legend_local_function.png
==============================================================================
Binary file. No diff available.
Added: sandbox/local_function/libs/local_function/example/profile_legend_local_function_inline.png
==============================================================================
Binary file. No diff available.
Added: sandbox/local_function/libs/local_function/example/profile_legend_local_functor.png
==============================================================================
Binary file. No diff available.
Added: sandbox/local_function/libs/local_function/example/profile_legend_phoenix.png
==============================================================================
Binary file. No diff available.
Added: sandbox/local_function/libs/local_function/example/profile_local_function.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/profile_local_function.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,44 @@
+
+// Copyright (C) 2009-2011 Lorenzo Caminiti
+// 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).
+
+#include <boost/local_function.hpp>
+#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;
+ profile::args(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(
+ 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;
+ }
+
+ profile::display(size, trials, sum, trials_sec.count(), decl_sec.count());
+ return 0;
+}
+
Added: sandbox/local_function/libs/local_function/example/profile_local_function_inline.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/profile_local_function_inline.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,44 @@
+
+// Copyright (C) 2009-2011 Lorenzo Caminiti
+// 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).
+
+#include <boost/local_function.hpp>
+#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;
+ profile::args(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(
+ const double& num, bind& sum, const bind& factor) {
+ sum += factor * num;
+ } BOOST_LOCAL_FUNCTION_NAME(inline add) // inlined
+ 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;
+ }
+
+ profile::display(size, trials, sum, trials_sec.count(), decl_sec.count());
+ return 0;
+}
+
Modified: sandbox/local_function/libs/local_function/example/profile_local_functor.cpp
==============================================================================
--- sandbox/local_function/libs/local_function/example/profile_local_functor.cpp (original)
+++ sandbox/local_function/libs/local_function/example/profile_local_functor.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -4,7 +4,6 @@
// License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a
// copy at http://www.boost.org/LICENSE_1_0.txt).
-//[example_profile_local_functor_cpp
#include <boost/chrono.hpp>
#include <vector>
#include <algorithm>
@@ -40,12 +39,11 @@
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.
+ for(unsigned long j = 0; j < v.size(); ++j) add(v[j]); // No for_each.
trials_sec += boost::chrono::system_clock::now() - start;
}
- profile::print(size, trials, sum, trials_sec.count(), decl_sec.count());
+ profile::display(size, trials, sum, trials_sec.count(), decl_sec.count());
return 0;
}
-//]
Added: sandbox/local_function/libs/local_function/example/profile_msvc_debug.png
==============================================================================
Binary file. No diff available.
Added: sandbox/local_function/libs/local_function/example/profile_msvc_release.png
==============================================================================
Binary file. No diff available.
Added: sandbox/local_function/libs/local_function/example/profile_phoenix.cpp
==============================================================================
--- (empty file)
+++ sandbox/local_function/libs/local_function/example/profile_phoenix.cpp 2012-01-26 17:18:26 EST (Thu, 26 Jan 2012)
@@ -0,0 +1,44 @@
+
+// Copyright (C) 2009-2011 Lorenzo Caminiti
+// 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).
+
+#include <boost/spirit/home/phoenix/statement/sequence.hpp>
+#include <boost/spirit/home/phoenix/core/reference.hpp>
+#include <boost/spirit/home/phoenix/core/argument.hpp>
+#include <boost/spirit/home/phoenix/operator/arithmetic.hpp>
+#include <boost/chrono.hpp>
+#include <iostream>
+#include <vector>
+#include <algorithm>
+#include "profile_helpers.hpp"
+
+int main(int argc, char* argv[]) {
+ unsigned long size = 0, trials = 0;
+ profile::args(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;
+ }
+
+ profile::display(size, trials, sum, trials_sec.count());
+ 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