Код: Выделить всё
#include
static inline int all_equal(const std::vector &vals) {
if (vals.size() < 1) {
return -1;
}
int sum = 0;
for (const int &v : vals) {
sum += v;
}
if (sum == 0) {
return 3;
}
return vals.size() * vals[0] == sum;
}
void bench(void) {
std::vector a(10'000'000, 100);
all_equal(a);
// std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79063832/go-is-faster-than-c-with-calculations-and-nested-repeated-for-loops-where-is[/url]