Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72234 - sandbox/block_ptr/libs/smart_ptr/example
From: phil_at_[hidden]
Date: 2011-05-27 18:06:49


Author: pbouchard
Date: 2011-05-27 18:06:48 EDT (Fri, 27 May 2011)
New Revision: 72234
URL: http://svn.boost.org/trac/boost/changeset/72234

Log:
* Memory map speedup fix (calculating median)
Text files modified:
   sandbox/block_ptr/libs/smart_ptr/example/benchmark.cpp | 86 ++++++++++++++++++++++++++-------------
   1 files changed, 58 insertions(+), 28 deletions(-)

Modified: sandbox/block_ptr/libs/smart_ptr/example/benchmark.cpp
==============================================================================
--- sandbox/block_ptr/libs/smart_ptr/example/benchmark.cpp (original)
+++ sandbox/block_ptr/libs/smart_ptr/example/benchmark.cpp 2011-05-27 18:06:48 EDT (Fri, 27 May 2011)
@@ -14,6 +14,7 @@
 */
 
 #include <sys/time.h>
+#include <sched.h>
 
 #include <memory>
 #include <iostream>
@@ -50,42 +51,71 @@
    
 timespec diff(timespec start, timespec end);
 
+int cpu_bind(const unsigned short cpu)
+{
+ cpu_set_t mask;
+ int ret;
+
+ CPU_ZERO(&mask);
+ CPU_SET((int)cpu, &mask);
+ ret = sched_setaffinity(0, sizeof mask, &mask);
+
+ return ret;
+}
+
 int main(int argc, char* argv[])
 {
+ cpu_bind(0);
+
         timespec ts[2];
+ long median[5][3];
+
+ for (int i = 0; i < 5; ++ i)
+ {
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[0]);
+ worker_make< auto_ptr<int>, make_auto<int> >();
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[1]);
+ median[i][0] = diff(ts[0], ts[1]).tv_nsec;
+
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[0]);
+ worker_make< shared_ptr<int>, make_shared<int> >();
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[1]);
+ median[i][1] = diff(ts[0], ts[1]).tv_nsec;
+
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[0]);
+ worker_make< block_ptr<int>, make_block<int> >();
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[1]);
+ median[i][2] = diff(ts[0], ts[1]).tv_nsec;
+ }
         
         cout << "make:" << endl;
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[0]);
- worker_make< auto_ptr<int>, make_auto<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_make< shared_ptr<int>, make_shared<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_make< block_ptr<int>, make_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;
+ cout << "auto_ptr:\t" << setw(numeric_limits<long>::digits10 + 2) << median[3][0] << " ns" << endl;
+ cout << "shared_ptr:\t" << setw(numeric_limits<long>::digits10 + 2) << median[3][1] << " ns" << endl;
+ cout << "block_ptr:\t" << setw(numeric_limits<long>::digits10 + 2) << median[3][2] << " ns" << endl;
         cout << endl;
         
+ for (int i = 0; i < 5; ++ i)
+ {
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[0]);
+ worker_new< auto_ptr<int>, int >();
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[1]);
+ median[i][0] = diff(ts[0], ts[1]).tv_nsec;
+
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[0]);
+ worker_new< shared_ptr<int>, int >();
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[1]);
+ median[i][1] = diff(ts[0], ts[1]).tv_nsec;
+
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[0]);
+ worker_new< block_ptr<int>, block<int> >();
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[1]);
+ median[i][2] = diff(ts[0], ts[1]).tv_nsec;
+ }
+
         cout << "new:" << endl;
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, & ts[0]);
- worker_new< 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_new< 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_new< 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;
+ cout << "auto_ptr:\t" << setw(numeric_limits<long>::digits10 + 2) << median[3][0] << " ns" << endl;
+ cout << "shared_ptr:\t" << setw(numeric_limits<long>::digits10 + 2) << median[3][1] << " ns" << endl;
+ cout << "block_ptr:\t" << setw(numeric_limits<long>::digits10 + 2) << median[3][2] << " ns" << endl;
         cout << endl;
         
     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