Skip to content

Commit 0957551

Browse files
authored
Merge pull request #92 from rafbiels/hashtable-print-compute-time
[hashtable] Print both total and compute-only times
2 parents 6844687 + 176f830 commit 0957551

File tree

3 files changed

+51
-33
lines changed

3 files changed

+51
-33
lines changed

hashtable/CUDA/src/main.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
#define CPP_MODULE "MAIN"
2424
#define ITERATIONS 10
2525

26-
#define TIMER_START() time_start = std::chrono::steady_clock::now();
27-
#define TIMER_END() \
28-
time_end = std::chrono::steady_clock::now(); \
29-
time_total = std::chrono::duration<double, std::milli>(time_end - time_start).count();
30-
#define TIMER_PRINT(name) std::cout << name <<": " << time_total / 1e3 << " s\n";
26+
#define TIMER_START(name) time_start_ ## name = std::chrono::steady_clock::now();
27+
#define TIMER_END(name) \
28+
time_ ## name = std::chrono::duration<double, std::milli>( \
29+
std::chrono::steady_clock::now() - time_start_ ## name \
30+
).count();
31+
#define TIMER_PRINT(name, msg) std::cout << msg <<": " << time_ ## name / 1e3 << " s\n";
3132

3233
#ifdef DEBUG_TIME
3334
#define START_TIMER() start_time = std::chrono::steady_clock::now();
@@ -153,9 +154,10 @@ void test_correctness(
153154

154155
int main(int argc, char* argv[])
155156
{
156-
std::chrono::steady_clock::time_point time_start;
157-
std::chrono::steady_clock::time_point time_end;
157+
std::chrono::steady_clock::time_point time_start_total;
158+
std::chrono::steady_clock::time_point time_start_compute;
158159
double time_total = 0.0;
160+
double time_compute = 0.0;
159161

160162
try {
161163

@@ -190,7 +192,7 @@ STOP_TIMER();
190192
PRINT_TIMER("generate_hashtable ");
191193
#endif
192194

193-
TIMER_START()
195+
TIMER_START(total)
194196

195197
#ifdef DEBUG_TIME
196198
START_TIMER();
@@ -202,6 +204,8 @@ STOP_TIMER();
202204
PRINT_TIMER("init ");
203205
#endif
204206

207+
TIMER_START(compute)
208+
205209
std::vector<KeyValue> kvs;
206210
for (int iter = 0; iter < ITERATIONS; iter++){
207211
#ifdef DEBUG_TIME
@@ -278,9 +282,11 @@ PRINT_TIMER("iterate_hashtable ");
278282

279283
destroy_hashtable(pHashTable);
280284
}
281-
TIMER_END()
282-
TIMER_PRINT("hashtable - total time for whole calculation")
283-
printf("%f million keys/second\n", kNumKeyValues / (time_total / ITERATIONS / 1000.0f) / 1000000.0f);
285+
TIMER_END(compute)
286+
TIMER_END(total)
287+
TIMER_PRINT(compute, "hashtable - compute time")
288+
TIMER_PRINT(total, "hashtable - total time for whole calculation")
289+
printf("%f million keys/second\n", kNumKeyValues / (time_compute / ITERATIONS / 1000.0f) / 1000000.0f);
284290

285291
if (verify) {
286292
test_unordered_map(insert_kvs, delete_kvs);

hashtable/HIP/src/main.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
#define CPP_MODULE "MAIN"
2424
#define ITERATIONS 10
2525

26-
#define TIMER_START() time_start = std::chrono::steady_clock::now();
27-
#define TIMER_END() \
28-
time_end = std::chrono::steady_clock::now(); \
29-
time_total = std::chrono::duration<double, std::milli>(time_end - time_start).count();
30-
#define TIMER_PRINT(name) std::cout << name <<": " << time_total / 1e3 << " s\n";
26+
#define TIMER_START(name) time_start_ ## name = std::chrono::steady_clock::now();
27+
#define TIMER_END(name) \
28+
time_ ## name = std::chrono::duration<double, std::milli>( \
29+
std::chrono::steady_clock::now() - time_start_ ## name \
30+
).count();
31+
#define TIMER_PRINT(name, msg) std::cout << msg <<": " << time_ ## name / 1e3 << " s\n";
3132

3233
#ifdef DEBUG_TIME
3334
#define START_TIMER() start_time = std::chrono::steady_clock::now();
@@ -153,9 +154,10 @@ void test_correctness(
153154

154155
int main(int argc, char* argv[])
155156
{
156-
std::chrono::steady_clock::time_point time_start;
157-
std::chrono::steady_clock::time_point time_end;
157+
std::chrono::steady_clock::time_point time_start_total;
158+
std::chrono::steady_clock::time_point time_start_compute;
158159
double time_total = 0.0;
160+
double time_compute = 0.0;
159161

160162
try {
161163

@@ -190,7 +192,7 @@ STOP_TIMER();
190192
PRINT_TIMER("generate_hashtable ");
191193
#endif
192194

193-
TIMER_START()
195+
TIMER_START(total)
194196

195197
#ifdef DEBUG_TIME
196198
START_TIMER();
@@ -202,6 +204,8 @@ STOP_TIMER();
202204
PRINT_TIMER("init ");
203205
#endif
204206

207+
TIMER_START(compute)
208+
205209
std::vector<KeyValue> kvs;
206210
for (int iter = 0; iter < ITERATIONS; iter++){
207211
#ifdef DEBUG_TIME
@@ -278,9 +282,11 @@ PRINT_TIMER("iterate_hashtable ");
278282

279283
destroy_hashtable(pHashTable);
280284
}
281-
TIMER_END()
282-
TIMER_PRINT("hashtable - total time for whole calculation")
283-
printf("%f million keys/second\n", kNumKeyValues / (time_total / ITERATIONS / 1000.0f) / 1000000.0f);
285+
TIMER_END(compute)
286+
TIMER_END(total)
287+
TIMER_PRINT(compute, "hashtable - compute time")
288+
TIMER_PRINT(total, "hashtable - total time for whole calculation")
289+
printf("%f million keys/second\n", kNumKeyValues / (time_compute / ITERATIONS / 1000.0f) / 1000000.0f);
284290

285291
if (verify) {
286292
test_unordered_map(insert_kvs, delete_kvs);

hashtable/SYCL/src/main.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
#define CPP_MODULE "MAIN"
2424
#define ITERATIONS 10
2525

26-
#define TIMER_START() time_start = std::chrono::steady_clock::now();
27-
#define TIMER_END() \
28-
time_end = std::chrono::steady_clock::now(); \
29-
time_total = std::chrono::duration<double, std::milli>(time_end - time_start).count();
30-
#define TIMER_PRINT(name) std::cout << name <<": " << time_total / 1e3 << " s\n";
26+
#define TIMER_START(name) time_start_ ## name = std::chrono::steady_clock::now();
27+
#define TIMER_END(name) \
28+
time_ ## name = std::chrono::duration<double, std::milli>( \
29+
std::chrono::steady_clock::now() - time_start_ ## name \
30+
).count();
31+
#define TIMER_PRINT(name, msg) std::cout << msg <<": " << time_ ## name / 1e3 << " s\n";
3132

3233
#ifdef DEBUG_TIME
3334
#define START_TIMER() start_time = std::chrono::steady_clock::now();
@@ -153,9 +154,10 @@ void test_correctness(
153154

154155
int main(int argc, char* argv[])
155156
{
156-
std::chrono::steady_clock::time_point time_start;
157-
std::chrono::steady_clock::time_point time_end;
157+
std::chrono::steady_clock::time_point time_start_total;
158+
std::chrono::steady_clock::time_point time_start_compute;
158159
double time_total = 0.0;
160+
double time_compute = 0.0;
159161

160162
try {
161163

@@ -190,7 +192,7 @@ STOP_TIMER();
190192
PRINT_TIMER("generate_hashtable ");
191193
#endif
192194

193-
TIMER_START()
195+
TIMER_START(total)
194196

195197
#ifdef DEBUG_TIME
196198
START_TIMER();
@@ -202,6 +204,8 @@ STOP_TIMER();
202204
PRINT_TIMER("init ");
203205
#endif
204206

207+
TIMER_START(compute)
208+
205209
std::vector<KeyValue> kvs;
206210
for (int iter = 0; iter < ITERATIONS; iter++) {
207211
#ifdef DEBUG_TIME
@@ -281,9 +285,11 @@ PRINT_TIMER("iterate_hashtable ");
281285

282286
destroy_hashtable(pHashTable, qht);
283287
}
284-
TIMER_END()
285-
TIMER_PRINT("hashtable - total time for whole calculation")
286-
printf("%f million keys/second\n", kNumKeyValues / (time_total / ITERATIONS / 1000.0f) / 1000000.0f);
288+
TIMER_END(compute)
289+
TIMER_END(total)
290+
TIMER_PRINT(compute, "hashtable - compute time")
291+
TIMER_PRINT(total, "hashtable - total time for whole calculation")
292+
printf("%f million keys/second\n", kNumKeyValues / (time_compute / ITERATIONS / 1000.0f) / 1000000.0f);
287293

288294
if (verify) {
289295
test_unordered_map(insert_kvs, delete_kvs);

0 commit comments

Comments
 (0)