123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <cstdlib>
- #include "ra/bench.hh"
- using std::cout, std::endl, std::flush, ra::TestRecorder;
- using real = double;
- int main()
- {
- TestRecorder tr(cout);
- cout.precision(4);
- tr.section("rank 1");
- {
- auto test1 = [&tr](char const * atag, auto && A, int N)
- {
- auto s = ra::size(A);
- Benchmark bm { N, 3 };
- auto report = [&](std::string const & tag, auto && bv)
- {
- tr.info(std::setw(5), std::fixed, bm.avg(bv)/s/1e-9, " ns [", bm.stddev(bv)/s/1e-9, "] ",
- atag, " [", ra::noshape, ra::shape(A), "] ", tag)
- .test_eq(ra::iota(s), A);
- };
- report("range for",
- bm.run([&] {
- int i = 0;
- for (auto & a: A) {
- a = i;
- ++i;
- }
- }));
- report("ply undef",
- bm.run([&] {
- A = ra::_0;
- }));
- report("ply def",
- bm.run([&] {
- A = ra::iota(s);
- }));
- };
- tr.section("static dimensions");
- test1("small", ra::Small<real, 10>(), 50000000);
- tr.section("static rank");
- test1("unique", ra::Unique<real, 1>({10000}, ra::none), 5000);
- test1("view", ra::Unique<real, 1>({10000}, ra::none).view(), 5000);
- tr.section("var rank");
- test1("unique", ra::Unique<real>({10000}, ra::none), 5000);
- test1("view", ra::Unique<real>({10000}, ra::none).view(), 5000);
- }
- tr.section("rank 2");
- {
- auto test2 = [&tr](char const * atag, auto && A, int N)
- {
- auto s = ra::size(A);
- Benchmark bm { N, 3 };
- auto report = [&](std::string const & tag, auto && bv)
- {
- auto B = ra::Unique<real, 1>({s}, A.begin(), s);
- tr.info(std::setw(5), std::fixed, bm.avg(bv)/s/1e-9, " ns [", bm.stddev(bv)/s/1e-9, "] ",
- atag, " [", ra::noshape, ra::shape(A), "] ", tag)
- .test_eq(ra::iota(s), B);
- };
- report("range for",
- bm.run([&] {
- int i = 0;
- for (auto & a: A) {
- a = i;
- ++i;
- }
- }));
- };
- tr.section("static dimensions");
- test2("small", ra::Small<real, 10, 10>(), 1000000);
- test2("small transposed", ra::transpose<1, 0>(ra::Small<real, 10, 10>()), 1000000);
- tr.section("static rank");
- test2("unique", ra::Unique<real, 2>({1000, 1000}, ra::none), 100);
- test2("view", ra::Unique<real, 2>({1000, 1000}, ra::none).view(), 100);
- test2("transposed view", ra::transpose<1, 0>(ra::Unique<real, 2>({1000, 1000}, ra::none)), 100);
- tr.section("var rank");
- test2("unique", ra::Unique<real>({1000, 1000}, ra::none), 100);
- test2("view", ra::Unique<real>({1000, 1000}, ra::none).view(), 100);
- test2("transposed view", ra::transpose<1, 0>(ra::Unique<real>({1000, 1000}, ra::none)), 100);
- }
- return tr.summary();
- }
|