Skip to content

Commit 9973da0

Browse files
author
Oğuzhan Katlı
committed
- cpu cache misses updated.
1 parent ef67da5 commit 9973da0

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/3-SmartPointer/cpu_cache_misses.hpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,32 +73,31 @@ namespace cpu_cache_misses {
7373
/*
7474
// checked way access of array
7575
struct two_dim_arr_access_helper {
76-
explicit two_dim_arr_access_helper(T* _a) noexcept : arr(_a) { }
76+
explicit two_dim_arr_access_helper(T* _a) noexcept : arr(_a) { }
7777
78-
T& operator[](unsigned int index) {
79-
assert(arr[index] != nullptr);
80-
return arr[index];
81-
}
78+
T& operator[](unsigned int index) {
79+
assert(arr[index] != nullptr);
80+
return arr[index];
81+
}
8282
83-
T const& operator[](unsigned int index) const {
84-
assert(arr[index] != nullptr);
85-
return arr[index];
86-
}
83+
T const& operator[](unsigned int index) const {
84+
assert(arr[index] != nullptr);
85+
return arr[index];
86+
}
8787
private:
88-
T* arr;
88+
T* arr;
8989
};
9090
9191
two_dim_arr_access_helper operator[](unsigned int index) {
92-
assert(data_[index] != nullptr);
93-
return two_dim_arr_access_helper(data_[index]);
92+
assert(data_[index] != nullptr);
93+
return two_dim_arr_access_helper(data_[index]);
9494
}
9595
9696
two_dim_arr_access_helper operator[](unsigned int index) const {
97-
assert(data_[index] != nullptr);
98-
return two_dim_arr_access_helper(data_[index]);
97+
assert(data_[index] != nullptr);
98+
return two_dim_arr_access_helper(data_[index]);
9999
}
100100
*/
101-
102101
private:
103102
Type** data_;
104103
unsigned int rowsize;
@@ -149,26 +148,19 @@ namespace cpu_cache_misses {
149148
};
150149

151150
struct benchmarkresult {
152-
//benchmarkresult() = default;
153-
//benchmarkresult(std::string name) : testname(name) { }
154-
155151
void SetName(std::string name) {
156152
testname = name;
157153
}
158154

159155
void AddSample(long long matrix_size, double time) {
160156
samplings.push_back(
161157
std::make_pair(matrix_size, time));
162-
//matrix_sizes.push_back(matrix_size);
163-
//elapsed_msec.push_back(time);
164158
}
165159

166160
friend std::ostream& operator<<(std::ostream& os, const benchmarkresult& result);
167161
private:
168162
std::string testname;
169163
std::vector<std::pair<long long, double>> samplings; // matrix size (mb) - traversal sum time in milliseconds
170-
//std::vector<long long> matrix_sizes; // matrix size (mb) - traversal sum time in milliseconds
171-
//std::vector<double> elapsed_msec; // matrix size (mb) - traversal sum time in milliseconds
172164
};
173165

174166
std::ostream& operator<<(std::ostream& os, const benchmarkresult& result) {
@@ -186,18 +178,27 @@ namespace cpu_cache_misses {
186178

187179
CREATE_ELEMENT_WITH_CODE(CpuCacheExample) {
188180
using namespace cpu_cache_misses;
189-
constexpr size_t num_of_samplings = 10;
181+
constexpr size_t num_of_iter = 5;
182+
constexpr size_t done_before = 0;
190183

191184
// initiate result map
192185
std::map<std::string, benchmarkresult> results;
193186
results["rowmajor"].SetName("rowmajor");
194187
results["columnmajor"].SetName("columnmajor");
195188

196-
for (size_t i = 0; i < num_of_samplings; i++)
189+
for (size_t i = 0; i < num_of_iter; i++)
197190
{
198-
auto dimsize = 1024 << i;
191+
auto dimsize = 1024 << (i + done_before);
192+
std::cout
193+
<< "\n------------------benchmark point------------------\n"
194+
<< "Matrix with size : " << dimsize << std::endl;
199195
MatrixSumBenchmarkHelper benchmarker{ dimsize };
196+
std::cout
197+
<< "Starting benchmark for row major traversal" << std::endl;
200198
results["rowmajor"].AddSample(dimsize, benchmarker.start(TraversalOrder::RowMajor));
199+
200+
std::cout
201+
<< "Starting benchmark for column major traversal" << std::endl;
201202
results["columnmajor"].AddSample(dimsize, benchmarker.start(TraversalOrder::ColumnMajor));
202203
}
203204

@@ -207,5 +208,4 @@ CREATE_ELEMENT_WITH_CODE(CpuCacheExample) {
207208
<< "\n------------------------------------------------------\n"
208209
<< results["columnmajor"]
209210
<< std::endl;
210-
211211
}

0 commit comments

Comments
 (0)