Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51593 - sandbox/reference_closure
From: dave_at_[hidden]
Date: 2009-03-03 21:41:23


Author: dave
Date: 2009-03-03 21:41:23 EST (Tue, 03 Mar 2009)
New Revision: 51593
URL: http://svn.boost.org/trac/boost/changeset/51593

Log:
* Removed unrealistic indirection from lambda case
* Changed benchmark.sh to print only test run timings, without compilation timings, for clarity

Text files modified:
   sandbox/reference_closure/benchmark.sh | 16 ++++++++++------
   sandbox/reference_closure/timings.txt | 12 ++++++++++++
   sandbox/reference_closure/trivial_closure.h | 20 +++++++++++++++++++-
   sandbox/reference_closure/trivial_initiator.h | 13 ++++++++++++-
   4 files changed, 53 insertions(+), 8 deletions(-)

Modified: sandbox/reference_closure/benchmark.sh
==============================================================================
--- sandbox/reference_closure/benchmark.sh (original)
+++ sandbox/reference_closure/benchmark.sh 2009-03-03 21:41:23 EST (Tue, 03 Mar 2009)
@@ -1,13 +1,17 @@
-#!/bin/sh
+#!/bin/bash
+set -e
 CC=g++
 
 echo compile trivial_nested
-time $CC -O2 trivial_nested.cc -o trivial_nested
-echo execute trivial_nested
+$CC -O2 -DREFERENCE_CLOSURE trivial_nested.cc -o trivial_nested
+echo compile trivial_function
+$CC -O2 -DSTD_FUNCTION trivial_function.cc -o trivial_function
+
+echo
+echo -n execute trivial_nested
 time ./trivial_nested
 
-echo compile trivial_function
-time $CC -O2 trivial_function.cc -o trivial_function
-echo execute trivial_function
+echo
+echo -n execute trivial_function
 time ./trivial_function
 

Modified: sandbox/reference_closure/timings.txt
==============================================================================
--- sandbox/reference_closure/timings.txt (original)
+++ sandbox/reference_closure/timings.txt 2009-03-03 21:41:23 EST (Tue, 03 Mar 2009)
@@ -10,3 +10,15 @@
 user 0m26.292s
 sys 0m0.056s
 
+=== Removed unrealistic indirection from lambda case ===
+
+execute trivial_nested
+real 0m1.179s
+user 0m1.166s
+sys 0m0.004s
+
+execute trivial_function
+real 0m27.693s
+user 0m27.443s
+sys 0m0.080s
+

Modified: sandbox/reference_closure/trivial_closure.h
==============================================================================
--- sandbox/reference_closure/trivial_closure.h (original)
+++ sandbox/reference_closure/trivial_closure.h 2009-03-03 21:41:23 EST (Tue, 03 Mar 2009)
@@ -1,7 +1,25 @@
 struct frame { };
-void nested( frame* ) { }
+
+inline void work( frame* )
+{
+}
+
+#if REFERENCE_CLOSURE
+
+void nested( frame* f ) { work(f); }
+
 struct closure {
     void (*func)( frame* );
     frame* scope;
     void operator()() { func( scope ); }
 };
+
+#elif STD_FUNCTION
+
+struct lambda
+{
+ frame* scope;
+ void operator()() { work( scope ); }
+};
+
+#endif

Modified: sandbox/reference_closure/trivial_initiator.h
==============================================================================
--- sandbox/reference_closure/trivial_initiator.h (original)
+++ sandbox/reference_closure/trivial_initiator.h 2009-03-03 21:41:23 EST (Tue, 03 Mar 2009)
@@ -1,5 +1,16 @@
 void initiator() {
- frame mine; closure child;
+ frame mine;
+
+#if REFERENCE_CLOSURE
+
+ closure child;
     child.func = nested; child.scope = &mine;
+
+#elif STD_FUNCTION
+
+ lambda child;
+ child.scope = &mine;
+
+#endif
     passer( child );
 }


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