Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59510 - in sandbox/statistics/detail/assign: boost/assign libs/assign/example libs/assign/test
From: erwann.rogard_at_[hidden]
Date: 2010-02-05 09:33:26


Author: e_r
Date: 2010-02-05 09:33:26 EST (Fri, 05 Feb 2010)
New Revision: 59510
URL: http://svn.boost.org/trac/boost/changeset/59510

Log:
m
Text files modified:
   sandbox/statistics/detail/assign/boost/assign/cref_list_of2.hpp | 11
   sandbox/statistics/detail/assign/libs/assign/example/cref_list_of2.cpp | 2
   sandbox/statistics/detail/assign/libs/assign/example/cref_list_of2.h | 2
   sandbox/statistics/detail/assign/libs/assign/test/cref_list_of2_speed.cpp | 309 +++++++++++++++++++++++++++++++--------
   sandbox/statistics/detail/assign/libs/assign/test/cref_list_of2_speed.h | 8
   5 files changed, 249 insertions(+), 83 deletions(-)

Modified: sandbox/statistics/detail/assign/boost/assign/cref_list_of2.hpp
==============================================================================
--- sandbox/statistics/detail/assign/boost/assign/cref_list_of2.hpp (original)
+++ sandbox/statistics/detail/assign/boost/assign/cref_list_of2.hpp 2010-02-05 09:33:26 EST (Fri, 05 Feb 2010)
@@ -23,7 +23,7 @@
 namespace boost{
 namespace assign{
 
- // This is as efficient as Boost.Assign's cref_list_of but more
+ // This a variation on Boost.Assign's cref_list_of that is more
     // convenient as the number of items must not be specified in advance
     // Usage : vec = cref_list2_of(a)(b)(c)
     // The idea of this class was developed in collaboration with M.P.G.
@@ -42,7 +42,7 @@
         typedef boost::array<typename ref<T>::type,N> type;
     };
             
- template<typename L,typename R,int N>
+ template<typename L,typename T,int N>
     struct expr;
             
     template<typename E,typename T,int N>
@@ -130,7 +130,7 @@
         }
                 
         typedef boost::shared_ptr<ref_array_> smart_ptr_;
- mutable smart_ptr_ ptr;
+ smart_ptr_ ptr;
                 
     };
             
@@ -145,13 +145,13 @@
     }
             
     template<typename A,typename E,typename T,int N>
- void write_to_array(A& a,expr<E,T,N>& e,false_ exit){
+ void write_to_array(A& a,expr<E,T,N>& e,false_ /*exit*/){
         a[N-1] = e.ref;
         write_to_array(a,e.previous);
     }
             
     template<typename A,typename E,typename T,int N>
- void write_to_array(A& a,expr<E,T,N>& e,true_ exit){
+ void write_to_array(A& a,expr<E,T,N>& e,true_ /*exit*/){
         a[N-1] = e.ref;
     }
             
@@ -181,4 +181,3 @@
 }// boost
 
 #endif
-

Modified: sandbox/statistics/detail/assign/libs/assign/example/cref_list_of2.cpp
==============================================================================
--- sandbox/statistics/detail/assign/libs/assign/example/cref_list_of2.cpp (original)
+++ sandbox/statistics/detail/assign/libs/assign/example/cref_list_of2.cpp 2010-02-05 09:33:26 EST (Fri, 05 Feb 2010)
@@ -100,8 +100,6 @@
         
     }
 
-
-
         os << "<- " << std::endl;
     
 };

Modified: sandbox/statistics/detail/assign/libs/assign/example/cref_list_of2.h
==============================================================================
--- sandbox/statistics/detail/assign/libs/assign/example/cref_list_of2.h (original)
+++ sandbox/statistics/detail/assign/libs/assign/example/cref_list_of2.h 2010-02-05 09:33:26 EST (Fri, 05 Feb 2010)
@@ -1,5 +1,5 @@
 //////////////////////////////////////////////////////////////////////////////
-// example::cerf_list_of2.h //
+// example::cref_list_of2.h //
 // //
 // (C) Copyright 2010 Erwann Rogard //
 // Use, modification and distribution are subject to the //

Modified: sandbox/statistics/detail/assign/libs/assign/test/cref_list_of2_speed.cpp
==============================================================================
--- sandbox/statistics/detail/assign/libs/assign/test/cref_list_of2_speed.cpp (original)
+++ sandbox/statistics/detail/assign/libs/assign/test/cref_list_of2_speed.cpp 2010-02-05 09:33:26 EST (Fri, 05 Feb 2010)
@@ -1,91 +1,264 @@
 //////////////////////////////////////////////////////////////////////////////
 // test::cref_list_of2_speed.cpp //
 // //
