V
vishnu mahendra
cah you please tell me how to find the execution time of a program in c.
thank you in advance,
vishnu
thank you in advance,
vishnu
cah you please tell me how to find the execution time of a program in c.
In said:Call clock() at the start of your program; call clock() at the end of
your program; subtract the two; divide by CLOCKS_PER_SEC. Not very
precise, probably, but it's as precise as ISO C gets.
Richard said:Call clock() at the start of your program; call clock() at the end of
your program; subtract the two; divide by CLOCKS_PER_SEC. Not very
precise, probably, but it's as precise as ISO C gets.
cah you please tell me how to find the execution time of a program in c.
thank you in advance,
vishnu
GIR said:I don't know what platform you are writing for, but most "industrial
compilers" have an option to export your C file with the ASM code
included as comments.
What you do from there is get the user manual for your processor and
look up the used cycles per instruction. The Compiler we use (custom)
even includes the used memory.
If you know the XTAL of your processor (The ferquency is operates on,
probably mentioned in the user manual) you know how long 1 cycle is.
Kevin Goodsell said:OK, but this can be a very poor way to gauge execution time. Memory
and disk access, various interrupts, dynamic RAM refresh, branch
prediction failures, pipeline flushes, and many other things can
affect the execution speed. This varies from one architecture to the
next, but in general you can only know how fast a section of code is
by carefully timing it.
In said:I don't know what platform you are writing for, but most "industrial
compilers" have an option to export your C file with the ASM code
included as comments.
What you do from there is get the user manual for your processor and
look up the used cycles per instruction. The Compiler we use (custom)
even includes the used memory.
If you know the XTAL of your processor (The ferquency is operates on,
probably mentioned in the user manual) you know how long 1 cycle is.
For example if you processor has an XTAL of 1MHz then 1 cycle takes 1
us (microsecond). Just multiply the total amount of cycles needed by
the XTAL and you got your execution time.
This used to work 25 years ago, but it's useless on modern architectures.
A single cache miss may cost as much as 100 cpu cycles...
Dan
^^^^^^^^^^^^^^^^In said:To my knowledge that is the only accurate way of finding out how many
cycles a certain piece of code needs. And Like I said, it's platform
dependent. A good programmer always knows his/her system dynamics. If
for some reason the platform would introduce other ellements it's onto
the programmer to deal with these ellements. Like missed cache hits...
turn caching off.
Dan Pop said:This used to work 25 years ago, but it's useless on modern architectures.
A single cache miss may cost as much as 100 cpu cycles...
GIR said:I don't know what platform you are writing for, but most "industrial
compilers" have an option to export your C file with the ASM code
included as comments.
What you do from there is get the user manual for your processor and
look up the used cycles per instruction. The Compiler we use (custom)
even includes the used memory.
If you know the XTAL of your processor (The ferquency is operates on,
probably mentioned in the user manual) you know how long 1 cycle is.
For example if you processor has an XTAL of 1MHz then 1 cycle takes 1
us (microsecond). Just multiply the total amount of cycles needed by
the XTAL and you got your execution time.
>
> 100 cpu cycles? Why so high?
GIR said:To my knowledge that is the only accurate way of finding out how many
cycles a certain piece of code needs.
cah you please tell me how to find the execution time of a program in c.
thank you in advance,
vishnu
^^^^^^^^^^^^^^^^
You're either a patent idiot or a troll.
Dan
The OP didn't ask about cycles, but about time. Those are far from the
same thing.
Richard
GIR said:Uhu, it didn't occure to you that the language C isn't just for 8086
machines... there are architectures around which do allow a coder to
specify wether you want to enable caching.
OK... but that would make the timing method you suggest *less* accurate.
-Kevin
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.