diff --git a/test/check/run_speed_root.sh b/test/check/run_speed_root.sh new file mode 100755 index 00000000..ac87b49a --- /dev/null +++ b/test/check/run_speed_root.sh @@ -0,0 +1,2 @@ +#!/bin/sh +g++ -std=c++11 -O3 `root-config --cflags` speed_root.cpp `root-config --libs` -lstdc++ -o /tmp/speed_root && /tmp/speed_root diff --git a/test/check/speed_cpp.cpp b/test/check/speed_cpp.cpp index 36c39618..41296a06 100644 --- a/test/check/speed_cpp.cpp +++ b/test/check/speed_cpp.cpp @@ -6,11 +6,11 @@ #include #include -#include +#include #include #include -#include +#include #include #include diff --git a/test/check/speed_root.cpp b/test/check/speed_root.cpp index 4cfcc0a7..6290a1fb 100644 --- a/test/check/speed_root.cpp +++ b/test/check/speed_root.cpp @@ -4,118 +4,82 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) -#include -#include -#include -#include - #include #include #include + +#include #include #include #include #include #include -using namespace std; -using namespace boost::histogram; - -template -struct rng { - boost::random::mt19937 r; - D d; - rng(double a, double b) : d(a, b) {} - double operator()() { return d(r); } -}; - -vector random_array(unsigned n, int type) { - using namespace boost::random; - std::vector result; - switch (type) { - case 0: - std::generate_n(std::back_inserter(result), n, rng >(0.0, 1.0)); - break; - case 1: - std::generate_n(std::back_inserter(result), n, rng >(0.0, 0.3)); - break; +std::vector random_array(unsigned n, int type) { + std::vector result(n); + std::default_random_engine gen(1); + if (type) { // type == 1 + std::normal_distribution<> d(0.0, 0.3); + for (auto& x : result) + x = d(gen); + } + else { // type == 0 + std::uniform_real_distribution<> d(0.0, 1.0); + for (auto& x: result) + x = d(gen); } return result; } void compare_1d(unsigned n, int distrib) { - vector r = random_array(n, distrib); + auto r = random_array(n, distrib); double best_root = std::numeric_limits::max(); - double best_boost = std::numeric_limits::max(); for (unsigned k = 0; k < 10; ++k) { TH1I hroot("", "", 100, 0, 1); - clock_t t = clock(); + auto t = clock(); for (unsigned i = 0; i < n; ++i) hroot.Fill(r[i]); t = clock() - t; best_root = std::min(best_root, double(t) / CLOCKS_PER_SEC); - - histogram h(regular_axis(100, 0, 1)); - t = clock(); - for (unsigned i = 0; i < n; ++i) - h.fill(r[i]); - t = clock() - t; - best_boost = std::min(best_boost, double(t) / CLOCKS_PER_SEC); - // printf("root %g this %g\n", hroot.GetSum(), h.sum()); - assert(hroot.GetSum() == h.sum()); } printf("1D\n"); printf("t[root] = %.3f\n", best_root); - printf("t[boost] = %.3f\n", best_boost); } void compare_3d(unsigned n, int distrib) { - vector r = random_array(3 * n, distrib); + auto r = random_array(3 * n, distrib); double best_root = std::numeric_limits::max(); - double best_boost = std::numeric_limits::max(); for (unsigned k = 0; k < 10; ++k) { TH3I hroot("", "", 100, 0, 1, 100, 0, 1, 100, 0, 1); - clock_t t = clock(); + auto t = clock(); for (unsigned i = 0; i < n; ++i) hroot.Fill(r[3 * i], r[3 * i + 1], r[3 * i + 2]); t = clock() - t; best_root = std::min(best_root, double(t) / CLOCKS_PER_SEC); - - histogram h(regular_axis(100, 0, 1), - regular_axis(100, 0, 1), - regular_axis(100, 0, 1)); - t = clock(); - for (unsigned i = 0; i < n; ++i) - h.fill(r[3 * i], r[3 * i + 1], r[3 * i + 2]); - t = clock() - t; - best_boost = std::min(best_boost, double(t) / CLOCKS_PER_SEC); - assert(hroot.GetSum() == h.sum()); } printf("3D\n"); printf("t[root] = %.3f\n", best_root); - printf("t[boost] = %.3f\n", best_boost); } void compare_6d(unsigned n, int distrib) { - vector r = random_array(6 * n, distrib); + auto r = random_array(6 * n, distrib); double best_root = std::numeric_limits::max(); - double best_boost = std::numeric_limits::max(); for (unsigned k = 0; k < 10; ++k) { double x[6]; - vector bin(6, 10); - vector min(6, 0); - vector max(6, 1); + std::vector bin(6, 10); + std::vector min(6, 0); + std::vector max(6, 1); THnI hroot("", "", 6, &bin.front(), &min.front(), &max.front()); - clock_t t = clock(); + auto t = clock(); for (unsigned i = 0; i < n; ++i) { for (unsigned k = 0; k < 6; ++k) x[k] = r[6 * i + k]; @@ -123,27 +87,10 @@ void compare_6d(unsigned n, int distrib) } t = clock() - t; best_root = std::min(best_root, double(t) / CLOCKS_PER_SEC); - - histogram h(regular_axis(10, 0, 1), - regular_axis(10, 0, 1), - regular_axis(10, 0, 1), - regular_axis(10, 0, 1), - regular_axis(10, 0, 1), - regular_axis(10, 0, 1)); - - t = clock(); - for (unsigned i = 0; i < n; ++i) { - for (unsigned k = 0; k < 6; ++k) - x[k] = r[6 * i + k]; - h.fill(x, x+6); - } - t = clock() - t; - best_boost = std::min(best_boost, double(t) / CLOCKS_PER_SEC); } printf("6D\n"); printf("t[root] = %.3f\n", best_root); - printf("t[boost] = %.3f\n", best_boost); } int main(int argc, char** argv) {