Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72005 - sandbox/block_ptr/libs/smart_ptr/example
From: phil_at_[hidden]
Date: 2011-05-16 18:28:41


Author: pbouchard
Date: 2011-05-16 18:28:40 EDT (Mon, 16 May 2011)
New Revision: 72005
URL: http://svn.boost.org/trac/boost/changeset/72005

Log:
* Added benchmark
Added:
   sandbox/block_ptr/libs/smart_ptr/example/benchmark.cpp (contents, props changed)
Text files modified:
   sandbox/block_ptr/libs/smart_ptr/example/Jamfile.v2 | 1 +
   1 files changed, 1 insertions(+), 0 deletions(-)

Modified: sandbox/block_ptr/libs/smart_ptr/example/Jamfile.v2
==============================================================================
--- sandbox/block_ptr/libs/smart_ptr/example/Jamfile.v2 (original)
+++ sandbox/block_ptr/libs/smart_ptr/example/Jamfile.v2 2011-05-16 18:28:40 EDT (Mon, 16 May 2011)
@@ -32,4 +32,5 @@
     [ run block_ptr_test3.cpp boost_thread boost_unit_test_framework ]
     [ run t100_test1.cpp boost_thread boost_regex ]
     [ run thread_test.cpp boost_thread ]
+ [ run benchmark.cpp boost_thread ]
     ;

Added: sandbox/block_ptr/libs/smart_ptr/example/benchmark.cpp
==============================================================================
--- (empty file)
+++ sandbox/block_ptr/libs/smart_ptr/example/benchmark.cpp 2011-05-16 18:28:40 EDT (Mon, 16 May 2011)
@@ -0,0 +1,56 @@
+#include <sys/time.h>
+
+#include <memory>
+#include <iostream>
+#include <boost/shared_ptr.hpp>
+#define BOOST_BP_RAW_POINTER
+#include <boost/block_ptr.hpp>
+
+using namespace std;
+using namespace boost;
+
+template <typename T, typename U>
+ void worker()
+ {
+ T p;
+
+ for (int i = 0; i < 100000; ++ i)
+ p.reset(new U);
+ }
+
+timespec diff(timespec start, timespec end);
+
+int main(int argc, char* argv[])
+{
+ timespec ts[2];
+
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[0]);
+ worker< auto_ptr<int>, int >();
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[1]);
+ cout << "auto_ptr:\t" << setw(numeric_limits<long>::digits10 + 2) << diff(ts[0], ts[1]).tv_nsec << " ns" << endl;
+
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[0]);
+ worker< shared_ptr<int>, int >();
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[1]);
+ cout << "shared_ptr:\t" << setw(numeric_limits<long>::digits10 + 2) << diff(ts[0], ts[1]).tv_nsec << " ns" << endl;
+
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[0]);
+ worker< block_ptr<int>, block<int> >();
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[1]);
+ cout << "block_ptr:\t" << setw(numeric_limits<long>::digits10 + 2) << diff(ts[0], ts[1]).tv_nsec << " ns" << endl;
+
+ return 0;
+}
+
+timespec diff(timespec start, timespec end)
+{
+ timespec temp;
+ if ((end.tv_nsec-start.tv_nsec)<0) {
+ temp.tv_sec = end.tv_sec-start.tv_sec-1;
+ temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
+ } else {
+ temp.tv_sec = end.tv_sec-start.tv_sec;
+ temp.tv_nsec = end.tv_nsec-start.tv_nsec;
+ }
+ return temp;
+}


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