//copyright: Nedal Ahmed Husein Aburuqaya, all rights reserved.
#include<time.h>
#include<cstdlib>
#include<chrono>
using namespace std::chrono;
#include <iostream>
using namespace std;
const unsigned int n = 20000;
void fillArray(int a[n]){
srand(time(0));
for (int i = 0; i < n; i++)
a[i] = rand()+1;
}
bool compare(int a[n], int b[n]) {
for (int i = 0; i < n; i++)
if (a[i] != b[i])
return false;
return true;
}
int main()
{
int a1[n], a2[n], a3[n], a4[n], a5[n], a6[n], a7[n], a8[n], a[n], b[n];
fillArray(a1); fillArray(a2); fillArray(a3); fillArray(a4); fillArray(a5); fillArray(a6); fillArray(a7); fillArray(a8);
auto begin1 = high_resolution_clock::now();
for (int i = 0; i < n; i++) {
a[i] = a1[i] * a2[i] + a3[i] / a4[i] + a5[i] * a6[i] - a7[i] / a8[i];
}
auto end1 = high_resolution_clock::now();
auto duration1 = duration_cast<microseconds>(end1 - begin1);
cout << "duration for default precedence "<< duration1.count() << endl;
auto begin2 = high_resolution_clock::now();
for (int i = 0; i < n; i++) {
b[i] = (((a1[i] * a2[i]) +( a3[i] / a4[i])) + (a5[i] * a6[i]) )- (a7[i] / a8[i]);
}
auto end2 = high_resolution_clock::now();
auto duration2 = duration_cast<microseconds>(end2 - begin2);
cout << "duration for default precedence associate shape " << duration2.count() << endl;
if (compare(a, b))
cout << "they are the same default precedence and associative shape";
else cout << "possible errors associative shape redo it";
return 0;
}