Commit ec72cb49 authored by Paal Kvamme's avatar Paal Kvamme
Browse files

Performance tests for CopySubset().

parent 1863651a
......@@ -21,6 +21,7 @@
#include <iostream>
#include <iomanip>
#include <memory>
#include <omp.h>
using namespace OpenZGY;
using namespace InternalZGY;
......@@ -333,6 +334,60 @@ test_databuffer_copyfrom()
TEST_CHECK(countequal(3,target.data(),target.totalsize()) == 2*5*10-1);
}
/**
* Used as a performance test only. There is no assert on a specific
* maximum time. Instead, look at the test log which gives the elapsed
* time of every test.
*/
template<typename T, int LOOPS>
static void
test_databuffer_copyfromST()
{
DataBufferNd<T,3> target(std::array<std::int64_t,3>{64,64,64});
DataBufferNd<T,3> brick1(std::array<std::int64_t,3>{64,64,64});
DataBufferNd<T,3> brick2(std::array<std::int64_t,3>{64,64,64});
std::fill(target.data(), target.data()+target.allocsize(), (T)0);
std::fill(brick1.data(), brick1.data()+brick1.allocsize(), (T)99);
std::fill(brick2.data(), brick2.data()+brick2.allocsize(), (T)42);
const std::int64_t origin[3]{0, 0, 0};
for (int ii=0; ii<LOOPS; ii += 2) {
target.copyFrom(&brick1, origin, origin, nullptr, nullptr);
target.copyFrom(&brick2, origin, origin, nullptr, nullptr);
}
}
/**
* Used as a performance test only. There is no assert on a specific
* maximum time. Instead, look at the test log which gives the elapsed
* time of every test.
*/
template<typename T, int LOOPS,int THREADS>
static void
test_databuffer_copyfromMT()
{
DataBufferNd<T,3> target(std::array<std::int64_t,3>{64,64,64});
DataBufferNd<T,3> brick1(std::array<std::int64_t,3>{64,64,64});
DataBufferNd<T,3> brick2(std::array<std::int64_t,3>{64,64,64});
std::fill(brick1.data(), brick1.data()+brick1.allocsize(), (T)99);
std::fill(brick2.data(), brick2.data()+brick2.allocsize(), (T)42);
const std::int64_t origin[3]{0, 0, 0};
int actual_threads = 0;
#pragma omp parallel num_threads(THREADS)
{
DataBufferNd<T,3> target(std::array<std::int64_t,3>{64,64,64});
if (omp_get_thread_num() == 0) {
actual_threads = omp_get_num_threads();
}
#pragma omp for
for (int ii=0; ii<LOOPS; ii += 2) {
target.copyFrom(&brick1, origin, origin, nullptr, nullptr);
target.copyFrom(&brick2, origin, origin, nullptr, nullptr);
}
}
TEST_EQUAL(actual_threads, THREADS);
}
static void
test_databuffer_copytoscalar()
{
......@@ -459,6 +514,29 @@ namespace {
register_test("databuffer.isnan", test_databuffer_isnan);
register_test("databuffer.slice<h>", test_databuffer_slice<std::int16_t>);
#endif
// Raise the iteration count at least by a factor of 100 to get
// meaningful timing results. Do *not* do this in a valgrind
// run; that might take 20 minutes per test.
register_test("databuffer.copyfromST",
test_databuffer_copyfromST<float,200>);
register_test("databuffer.copyfrom02",
test_databuffer_copyfromMT<float,1000,2>);
register_test("databuffer.copyfrom04",
test_databuffer_copyfromMT<float,1000,4>);
register_test("databuffer.copyfrom08",
test_databuffer_copyfromMT<float,1000,8>);
register_test("databuffer.copyfrom16",
test_databuffer_copyfromMT<float,1000,16>);
register_test("databuffer.copyfrom24",
test_databuffer_copyfromMT<float,1000,24>);
register_test("databuffer.copyfrom32",
test_databuffer_copyfromMT<float,1000,32>);
register_test("databuffer.copyfrom48",
test_databuffer_copyfromMT<float,1000,48>);
register_test("databuffer.copyfrom64",
test_databuffer_copyfromMT<float,1000,64>);
register_test("databuffer.copyfrom96",
test_databuffer_copyfromMT<float,1000,96>);
}
} dummy;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment