speed of execution

K

kavi

Hello friends,

Could any one tell the way of calculating the speed of c program
execution?
 
R

Richard Heathfield

Ian Collins said:

That only tells you the time of execution. To calculate the speed, you will
also need to know the distance the program travels within that time.
 
K

kwikius

Richard said:
Ian Collins said:


That only tells you the time of execution. To calculate the speed, you will
also need to know the distance the program travels within that time.

Unless the app is so fast that it distorts space time . Once the speed
of light itself is approached however, buffer overruns cannot occur.
Running the app at a high temperature has also been shown to increase
performance in some cases.

regards
Andy Little
 
D

David Wade

Richard Heathfield said:
Ian Collins said:


That only tells you the time of execution. To calculate the speed, you will
also need to know the distance the program travels within that time.

Is that why mainframes are faster then? As they are physically bigger the
program bytes have further to travel from the RAM to the CPU so they must
travel at a higher speed?
 
C

Chris Hills

David Wade said:
Is that why mainframes are faster then? As they are physically bigger the
program bytes have further to travel from the RAM to the CPU so they must
travel at a higher speed?

Silly boy..... Lap tops programs are fastest because they travel at
several 100's MPH when used in an aircraft.

Though you could argue programs in satellites are faster (assuming they
are not geo-stationary) but then you have to take relativity into
account......

Is it Friday afternoon again? That came round quickly :)
 
D

David Wade

Is it Friday afternoon again? That came round quickly :)

I guess so. But I suppose any one who asks a question like that without
doing an research deserves evrey thing they get,,,
 
P

pete

kavi said:
Hello friends,

Could any one tell the way of calculating the speed of c program
execution?

The clock function in <time.h> is for timing programs
or parts of programs.

{
clock_t start, stop;

start = clock();
while (start == clock()) {
;
}
start = clock();
/*
** Timed event goes here
*/
stop = clock();
return (double)(stop - start) / (double)CLOCKS_PER_SEC;
}

