Wiesz co, mierzyłem tak:
#include <iostream>
#include <chrono>
#include <thread>
int main() {
constexpr int count = 10000;
int array[count];
auto value = 42;
using namespace std::chrono;
using namespace std;
auto start = high_resolution_clock::now();
int i;
#pragma omp parallel default(shared) private(i) num_threads(6)
{
#pragma omp for schedule(static, 100) nowait
for (i = 0; i < count; i++) {
array[i] = value ;
this_thread::sleep_for(milliseconds(1));
}
}
auto stop = high_resolution_clock::now();
cout << "Czas wykonywania pierwszej funkcji: "
<< duration_cast<milliseconds>(stop - start).count()
<< " ms." << std::endl;
}
.. i wyniki wychodzą powtarzalne. Skalowalność zbliżona do czynnika 6.
Chyba że źle odczytałem intencje Twojego fragmentu kodu?
A tak na marginesie, może warto popełnić do pomiarów takie coś:
#include <iostream>
#include <chrono>
using namespace std;
// Jakieś przykładowe funkcje...
int fast_fun() {
int sum{};
for(size_t i = 0; i < 1000; ++i) {
sum += i;
}
return sum;
}
long slow_fun() {
long sum{};
for(size_t i = 0; i < 10000000000; ++i) {
sum += i;
}
return sum;
}
long other_fun(int z) {
long sum{};
for(int i = 0; i < z; ++i) {
sum += i;
}
return sum;
}
template<typename Func, typename... TT>
void check_time(const string& message, Func func, TT&& ...tt) {
using namespace chrono;
cout << message << endl;
auto start_time = high_resolution_clock::now();
func(std::forward<TT>(tt)...);
auto end_time = high_resolution_clock::now();
cout << "Wykonanie zajęło: "
<< duration_cast<microseconds>(end_time - start_time).count()
<< " us.\n";
}
int main() {
cout << "Precyzja Twojego zegara to "
<< (static_cast<double>(chrono::high_resolution_clock::period::num)
/ chrono::high_resolution_clock::period::den) << " impulsów na sekundę.\n";
check_time("Funkcja fast_fun()", fast_fun);
check_time("Funkcja slow_fun()", slow_fun);
check_time("Funkcja other_fun()", other_fun, 900);
}