Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51600 - sandbox/reference_closure
From: dave_at_[hidden]
Date: 2009-03-04 01:23:02


Author: dave
Date: 2009-03-04 01:23:00 EST (Wed, 04 Mar 2009)
New Revision: 51600
URL: http://svn.boost.org/trac/boost/changeset/51600

Log:
Add move semantics emulation and ability to disable work from command line
Measure with move semantics, with and without work.

Added:
   sandbox/reference_closure/move.h (contents, props changed)
Text files modified:
   sandbox/reference_closure/benchmark.sh | 8 ++++----
   sandbox/reference_closure/parallel_lib.cc | 9 ++++++++-
   sandbox/reference_closure/timings.txt | 27 +++++++++++++++++++++++++++
   sandbox/reference_closure/trivial_closure.h | 2 ++
   4 files changed, 41 insertions(+), 5 deletions(-)

Modified: sandbox/reference_closure/benchmark.sh
==============================================================================
--- sandbox/reference_closure/benchmark.sh (original)
+++ sandbox/reference_closure/benchmark.sh 2009-03-04 01:23:00 EST (Wed, 04 Mar 2009)
@@ -3,12 +3,12 @@
 CC=g++
 
 set -x
-$CC -O2 -DREFERENCE_CLOSURE parallel_lib.cc -c -o parallel_lib_refclosure.o
-$CC -O2 -DREFERENCE_CLOSURE main.cc -c -o main_refclosure.o
+$CC -O2 -DREFERENCE_CLOSURE $CXXFLAGS parallel_lib.cc -c -o parallel_lib_refclosure.o
+$CC -O2 -DREFERENCE_CLOSURE $CXXFLAGS main.cc -c -o main_refclosure.o
 $CC main_refclosure.o parallel_lib_refclosure.o -o refclosure
 
-$CC -O2 -DSTD_FUNCTION parallel_lib.cc -c -o parallel_lib_stdfunction.o
-$CC -O2 -DSTD_FUNCTION main.cc -c -o main_stdfunction.o
+$CC -O2 -DSTD_FUNCTION $CXXFLAGS parallel_lib.cc -c -o parallel_lib_stdfunction.o
+$CC -O2 -DSTD_FUNCTION $CXXFLAGS main.cc -c -o main_stdfunction.o
 $CC main_stdfunction.o parallel_lib_stdfunction.o -o stdfunction
 
 set +x

Added: sandbox/reference_closure/move.h
==============================================================================
--- (empty file)
+++ sandbox/reference_closure/move.h 2009-03-04 01:23:00 EST (Wed, 04 Mar 2009)
@@ -0,0 +1,17 @@
+// Copyright David Abrahams 2009. 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)
+#ifndef MOVE_DWA200934_H
+# define MOVE_DWA200934_H
+
+namespace std
+{
+ template <class T>
+ struct rvalue : T
+ {};
+
+ template <class T>
+ inline rvalue<T>& move(T& x) { return static_cast<rvalue<T>&>(x); }
+}
+
+#endif // MOVE_DWA200934_H

Modified: sandbox/reference_closure/parallel_lib.cc
==============================================================================
--- sandbox/reference_closure/parallel_lib.cc (original)
+++ sandbox/reference_closure/parallel_lib.cc 2009-03-04 01:23:00 EST (Wed, 04 Mar 2009)
@@ -1,4 +1,11 @@
 #include "callback_type.h"
+#include "move.h"
 
 void executer( callback_type arg ) { arg(); }
-void passer( callback_type arg ) { executer( arg ); }
+void passer( callback_type arg ) { executer(
+#if STD_FUNCTION
+ std::move( arg )
+#elif REFERENCE_CLOSURE
+ arg
+#endif
+ ); }

Modified: sandbox/reference_closure/timings.txt
==============================================================================
--- sandbox/reference_closure/timings.txt (original)
+++ sandbox/reference_closure/timings.txt 2009-03-04 01:23:00 EST (Wed, 04 Mar 2009)
@@ -96,3 +96,30 @@
 
 t(std::function<>) / t(reference_closure): 2.1
 
+=== Add move semantics for std::function ===
+
+execute refclosure
+real 0m15.236s
+user 0m14.778s
+sys 0m0.033s
+
+execute stdfunction
+real 0m29.287s
+user 0m28.277s
+sys 0m0.066s
+
+t(std::function<>) / t(reference_closure): 1.9
+
+=== Same thing with no work: measures only overhead ===
+
+execute refclosure
+real 0m12.445s
+user 0m12.399s
+sys 0m0.022s
+
+execute stdfunction
+real 0m23.270s
+user 0m23.185s
+sys 0m0.050s
+
+t(std::function<>) / t(reference_closure): 1.9

Modified: sandbox/reference_closure/trivial_closure.h
==============================================================================
--- sandbox/reference_closure/trivial_closure.h (original)
+++ sandbox/reference_closure/trivial_closure.h 2009-03-04 01:23:00 EST (Wed, 04 Mar 2009)
@@ -1,6 +1,8 @@
 #ifndef TRIVIAL_CLOSURE2_DWA200933_H
 # define TRIVIAL_CLOSURE2_DWA200933_H
 
+#include "move.h"
+
 struct frame { double a, b, c; };
 
 inline void work( frame* f )


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