[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/xtensor-stack/xtensor/master/benchmark/benchmark_xshape.cpp [Back]  [Original]

/***************************************************************************
 * Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht    *
 *                                                                          *
 * Distributed under the terms of the BSD 3-Clause License.                 *
 *                                                                          *
 * The full license is in the file LICENSE, distributed with this software. *
 ****************************************************************************/


#ifndef BENCHMARK_SHAPE_HPP
#define BENCHMARK_SHAPE_HPP

#include 

#include "xtensor/containers/xstorage.hpp"
#include "xtensor/core/xshape.hpp"

namespace xt
{
    namespace benchmark_xshape
    {
        template 
        void xshape_initializer(benchmark::State& state)
        {
            for (auto _ : state)
            {
                T sv({2, 3, 1});
                benchmark::DoNotOptimize(sv.data());
            }
        }

        template 
        void xshape_initializer_long(benchmark::State& state)
        {
            for (auto _ : state)
            {
                T sv({2, 3, 1, 2, 6, 1, 2, 3, 45, 6, 12, 3, 5, 45, 5, 6});
                benchmark::DoNotOptimize(sv.data());
            }
        }

        template 
        void xshape_access(benchmark::State& state)
        {
            T a({3, 2, 1, 3});
            for (auto _ : state)
            {
                a[0] = a[1] * a[2] + a[3];
                a[3] = a[1];
                a[1] = a[2] + a[3];
                a[2] = a[3];
                benchmark::DoNotOptimize(a.data());
            }
        }

        BENCHMARK_TEMPLATE(xshape_initializer, std::vector);
        BENCHMARK_TEMPLATE(xshape_initializer, xt::svector);
        BENCHMARK_TEMPLATE(xshape_initializer, std::array);
        BENCHMARK_TEMPLATE(xshape_initializer_long, xt::svector);
        BENCHMARK_TEMPLATE(xshape_initializer_long, xt::uvector);
        BENCHMARK_TEMPLATE(xshape_initializer_long, std::vector);
        BENCHMARK_TEMPLATE(xshape_access, xt::uvector);
        BENCHMARK_TEMPLATE(xshape_access, std::vector);
        BENCHMARK_TEMPLATE(xshape_access, xt::svector);
        BENCHMARK_TEMPLATE(xshape_access, std::array);
    }
}

#endif

Web Proxy Viewer  |  New URL  |  Original Page