I've never seen the time function but I would just guess it would have to look like this.
a=sqrt(x);
j=time(sqrt(x));
jasweb2002
Junior Poster in Training
56 posts since Sep 2004
Reputation Points: 11
Solved Threads: 2
Jpowers22 is right, you need to use clock() to get to something that is about a millisecond. You also have to do the calculation about a million times to get a meaningful time to measure. Yes Ruby, computers are fast nowadays!
[php]// time the sqrt() function Dev-C++
#include
#include
#include
using namespace std;
int main()
{
int k;
double a,x,y,z;
clock_t start, end;
z = 0.01;
y = 2;
cout << "Enter the number you want to find the squareroot of : ";
cin >> x;
start = clock();
for(k = 0; k < 1000000; k++)
a = sqrt(x);
end = clock();
cout << "1M iterations of sqrt() from cmath took ";
cout << (end - start) << " ticks\n"; // a tick is about 1 ms
// now do a similar thing for sqroot(x,y,z)
system("PAUSE");
return 0;
}
[/php]
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417