>>106497562
This is the code I used with g++ as -std=c++20
#include <random>
#include <span>
#include <chrono>
#include <iostream>
#include <numeric>
int fast(int *arr, int cnt)
{
int s { 0 };
for (int i = 0; i < cnt; ++i)
{
s += arr[i];
}
return s;
}
int slow(int *arr, int cnt)
{
int s { 0 };
for (int x : std::span(arr, cnt))
{
s += x;
}
return s;
}
int slow_with_std_reduce(int *arr, int cnt)
{
auto span_of_arr { std::span(arr, cnt) };
return std::reduce(span_of_arr.begin(), span_of_arr.end(), 0);
}
void __attribute__((optimize("O0"))) randomize_cache()
{
const size_t bigger_than_cachesize { 10 * 1024 * 1024 };
static long *p { new long[bigger_than_cachesize] };
for (int i = 0; i < bigger_than_cachesize; ++i)
{
p[i] = rand();
}
}
to be continued