Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57430 - sandbox/odeint/libs/numeric/odeint/stuff/iterator_algebra
From: karsten.ahnert_at_[hidden]
Date: 2009-11-05 17:36:11


Author: karsten
Date: 2009-11-05 17:36:10 EST (Thu, 05 Nov 2009)
New Revision: 57430
URL: http://svn.boost.org/trac/boost/changeset/57430

Log:
small adds in speed comparison for iterator
Text files modified:
   sandbox/odeint/libs/numeric/odeint/stuff/iterator_algebra/increment_decrement.cc | 71 +++++++++++++++++++++++++++++++++++++--
   1 files changed, 67 insertions(+), 4 deletions(-)

Modified: sandbox/odeint/libs/numeric/odeint/stuff/iterator_algebra/increment_decrement.cc
==============================================================================
--- sandbox/odeint/libs/numeric/odeint/stuff/iterator_algebra/increment_decrement.cc (original)
+++ sandbox/odeint/libs/numeric/odeint/stuff/iterator_algebra/increment_decrement.cc 2009-11-05 17:36:10 EST (Thu, 05 Nov 2009)
@@ -47,11 +47,18 @@
         (*first1++) -= val * (*first2++);
 }
 
+template< class Iterator1 , class Iterator2 , class Operation >
+void decrement_op( Iterator1 first1 , Iterator1 last1 , Iterator2 first2 , Operation op )
+{
+ while( first1 < last1 )
+ (*first1++) -= op(*first2++);
+}
+
 
 
 
 const size_t n = 100000;
-const size_t cycles = 500000;
+const size_t cycles = 10000;
 
 int main( int argc , char **argv )
 {
@@ -67,10 +74,7 @@
     cout << "4. a += lambda( _1 )" << endl;
     cout << "5. a += lambda( 1.0 *_1)" << endl;
 
-
     clock_t st1 , et1 , st2 , et2 , st3 , et3 , st4 , et4 , st5 , et5;
-
-
     eins1 = eins;
     zwei1 = zwei;
     st1 = clock();
@@ -121,6 +125,65 @@
     cout << "1." << tab << "2." << tab << "3." << tab << "4." << tab << "5." << endl;
     cout << time1 << tab << time2 << tab << time3 << tab << time4 << tab << time5 << endl;
 
+
+
+
+
+
+
+
+
+
+
+ cout << endl << endl;
+ cout << "Berechne a += 0.25*b, mit " << endl;
+ cout << "1. a += 0.25 * b" << endl;
+ cout << "2. a -= (-0.25)*b" << endl;
+ cout << "3. a += lambda( 0.25 *_1)" << endl;
+ cout << "4. a -= lambda( -0.25 *_1)" << endl;
+
+ eins1 = eins;
+ zwei1 = zwei;
+ st1 = clock();
+ for( size_t i=0 ; i<cycles ; ++i )
+ increment( eins1.begin() , eins1.end() , zwei1.begin() , 0.25 );
+ et1 = clock();
+ time1 = double( et1 - st1 ) / double( CLOCKS_PER_SEC );
+ cout << "1." << tab << time1 << endl;
+
+ eins1 = eins;
+ zwei1 = zwei;
+ st2 = clock();
+ for( size_t i=0 ; i<cycles ; ++i )
+ decrement( eins1.begin() , eins1.end() , zwei1.begin() , -0.25 );
+ et2 = clock();
+ time2 = double( et2 - st2 ) / double( CLOCKS_PER_SEC );
+ cout << "2." << tab << time2 << endl;
+
+
+ eins1 = eins;
+ zwei1 = zwei;
+ st3 = clock();
+ for( size_t i=0 ; i<cycles ; ++i )
+ increment_op( eins1.begin() , eins1.end() , zwei1.begin() , 0.25 * _1 );
+ et3 = clock();
+ time3 = double( et3 - st3 ) / double( CLOCKS_PER_SEC );
+ cout << "3." << tab << time3 << endl;
+
+ eins1 = eins;
+ zwei1 = zwei;
+ st4 = clock();
+ for( size_t i=0 ; i<cycles ; ++i )
+ decrement_op( eins1.begin() , eins1.end() , zwei1.begin() , -0.25 * _1 );
+ et4 = clock();
+ time4 = double( et4 - st4 ) / double( CLOCKS_PER_SEC );
+ cout << "4." << tab << time4 << endl;
+
+ cout << "1." << tab << "2." << tab << "3." << tab << "4." << endl;
+ cout << time1 << tab << time2 << tab << time3 << tab << time4 << 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