hello people
i was wondering if anyone could come up with a program that could excatly compute the amount of time that it takes for a simple arthimetic operation. I mean lets assume that there is a simple addition program, is it possible to find the exact amount of time that it took for the computation for addition..

anticipating your replies.
cheers!!!!

jack

Computers don't keep exact time and don't keep infinitely precise measurements of time. If you are wanting measurements of time greater than a few milliseconds and you are on a Windows system, you can use the GetTickCount function. Record the value returned by the function before and after you execute the code that you want to time, subtract the first value from the second, and you have the number of milliseconds that have elapsed.

whenevr i need to check the computation time of my program segments....i go for gcc compiler...and compile the program using profiling option...it gives complete description of all the blocks(time taken...how many times a particular block is called and many other useful things etc....)

hey..
What is ur purpose for knowing the computation time?? If its an ideal code then u will have to code directly in assembly to idealise ur coding.. compilers generally break an instruction in a standard manner.. e.g if u say 2*x it will multiply 2 by x and not add x to itself which will reduce the computation time..

If you say 2*x, compilers will generally use the same code as x << 1. They're smart enough for that.

hey..
What is ur purpose for knowing the computation time?? If its an ideal code then u will have to code directly in assembly to idealise ur coding.. compilers generally break an instruction in a standard manner.. e.g if u say 2*x it will multiply 2 by x and not add x to itself which will reduce the computation time..

hey
Thankz guys for the replies.. This was a question that was given to me as assignment. My prof wanted us to calculate the amount of time it takes to do a simple arithmetic operation. I did use all the time function available. But time functions shows only micro seconds value. The time taken for addition is so slow that everytime i run the program it says 0.00seconds...so now am looking for somethin that would calculate time in nanoseconds

thanks again

Suppose you want to measure the thickness of a sheet of paper. Don't put a ruler next to the sheet of paper and use a microscope; put a ruler next to a stack of one hundred sheets of paper and use your eyes.

Yay... I helped a guy with a homework assignment. Read my orignial post, then read Rashakil Fol's post above mine, and then think about the problem. We gave you the answer, you just need to piece it together. Since it is a homework assignment, you should have to think about it a bit.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.