12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #include <iostream>
- #include "ra/bench.hh"
- using std::cout, std::endl, std::flush, ra::TestRecorder;
- int main()
- {
- TestRecorder tr;
-
- {
- ra::Big<int, 1> a = {0, 0, 0};
- ra::ply(map([](auto && i) { std::cout << "i: " << i << std::endl; },
- a+ra::iota<0>()));
- ra::ply_ravel(map([](auto && i) { std::cout << "i: " << i << std::endl; },
- a+ra::iota<0>()));
- }
-
- {
- ra::Big<int, 2> a = {{0, 0, 0}, {0, 0, 0}};
- ra::ply(map([](auto && i, auto && j) { std::cout << "i: " << i << ", " << j << std::endl; },
- a+ra::iota<0>(), a+ra::iota<1>()));
- ra::ply_ravel(map([](auto && i, auto && j) { std::cout << "i: " << i << ", " << j << std::endl; },
- a+ra::iota<0>(), a+ra::iota<1>()));
- }
-
- auto taking_view =
- [](TestRecorder & tr, auto && a)
- {
- auto fa = [&a]()
- {
- int c = 0;
- ra::ply(ra::map([&c](auto && i, auto && j) { c += 2*i-j; },
- a+ra::iota<0>(), a+ra::iota<1>()));
- return c;
- };
- auto fb = [&a]()
- {
- int c = 0;
- ra::ply_ravel(ra::map([&c](auto && i, auto && j) { c += 2*i-j; },
- a+ra::iota<0>(), a+ra::iota<1>()));
- return c;
- };
- tr.test_eq(499500000, fa());
- tr.test_eq(499500000, fb());
- auto bench = Benchmark { 30, 30};
- bench.info("vala").report(std::cout, bench.run(fa), 1e-6);
- bench.info("valb").report(std::cout, bench.run(fb), 1e-6);
- };
- ra::Big<int, 2> const a({1000, 1000}, 0);
- taking_view(tr, a);
- auto b = transpose<1, 0>(a);
- taking_view(tr, b);
- return tr.summary();
- }
|