1+ /* **************************************************************************
2+ * Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
3+ * *
4+ * Distributed under the terms of the BSD 3-Clause License. *
5+ * *
6+ * The full license is in the file LICENSE, distributed with this software. *
7+ ****************************************************************************/
8+
9+ #include < benchmark/benchmark.h>
10+ #include " xtensor/containers/xtensor.hpp"
11+ #include " xtensor/core/xmath.hpp"
12+ #include " xtensor/generators/xrandom.hpp"
13+
14+ namespace xt
15+ {
16+ namespace {
17+ constexpr std::array<size_t , 2 > cContainerAssignShape{2000 ,2000 };
18+ template <class Shape >
19+ auto generateRandomInt16From0To100 (Shape&& x)
20+ {
21+ return xt::random::randint (x, 0 , 100 );
22+ }
23+ }
24+
25+ static void Xtensor_Uint16_2000x2000_DivideBy2_StdTransform (benchmark::State& aState) {
26+ xt::xtensor<uint16_t , 2 > vInput = generateRandomInt16From0To100 (cContainerAssignShape);
27+ auto vOutput = xt::xtensor<uint16_t , 2 >::from_shape (cContainerAssignShape);
28+
29+ for (auto _ : aState) {
30+ std::transform (vInput.begin (), vInput.end (), vOutput.begin (), [](auto && aInputValue) { return aInputValue / 2 ; });
31+ }
32+ }
33+
34+ static void Xtensor_Uint16_2000x2000_DivideBy2_Xtensor (benchmark::State& aState) {
35+ xt::xtensor<uint16_t , 2 > vInput = generateRandomInt16From0To100 (cContainerAssignShape);
36+ auto vOutput = xt::xtensor<uint16_t , 2 >::from_shape (cContainerAssignShape);
37+
38+ for (auto _ : aState) {
39+ vOutput = vInput / 2 ;
40+ }
41+ }
42+
43+ static void Xtensor_Uint16_2000x2000_DivideBy2Double_StdTransform (benchmark::State& aState) {
44+ xt::xtensor<uint16_t , 2 > vInput = generateRandomInt16From0To100 (cContainerAssignShape);
45+ auto vOutput = xt::xtensor<uint16_t , 2 >::from_shape (cContainerAssignShape);
46+
47+ for (auto _ : aState) {
48+ std::transform (vInput.begin (), vInput.end (), vOutput.begin (), [](auto && aInputValue) { return aInputValue / 2.0 ; });
49+ }
50+ }
51+
52+ static void Xtensor_Uint16_2000x2000_DivideBy2Double_Xtensor (benchmark::State& aState) {
53+ xt::xtensor<uint16_t , 2 > vInput = generateRandomInt16From0To100 (cContainerAssignShape);
54+ auto vOutput = xt::xtensor<uint16_t , 2 >::from_shape (cContainerAssignShape);
55+
56+ for (auto _ : aState) {
57+ vOutput = vInput / 2.0 ;
58+ }
59+ }
60+
61+ static void Xtensor_Uint16_2000x2000_MultiplyBy2_StdTransform (benchmark::State& aState) {
62+ xt::xtensor<uint16_t , 2 > vInput = generateRandomInt16From0To100 (cContainerAssignShape);
63+ auto vOutput = xt::xtensor<uint16_t , 2 >::from_shape (cContainerAssignShape);
64+
65+ for (auto _ : aState) {
66+ std::transform (vInput.begin (), vInput.end (), vOutput.begin (), [](auto && aInputValue) { return aInputValue * 2 ; });
67+ }
68+ }
69+
70+ static void Xtensor_Uint16_2000x2000_MultiplyBy2_Xtensor (benchmark::State& aState) {
71+ xt::xtensor<uint16_t , 2 > vInput = generateRandomInt16From0To100 (cContainerAssignShape);
72+ auto vOutput = xt::xtensor<uint16_t , 2 >::from_shape (cContainerAssignShape);
73+
74+ for (auto _ : aState) {
75+ vOutput = vInput * 2 ;
76+ }
77+ }
78+
79+ static void Xtensor_Uint16_2000x2000_Maximum_StdTransform (benchmark::State& aState) {
80+ xt::xtensor<uint16_t , 2 > vInput1 = generateRandomInt16From0To100 (cContainerAssignShape);
81+ xt::xtensor<uint16_t , 2 > vInput2 = generateRandomInt16From0To100 (cContainerAssignShape);
82+ auto vOutput = xt::xtensor<uint16_t , 2 >::from_shape (cContainerAssignShape);
83+
84+ for (auto _ : aState) {
85+ auto vInput2It = vInput2.begin ();
86+ std::transform (vInput1.begin (), vInput1.end (), vOutput.begin (), [&vInput2It](auto && aInput1Value) { return std::max (aInput1Value, *vInput2It++); });
87+ }
88+ }
89+
90+ static void Xtensor_Uint16_2000x2000_Maximum_Xtensor (benchmark::State& aState) {
91+ xt::xtensor<uint16_t , 2 > vInput1 = generateRandomInt16From0To100 (cContainerAssignShape);
92+ xt::xtensor<uint16_t , 2 > vInput2 = generateRandomInt16From0To100 (cContainerAssignShape);
93+ auto vOutput = xt::xtensor<uint16_t , 2 >::from_shape (cContainerAssignShape);
94+
95+ for (auto _ : aState) {
96+ vOutput = xt::maximum (vInput1, vInput2);
97+ }
98+ }
99+ }
100+
0 commit comments