7.23.2.1 The clock function
Synopsis
[#1]
#include <time.h>
clock_t clock(void);
Description
[#2] The clock function determines the processor time used.
Returns
[#3] The clock function returns the implementation's best
approximation to the processor time used by the program
since the beginning of an implementation-defined era related
only to the program invocation. To determine the time in
seconds, the value returned by the clock function should be
divided by the value of the macro CLOCKS_PER_SEC. If the
processor time used is not available or its value cannot be
represented, the function returns the value clock_t)-1.252)
____________________
252In order to measure the time spent in a program, the
clock function should be called at the start of the
program and its return value subtracted from the value
returned by subsequent calls.
 
R

Richard Heathfield

pete said:
The clock function in <time.h> is for timing programs
or parts of programs.

{
clock_t start, stop;

start = clock();
while (start == clock()) {
;
}
start = clock();
/*
** Timed event goes here
*/
stop = clock();
return (double)(stop - start) / (double)CLOCKS_PER_SEC;

This code could, of course, return a /negative/ value, which would make the
performance stats seem very impressive indeed.
 
O

osmium

kavi said:
Could any one tell the way of calculating the speed of c program
execution?

That's virtually impossible given the complexity of the current hardware and
software. Intel, AMD and others may have simulators that provide a good
estimate, but simulating is not actually calculating. Furthermore, I am
quite sure such simulators would be closely held. So the answer is no.

Your second post only makes sense to people using the Google Bulletin Board,
it is nonsense to the general Usenet population.
 
N

Nelu

pete said:
kavi said:
Hello friends,

Could any one tell the way of calculating the speed of c program
execution?

The clock function in <time.h> is for timing programs
or parts of programs.

{
clock_t start, stop;

start = clock();
while (start == clock()) {
;
}
start = clock();
/*
** Timed event goes here
*/
stop = clock();
return (double)(stop - start) / (double)CLOCKS_PER_SEC;
}

7.23.2.1 The clock function
Synopsis
[#1]
#include <time.h>
clock_t clock(void);
Description
[#2] The clock function determines the processor time used.
Returns
[#3] The clock function returns the implementation's best
approximation to the processor time used by the program
since the beginning of an implementation-defined era related
only to the program invocation. To determine the time in
seconds, the value returned by the clock function should be
divided by the value of the macro CLOCKS_PER_SEC. If the
processor time used is not available or its value cannot be
represented, the function returns the value clock_t)-1.252)
____________________
252In order to measure the time spent in a program, the
clock function should be called at the start of the
program and its return value subtracted from the value
returned by subsequent calls.
From my man: "Note that the time can wrap around. On a 32 bit system
where CLOCKS_PER_SEC equals 1000000 this function will return the
same value approximately every 72 minutes".
If this is the case, I hope his program doesn't need 72 minutes to
complete.
In that case he's better off using a stop watch :).
Is clock affected by other processes in a multitasking OS, or does it
count only when the CPU works on the calling process?
 
R

Richard Harter

Your second post only makes sense to people using the Google Bulletin Board,
it is nonsense to the general Usenet population.

While it is indeed good policy to quote that to which one is
responding, it is not the case that it only makes sense to people
using the Google Bulletin Board. Many usenet readers use news readers
that are threaded - I've been reading usenet for 24 years and I've
never used one that wasn't.

Although propagation times do vary and it can happen that a response
arrives before the original, it is unusual and the delay is usually
minor.

In short, your comment was an overstatement.



Richard Harter, (e-mail address removed)
http://home.tiac.net/~cri, http://www.varinoma.com
It is not wise to examine apparent coincidences too closely.
Sometimes they are not coincidences at all.
 
P

pete

Nelu said:
kavi said:
Hello friends,

Could any one tell the way of calculating the speed of c program
execution?

The clock function in <time.h> is for timing programs
or parts of programs.

{
clock_t start, stop;

start = clock();
while (start == clock()) {
;
}
start = clock();
/*
** Timed event goes here
*/
stop = clock();
return (double)(stop - start) / (double)CLOCKS_PER_SEC;
}

7.23.2.1 The clock function
Synopsis
[#1]
#include <time.h>
clock_t clock(void);
Description
[#2] The clock function determines the processor time used.
Returns
[#3] The clock function returns the implementation's best
approximation to the processor time used by the program
since the beginning of an implementation-defined era related
only to the program invocation. To determine the time in
seconds, the value returned by the clock function should be
divided by the value of the macro CLOCKS_PER_SEC. If the
processor time used is not available or its value cannot be
represented, the function returns the value clock_t)-1.252)
____________________
252In order to measure the time spent in a program, the
clock function should be called at the start of the
program and its return value subtracted from the value
returned by subsequent calls.
From my man: "Note that the time can wrap around. On a 32 bit system
where CLOCKS_PER_SEC equals 1000000 this function will return the
same value approximately every 72 minutes".
If this is the case, I hope his program doesn't need 72 minutes to
complete.
In that case he's better off using a stop watch :).

.... or maybe even a calendar.
Is clock affected by other processes in a multitasking OS, or does it
count only when the CPU works on the calling process?

"the implementation's best approximation
to the processor time used by the program"

.... which means
"only when the CPU works on the calling process"
except that
"other processes in a multitasking OS"
make the timing more complicated and possibly less accurate.
 
J

Julian V. Noble

kwikius said:
Unless the app is so fast that it distorts space time . Once the speed
of light itself is approached however, buffer overruns cannot occur.
Running the app at a high temperature has also been shown to increase
performance in some cases.

regards
Andy Little

Until meltdown occurs. You guys are probably too young to recall
the "Taiwan Syndrome" where a computer used to overheat to the
point that it melted its way through the earth until it returned
to where it was constructed.
 
N

Nelu

pete said:
... or maybe even a calendar.
.... whatever is more appropriate :).
"the implementation's best approximation
to the processor time used by the program"

... which means
"only when the CPU works on the calling process"
except that
"other processes in a multitasking OS"
make the timing more complicated and possibly less accurate.
That's why I asked, because it can be difficult to time in a
multitasking
environment. I guess that's been taken care of in the man where it
says:
"The clock() function returns an approximation". I just didn't know
whether the "approximation" had to do with multitasking or it was
something related to the processor no matter what the environment was.
 
C

CBFalconer

Richard said:
While it is indeed good policy to quote that to which one is
responding, it is not the case that it only makes sense to people
using the Google Bulletin Board. Many usenet readers use news
readers that are threaded - I've been reading usenet for 24 years
and I've never used one that wasn't.

Although propagation times do vary and it can happen that a
response arrives before the original, it is unusual and the delay
is usually minor.

In short, your comment was an overstatement.

It has nothing to do with threading (although that may affect the
end convenience) and everything to do with the raw mechanism.
Usenet articles are distributed on an "I hope it gets there"
philosophy. Any failure along a complicated path can effective
lose an article forever (at any particular news servers location).
Even if the article does make it to the server, its life there may
be severely limited by the servers own policies.

In short, Osmiums comment was an understatement.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
M

Mike Wahler

kavi said:
Hello friends,

Could any one tell the way of calculating the speed of c program
execution?

unsigned long speed(unsigned long distance,
unsigned long time)
{
return distance / time;
}

-Mike
 
O

osmium

Richard Harter said:
While it is indeed good policy to quote that to which one is
responding, it is not the case that it only makes sense to people
using the Google Bulletin Board. Many usenet readers use news readers
that are threaded - I've been reading usenet for 24 years and I've
never used one that wasn't.

Although propagation times do vary and it can happen that a response
arrives before the original, it is unusual and the delay is usually
minor.

In short, your comment was an overstatement.

Thanks for clarifying that. I'll bet there is a lots more traffic now than
there was in 1982?

Society depends on vigilant, public-spirited people like you to keep the
rest of us on the straight and narrow. Keep up the good work!
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,517
Latest member
Andres38A1

Latest Threads

Top