File: benchmark_lambda_expressions.cpp

package info (click to toggle)
xtensor 0.25.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,476 kB
  • sloc: cpp: 65,302; makefile: 202; python: 171; javascript: 8
file content (74 lines) | stat: -rw-r--r-- 2,541 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/***************************************************************************
 * 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. *
 ****************************************************************************/

#include <benchmark/benchmark.h>

#include "xtensor/xarray.hpp"
#include "xtensor/xbuilder.hpp"
#include "xtensor/xmath.hpp"
#include "xtensor/xnoalias.hpp"
#include "xtensor/xtensor.hpp"

namespace xt
{
    void lambda_cube(benchmark::State& state)
    {
        xtensor<double, 2> x = empty<double>({state.range(0), state.range(0)});
        for (auto _ : state)
        {
            xtensor<double, 2> res = xt::cube(x);
            benchmark::DoNotOptimize(res.data());
        }
    }

    void xexpression_cube(benchmark::State& state)
    {
        xtensor<double, 2> x = empty<double>({state.range(0), state.range(0)});
        for (auto _ : state)
        {
            xtensor<double, 2> res = x * x * x;
            benchmark::DoNotOptimize(res.data());
        }
    }

    void lambda_higher_pow(benchmark::State& state)
    {
        xtensor<double, 2> x = empty<double>({state.range(0), state.range(0)});
        for (auto _ : state)
        {
            xtensor<double, 2> res = xt::pow<16>(x);
            benchmark::DoNotOptimize(res.data());
        }
    }

    void xsimd_higher_pow(benchmark::State& state)
    {
        xtensor<double, 2> x = empty<double>({state.range(0), state.range(0)});
        for (auto _ : state)
        {
            xtensor<double, 2> res = xt::pow(x, 16);
            benchmark::DoNotOptimize(res.data());
        }
    }

    void xexpression_higher_pow(benchmark::State& state)
    {
        xtensor<double, 2> x = empty<double>({state.range(0), state.range(0)});
        for (auto _ : state)
        {
            xtensor<double, 2> res = x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x;
            benchmark::DoNotOptimize(res.data());
        }
    }

    BENCHMARK(lambda_cube)->Range(32, 32 << 3);
    BENCHMARK(xexpression_cube)->Range(32, 32 << 3);
    BENCHMARK(lambda_higher_pow)->Range(32, 32 << 3);
    BENCHMARK(xsimd_higher_pow)->Range(32, 32 << 3);
    BENCHMARK(xexpression_higher_pow)->Range(32, 32 << 3);
}