-// (C) Copyright 2010 Erwann Rogard //
-// Use, modification and distribution are subject to 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) //
 //////////////////////////////////////////////////////////////////////////////
-#include <boost/timer.hpp>
-#include <ostream>
+#include <iostream>
 #include <vector>
-#include <boost/format.hpp>
+#include <string>
+#include <algorithm>
+#include <boost/progress.hpp>
+#include <boost/bind.hpp>
 #include <boost/typeof/typeof.hpp>
-#include <boost/assign/list_of.hpp>
 #include <boost/assign/cref_list_of2.hpp>
 #include <libs/assign/test/cref_list_of2_speed.h>
 
+// This file is courtesy of M.P.G
+
+// http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx
+inline double uniform_deviate ( int seed )
+{
+ return seed * ( 1.0 / ( RAND_MAX + 1.0 ) );
+}
+inline int rand(int M, int N) // Range [M..N)
+{
+ return int(M + uniform_deviate(std::rand()) * (N - M));
+}
+char rand_letter()
+{
+ return char(rand('a', 'z' + 1));
+}
+
+std::string rand_str(int len)
+{
+ std::string result;
+ std::generate_n(std::back_inserter(result), len, &rand_letter);
+ return result;
+}
+
 void test_cref_list_of2_speed(std::ostream& os)
 {
         os << "-> test_cref_listof2_speed : " << std::endl;
 
- typedef boost::timer timer_;
- using namespace boost::assign;
-
- typedef std::vector<int> vec_ints_;
- typedef boost::format fmt_;
- int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
- fmt_ fmt("n = %1%");
- fmt_ fmt2("cref_list_of : t = %1%\n");
- fmt_ fmt3("cref_list_of2 : t = %1%\n");
- os << fmt_(fmt)%4 << std::endl;
- {
- timer_ timer;
- vec_ints_ vec_ints = cref_list_of<4>(a)(b)(c)(d);
- double t = timer.elapsed();
- os << (fmt_(fmt2)%t).str();
- }
- {
- timer_ timer;
- vec_ints_ vec_ints = cref_list_of2(a)(b)(c)(d);
- double t = timer.elapsed();
- os << (fmt_(fmt3)%t).str();
- }
- os << fmt_(fmt)%10 << std::endl;
+ typedef boost::progress_timer timer_;
+
+ typedef std::vector<std::string> Vec;
+
+ int const str_len = 100, // Irrelevant bec. we don't copy them
+ max_N = 200;
+
+ const int n = 100 * 1000;
+ int N;
+ Vec v;
+ std::generate_n(std::back_inserter(v), max_N, boost::bind(&rand_str, str_len));
+
     {
- timer_ timer;
- vec_ints_ vec_ints = ref_list_of<10>(a)(b)(c)(d)(e)(f)(g)(h)(i)(j);
- double t = timer.elapsed();
- os << (fmt_(fmt2)%t).str();
+ N = 1;
+ assert(N < max_N);
+ {
+ timer_ timer;
+ for(int i = 0; i < n; ++i)
+ {
+ BOOST_AUTO(rng, boost::assign::cref_list_of2(v[0]));
+ int sz = (int)rng.size();
+ if(sz != N)
+ os << "ERROR\n";
+ }
+ os << "cref_list_of2(" << N << ") => ";
+ }
+ {
+ timer_ timer;
+ for(int i = 0; i < n; ++i)
+ {
+ BOOST_AUTO(rng, boost::assign::cref_list_of<1>(v[0]));
+ int sz = (int)rng.size();
+ if(sz != N)
+ os << "ERROR\n";
+ }
+ os << "cref_list_of(" << N << ") => ";
+ }
     }
     {
- timer_ timer;
- vec_ints_ vec_ints = cref_list_of2(a)(b)(c)(d)(e)(f)(g)(h)(i)(j);
- double t = timer.elapsed();
- os << (fmt_(fmt3)%t).str();
+ N = 3;
+ assert(N < max_N);
+ {
+ timer_ timer;
+ for(int i = 0; i < n; ++i)
+ {
+ BOOST_AUTO(rng, boost::assign::cref_list_of2(v[0])(v[1])(v[2]));
+ int sz = (int)rng.size();
+ if(sz != N)
+ os << "ERROR\n";
+ }
+ os << "cref_list_of2(" << N << ") => ";
+ }
+ {
+ timer_ timer;
+ for(int i = 0; i < n; ++i)
+ {
+ BOOST_AUTO(rng, boost::assign::cref_list_of<3>(v[0])(v[1])(v[2]));
+ int sz = (int)rng.size();
+ if(sz != N)
+ os << "ERROR\n";
+ }
+ os << "cref_list_of(" << N << ") => ";
+ }
     }
- os << fmt_(fmt)%28 << std::endl;
+
     {
- timer_ timer;
- vec_ints_ vec_ints = cref_list_of<28>(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)(q)(r)(s)(t)(u)(v)(w)(x)(y)(z);
- double t = timer.elapsed();
- os << (fmt_(fmt2)%t).str();
+ N = 10;
+ assert(N < max_N);
+ {
+ timer_ timer;
+ for(int i = 0; i < n; ++i)
+ {
+ BOOST_AUTO(rng, boost::assign::cref_list_of2(v[0])(v[1])(v[2])(v[3])(v[4])(v[5])(v[6])(v[7])(v[8])(v[9]));
+ int sz = (int)rng.size();
+ if(sz != N)
+ os << "ERROR\n";
+ }
+ os << "cref_list_of2(" << N << ") => ";
+ }
+ {
+ timer_ timer;
+ for(int i = 0; i < n; ++i)
+ {
+ BOOST_AUTO(rng, boost::assign::cref_list_of<10>(v[0])(v[1])(v[2])(v[3])(v[4])(v[5])(v[6])(v[7])(v[8])(v[9]));
+ int sz = (int)rng.size();
+ if(sz != N)
+ os << "ERROR\n";
+ }
+ os << "cref_list_of(" << N << ") => ";
+ }
     }
+
     {
- timer_ timer;
- vec_ints_ vec_ints = cref_list_of2(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)(q)(r)(s)(t)(u)(v)(w)(x)(y)(z);
- double t = timer.elapsed();
- os << (fmt_(fmt3)%t).str();
- }
- os << fmt_(fmt)%112 << std::endl;
+ N = 30;
+ assert(N < max_N);
+ {
+ timer_ timer;
+ for(int i = 0; i < n; ++i)
+ {
+ BOOST_AUTO(rng, boost::assign::cref_list_of2(v[0])(v[1])(v[2])(v[3])(v[4])(v[5])(v[6])(v[7])(v[8])(v[9])
+ (v[10])(v[11])(v[12])(v[13])(v[14])(v[15])(v[16])(v[17])(v[18])(v[19])
+ (v[20])(v[21])(v[22])(v[23])(v[24])(v[25])(v[26])(v[27])(v[28])(v[29]));
+ int sz = (int)rng.size();
+ if(sz != N)
+ os << "ERROR\n";
+ }
+ os << "cref_list_of2(" << N << ") => ";
+ }
+ {
+ timer_ timer;
+ for(int i = 0; i < n; ++i)
+ {
+ BOOST_AUTO(rng, boost::assign::cref_list_of<30>(v[0])(v[1])(v[2])(v[3])(v[4])(v[5])(v[6])(v[7])(v[8])(v[9])
+ (v[10])(v[11])(v[12])(v[13])(v[14])(v[15])(v[16])(v[17])(v[18])(v[19])
+ (v[20])(v[21])(v[22])(v[23])(v[24])(v[25])(v[26])(v[27])(v[28])(v[29]));
+ int sz = (int)rng.size();
+ if(sz != N)
+ os << "ERROR\n";
+ }
+ os << "cref_list_of(" << N << ") => ";
+ }
+ }
+
     {
- timer_ timer;
- vec_ints_ vec_ints = cref_list_of<112>(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)(q)(r)(s)(t)(u)(v)(w)(x)(y)(z)
- (a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)(q)(r)(s)(t)(u)(v)(w)(x)(y)(z)
- (a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)(q)(r)(s)(t)(u)(v)(w)(x)(y)(z)
- (a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)(q)(r)(s)(t)(u)(v)(w)(x)(y)(z);
- double t = timer.elapsed();
- os << (fmt_(fmt2)%t).str();
- }
+ N = 80;
+ assert(N < max_N);
+ {
+ timer_ timer;
+ for(int i = 0; i < n; ++i)
+ {
+ BOOST_AUTO(rng, boost::assign::cref_list_of2( v[0])( v[1])( v[2])( v[3])( v[4])( v[5])( v[6])( v[7])( v[8])( v[9])
+ (v[10])(v[11])(v[12])(v[13])(v[14])(v[15])(v[16])(v[17])(v[18])(v[19])
+ (v[20])(v[21])(v[22])(v[23])(v[24])(v[25])(v[26])(v[27])(v[28])(v[29])
+ (v[30])(v[31])(v[32])(v[33])(v[34])(v[35])(v[36])(v[37])(v[38])(v[39])
+ (v[40])(v[41])(v[42])(v[43])(v[44])(v[45])(v[46])(v[47])(v[48])(v[49])
+ (v[50])(v[51])(v[52])(v[53])(v[54])(v[55])(v[56])(v[57])(v[58])(v[59])
+ (v[60])(v[61])(v[62])(v[63])(v[64])(v[65])(v[66])(v[67])(v[68])(v[69])
+ (v[70])(v[71])(v[72])(v[73])(v[74])(v[75])(v[76])(v[77])(v[78])(v[79]));
+ int sz = (int)rng.size();
+ if(sz != N)
+ os << "ERROR\n";
+ }
+ os << "cref_list_of2(" << N << ") => ";
+ }
+ {
+ timer_ timer;
+ for(int i = 0; i < n; ++i)
+ {
+ BOOST_AUTO(rng, boost::assign::cref_list_of<80>( v[0])( v[1])( v[2])( v[3])( v[4])( v[5])( v[6])( v[7])( v[8])( v[9])
+ (v[10])(v[11])(v[12])(v[13])(v[14])(v[15])(v[16])(v[17])(v[18])(v[19])
+ (v[20])(v[21])(v[22])(v[23])(v[24])(v[25])(v[26])(v[27])(v[28])(v[29])
+ (v[30])(v[31])(v[32])(v[33])(v[34])(v[35])(v[36])(v[37])(v[38])(v[39])
+ (v[40])(v[41])(v[42])(v[43])(v[44])(v[45])(v[46])(v[47])(v[48])(v[49])
+ (v[50])(v[51])(v[52])(v[53])(v[54])(v[55])(v[56])(v[57])(v[58])(v[59])
+ (v[60])(v[61])(v[62])(v[63])(v[64])(v[65])(v[66])(v[67])(v[68])(v[69])
+ (v[70])(v[71])(v[72])(v[73])(v[74])(v[75])(v[76])(v[77])(v[78])(v[79]));
+ int sz = (int)rng.size();
+ if(sz != N)
+ os << "ERROR\n";
+ }
+ os << "cref_list_of(" << N << ") => ";
+ }
+ }
+
     {
- timer_ timer;
- vec_ints_ vec_ints = cref_list_of2(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)(q)(r)(s)(t)(u)(v)(w)(x)(y)(z)
- (a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)(q)(r)(s)(t)(u)(v)(w)(x)(y)(z)
- (a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)(q)(r)(s)(t)(u)(v)(w)(x)(y)(z)
- (a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)(q)(r)(s)(t)(u)(v)(w)(x)(y)(z);
- double t = timer.elapsed();
- os << (fmt_(fmt3)%t).str();
- }
+ N = 160;
+ assert(N < max_N);
+ {
+ timer_ timer;
+ for(int i = 0; i < n; ++i)
+ {
+ BOOST_AUTO(rng, boost::assign::cref_list_of2( v[0])( v[1])( v[2])( v[3])( v[4])( v[5])( v[6])( v[7])( v[8])( v[9])
+ (v[10])(v[11])(v[12])(v[13])(v[14])(v[15])(v[16])(v[17])(v[18])(v[19])
+ (v[20])(v[21])(v[22])(v[23])(v[24])(v[25])(v[26])(v[27])(v[28])(v[29])
+ (v[30])(v[31])(v[32])(v[33])(v[34])(v[35])(v[36])(v[37])(v[38])(v[39])
+ (v[40])(v[41])(v[42])(v[43])(v[44])(v[45])(v[46])(v[47])(v[48])(v[49])
+ (v[50])(v[51])(v[52])(v[53])(v[54])(v[55])(v[56])(v[57])(v[58])(v[59])
+ (v[60])(v[61])(v[62])(v[63])(v[64])(v[65])(v[66])(v[67])(v[68])(v[69])
+ (v[70])(v[71])(v[72])(v[73])(v[74])(v[75])(v[76])(v[77])(v[78])(v[79])
+ (v[80])(v[88])(v[82])(v[83])(v[84])(v[85])(v[86])(v[87])(v[88])(v[89])
+ (v[90])(v[91])(v[92])(v[93])(v[94])(v[95])(v[96])(v[97])(v[98])(v[99])
+ (v[100])(v[101])(v[102])(v[103])(v[104])(v[105])(v[106])(v[107])(v[108])(v[109])
+ (v[110])(v[111])(v[112])(v[113])(v[114])(v[115])(v[116])(v[117])(v[118])(v[119])
+ (v[120])(v[121])(v[122])(v[123])(v[124])(v[125])(v[126])(v[127])(v[128])(v[129])
+ (v[130])(v[131])(v[132])(v[133])(v[134])(v[135])(v[136])(v[137])(v[138])(v[139])
+ (v[140])(v[141])(v[142])(v[143])(v[144])(v[145])(v[146])(v[147])(v[148])(v[149])
+ (v[150])(v[151])(v[152])(v[153])(v[154])(v[155])(v[156])(v[157])(v[158])(v[159]));
+ int sz = (int)rng.size();
+ if(sz != N)
+ os << "ERROR\n";
+ }
+ os << "cref_list_of2(" << N << ") => ";
+ }
+ {
+ timer_ timer;
+ for(int i = 0; i < n; ++i)
+ {
+ BOOST_AUTO(rng, boost::assign::cref_list_of<160>( v[0])( v[1])( v[2])( v[3])( v[4])( v[5])( v[6])( v[7])( v[8])( v[9])
+ (v[10])(v[11])(v[12])(v[13])(v[14])(v[15])(v[16])(v[17])(v[18])(v[19])
+ (v[20])(v[21])(v[22])(v[23])(v[24])(v[25])(v[26])(v[27])(v[28])(v[29])
+ (v[30])(v[31])(v[32])(v[33])(v[34])(v[35])(v[36])(v[37])(v[38])(v[39])
+ (v[40])(v[41])(v[42])(v[43])(v[44])(v[45])(v[46])(v[47])(v[48])(v[49])
+ (v[50])(v[51])(v[52])(v[53])(v[54])(v[55])(v[56])(v[57])(v[58])(v[59])
+ (v[60])(v[61])(v[62])(v[63])(v[64])(v[65])(v[66])(v[67])(v[68])(v[69])
+ (v[70])(v[71])(v[72])(v[73])(v[74])(v[75])(v[76])(v[77])(v[78])(v[79])
+ (v[80])(v[88])(v[82])(v[83])(v[84])(v[85])(v[86])(v[87])(v[88])(v[89])
+ (v[90])(v[91])(v[92])(v[93])(v[94])(v[95])(v[96])(v[97])(v[98])(v[99])
+ (v[100])(v[101])(v[102])(v[103])(v[104])(v[105])(v[106])(v[107])(v[108])(v[109])
+ (v[110])(v[111])(v[112])(v[113])(v[114])(v[115])(v[116])(v[117])(v[118])(v[119])
+ (v[120])(v[121])(v[122])(v[123])(v[124])(v[125])(v[126])(v[127])(v[128])(v[129])
+ (v[130])(v[131])(v[132])(v[133])(v[134])(v[135])(v[136])(v[137])(v[138])(v[139])
+ (v[140])(v[141])(v[142])(v[143])(v[144])(v[145])(v[146])(v[147])(v[148])(v[149])
+ (v[150])(v[151])(v[152])(v[153])(v[154])(v[155])(v[156])(v[157])(v[158])(v[159]));
+ int sz = (int)rng.size();
+ if(sz != N)
+ os << "ERROR\n";
+ }
+ os << "cref_list_of(" << N << ") => ";
+ }
+ }
+ os << "<- " << std::endl;
     
- os << std::endl;
-}
\ No newline at end of file
+};

Modified: sandbox/statistics/detail/assign/libs/assign/test/cref_list_of2_speed.h
==============================================================================
--- sandbox/statistics/detail/assign/libs/assign/test/cref_list_of2_speed.h (original)
+++ sandbox/statistics/detail/assign/libs/assign/test/cref_list_of2_speed.h 2010-02-05 09:33:26 EST (Fri, 05 Feb 2010)
@@ -1,13 +1,9 @@
 //////////////////////////////////////////////////////////////////////////////
 // test::cref_list_of2_speed.h //
 // //
-// (C) Copyright 2010 Erwann Rogard //
-// Use, modification and distribution are subject to 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 LIBS_ASSIGN_TEST_CREF_LIST_OF2_SPEED_ER_2010_HPP
-#define LIBS_ASSIGN_TEST_CREF_LIST_OF2_SPEED_ER_2010_HPP
+#ifndef LIBS_ASSIGN_TEST_CREF_LIST_OF2_SPEED_ER_2010_H
+#define LIBS_ASSIGN_TEST_CREF_LIST_OF2_SPEED_ER_2010_H
 #include <ostream>
 
 void test_cref_list_of2_speed(std::ostream&);


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