السلام عليكم
إليكم هذا الكود
#include <iostream>
#include <conio.h>
#include <string.h>
#include <math.h>
#include <time.h>
using namespace std;
clock_t test(int n){
int i = 0;
clock_t sr,sp,res;
sr = clock();
while(i < n){
i++;
}
sp = clock();
res = (double)sp-sr/CLOCKS_PER_SEC;
return res;
};
int main(){
clock_t t1,t2,t3;
t1 = test(10000000);
t2 = test(1000);
cout
<<"T1 = "<<t1<<endl
<<"T2 = "<<t2<<endl;
}نتيجة هذا الكود هي
T1 = 62 T2 = 62
المشكل هنا أن العملية الأولى تقوم بعمل أكثر من الثانية لكن نلاحظ هنا أن الوقت متطابق
فما الحل لهذا المشكل ؟ ولكم الشكر مسبقا.





