Files Classes Functions Hierarchy
#include <cassert>#include <iostream>#include <vector>#include <algorithm>#include <print.h>#include <aclock.h>#include <dumbarray.h>#include <dumbarraytest.h>
Go to the source code of this file.
Functions | |
| void | dumbarraytest01 () |
| void | dumbarraytest02 () |
| void | sumintarray (int &sum, int *v, uintc n) |
| template<typename T > | |
| void | sumintarray (int &sum, T &v, uintc n, uintc n2) |
| void | dumbarraytest03 () |
| void dumbarraytest01 | ( | ) |
Definition at line 17 of file dumbarraytest.cpp.
References SHOW.
Referenced by main().
00018 { 00019 cout << "Testing the dumb array class" << endl; 00020 double a = 3.0; 00021 double b = 5.0; 00022 double c = 7.0; 00023 00024 cout << SHOW(a) << endl; 00025 cout << SHOW(b) << endl; 00026 cout << SHOW(c) << endl; 00027 00028 double ** v = new double * [3]; 00029 00030 dumbarray<double> vi(v,3,false); 00031 00032 cout << "Set the pointers" << endl; 00033 vi(0) = & a; 00034 vi(1) = & b; 00035 vi(2) = & c; 00036 00037 cout << SHOW(vi[0]) << endl; 00038 cout << SHOW(vi[1]) << endl; 00039 cout << SHOW(vi[2]) << endl; 00040 00041 cout << SHOW((vi[1]=7.2)) << endl; 00042 00043 cout << SHOW(b) << endl; 00044 00045 cout << "Now have a second pointer v2 but without ownership." << endl; 00046 dumbarray<double> v2(vi); 00047 00048 cout << SHOW(v2[1]) << endl; 00049 00050 cout << "If this crashes on program termination there is a bug." << endl; 00051 cout << "ie I am testing that memory was not double deleted." << endl; 00052 00053 delete[] v; 00054 }
| void dumbarraytest02 | ( | ) |
Definition at line 57 of file dumbarraytest.cpp.
References SHOW.
Referenced by main().
00058 { 00059 cout << "Testing dumbarray 2." << endl; 00060 cout << "This time have dumbarray own the pointer array." << endl; 00061 00062 double a = 3.0; 00063 double b = 5.0; 00064 double c = 7.0; 00065 00066 cout << SHOW(a) << endl; 00067 cout << SHOW(b) << endl; 00068 cout << SHOW(c) << endl; 00069 00070 dumbarray<double> vi(3); 00071 vi(0) = &a; 00072 vi(1) = &b; 00073 vi(2) = &c; 00074 00075 cout << SHOW(vi[0]) << endl; 00076 cout << SHOW(vi[1]) << endl; 00077 cout << SHOW(vi[2]) << endl; 00078 }
| void dumbarraytest03 | ( | ) |
Definition at line 106 of file dumbarraytest.cpp.
References aclock::diff_ms(), aclock::measure(), SHOW, and sumintarray().
Referenced by main().
00107 { 00108 cout << "Testing the timmes for accessing with a dumbarray rather" << endl; 00109 cout << " than a contiguous pointer." << endl; 00110 00111 cout << "For optimized code I got dumbarray taking twice as long as " << endl; 00112 cout << " vector<int> and int* access. " << endl; 00113 00114 uint N=1000; 00115 //uintc N=10000; 00116 00117 00118 vector< int * > v1(N); 00119 00120 vector<int> v2(N); 00121 00122 for (uint i=0; i<N; ++i) 00123 { 00124 v2[i] = i; 00125 00126 v1[i] = & v2[i]; 00127 } 00128 00129 random_shuffle(v1.begin(),v1.end()); 00130 00131 dumbarray<int> v3(& v1[0],N,false); 00132 00133 00134 aclock ac; 00135 00136 int sum; 00137 ac.measure(); 00138 sumintarray(sum,v2,N,N); 00139 ac.measure(); 00140 cout << "vector<int>" << endl; 00141 cout << SHOW(sum) << endl; 00142 cout << SHOW(ac.diff_ms()) << endl; 00143 00144 00145 ac.measure(); 00146 sumintarray(sum,v3,N,N); 00147 ac.measure(); 00148 cout << "dumbarray<int>" << endl; 00149 cout << SHOW(sum) << endl; 00150 cout << SHOW(ac.diff_ms()) << endl; 00151 00152 int * v4 = & v2[0]; 00153 ac.measure(); 00154 sumintarray(sum,v4,N,N); 00155 ac.measure(); 00156 cout << "int *" << endl; 00157 cout << SHOW(sum) << endl; 00158 cout << SHOW(ac.diff_ms()) << endl; 00159 }
Definition at line 92 of file dumbarraytest.cpp.
00093 { 00094 sum = 0; 00095 00096 for (uint k=0; k<n2; ++k) 00097 { 00098 for (uint i=0; i<n; ++i) 00099 { 00100 sum += v[i]; 00101 } 00102 } 00103 }
| void sumintarray | ( | int & | sum, | |
| int * | v, | |||
| uintc | n | |||
| ) |
Definition at line 81 of file dumbarraytest.cpp.
Referenced by dumbarraytest03().
00082 { 00083 sum = 0; 00084 for (uint i=0; i<n; ++i) 00085 { 00086 sum += v[i]; 00087 } 00088 }
1.5.8