ten kod u mnie wykonuje się średno 6 sekund i to niezależnie od tego ile razy funkcja będzie wywoływana w pętli
czy będzie
if(i%5000000==0&&i!=0) lub
if(i%50000000==0&&i!=0) lub
if(i%500000000==0&&i!=0)
dlaczego tak jest ????????
#include "stdafx.h"
#include "iostream"
#include <stdio.h>
#include <cstdio>
#include <stdlib.h>
#include <conio.h>
#include <iostream>
#include <windows.h>
#include <sys/timeb.h> // pomiar czasu ();
#include <time.h> // pomiar czasu ();
#include <fstream>
using namespace std;
int funkcja_posredniczaca1(int &temp,int flaga);
double pomiar_czasu();
int _tmain(int argc, _TCHAR* argv[])
{
double czas_start1, czas_stop1, czasSzybkie1;
int j=0,j2=0,i=0;
//for(int p2=0;p2<20;p2++)
{
cout<<"i="<<i<<endl;
czas_start1=pomiar_czasu();
for(i=0;i<2000000000;i++)
{
if(i%50000000==0&&i!=0){funkcja_posredniczaca1(i,0);cout<<"..i="<<i<<endl;}
}
czas_stop1=pomiar_czasu();
czasSzybkie1=czas_stop1-czas_start1;
cout<<"i="<<i<<endl;
cout<<"Czas1: "<<czasSzybkie1<<endl;
}
cout<<" "<<funkcja_posredniczaca1(i,1)<<endl;//odczyt ostatniej modyfikacji
system("pause");
return 0;
}// koniec main
//////
int funkcja_posredniczaca1(int &temp,int flaga)
{ static int temp2=0;
if(flaga==1){return temp2;/*lub temp=temp2*/ }//odczyt
temp2=temp;
return -1;
}
//////
double pomiar_czasu()
{
struct timeb czas;
double wynik;
// Wypelnij strukture 'czas' biezacym czasem
ftime(&czas);
// Teraz mamy:
// * czas.time - liczba sekund, ktore uplynely od godziny
// 00:00 czasu GMT dnia 1.01.1970
// * czas.millitm - offset w milisekundach
// Skonwertuj czas do typu double
wynik = (double) czas.time;
wynik += (double) czas.millitm / 1000.0;
// Zwroc wynik
return wynik;
}