Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cscs-checks/microbenchmarks/alloc_speed/alloc_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def __init__(self, hugepages):
self.sys_reference = {
'no': {
'dom:gpu': {
'time': (1.80, None, 0.10, 's')
'time': (1.00, None, 0.10, 's')
},
'dom:mc': {
'time': (2.00, None, 0.10, 's')
'time': (1.20, None, 0.10, 's')
},
'daint:gpu': {
'time': (1.80, None, 0.10, 's')
Expand Down
17 changes: 12 additions & 5 deletions cscs-checks/microbenchmarks/alloc_speed/src/alloc_speed.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
#include <chrono>
#include <iostream>
#include <algorithm>
#include <memory>

double test_alloc(size_t n)
{
auto t_start = std::chrono::system_clock::now();
std::unique_ptr<char[]> ptr(new char[n]);

/* time to allocate + fill */
std::fill(ptr.get(), ptr.get() + n, 0);
/* memory is allocated using "malloc" since
"std::unique_ptr<char[]> ptr(new char[n])"
also creates the objects via "new[]" */
char* ptr = (char*)std::malloc(n);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a small comment with the rationale of not using unique_ptr here.

std::fill(ptr, ptr + n, 0);
auto t_alloc_fill = std::chrono::system_clock::now();

/* time too fill */
std::fill(ptr.get(), ptr.get() + n, 0);
/* time to fill */
std::fill(ptr, ptr + n, 0);
auto t_alloc_two_fills = std::chrono::system_clock::now();

/* prevent compiler optimizations */
t_start += std::chrono::nanoseconds(ptr[0]);

std::free(ptr);

return std::chrono::duration_cast<std::chrono::duration<double>>((t_alloc_fill - t_start) - (t_alloc_two_fills - t_alloc_fill)).count();
}

Expand Down