473,386 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

speed of execution

Hello friends,

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

May 19 '06 #1
40 2925
kavi wrote:
Hello friends,

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

Time it?

--
Ian Collins.
May 19 '06 #2
Ian Collins said:
kavi wrote:
Hello friends,

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

Time it?


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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 19 '06 #3
yes. Exactly.

May 19 '06 #4
Richard Heathfield wrote:
Ian Collins said:
kavi wrote:
Hello friends,

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

Time it?


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

May 19 '06 #5

"Richard Heathfield" <in*****@invalid.invalid> wrote in message
news:nv******************************@bt.com...
Ian Collins said:
kavi wrote:
Hello friends,

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


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?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

May 19 '06 #6
In article <7_********************@eclipse.net.uk>, David Wade
<g8***@yahoo.com> writes

"Richard Heathfield" <in*****@invalid.invalid> wrote in message
news:nv******************************@bt.com...
Ian Collins said:
> kavi wrote:
>> Hello friends,
>>
>> Could any one tell the way of calculating the speed of c program
>> execution?
>>
> Time it?


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?


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 :-)
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

May 19 '06 #7
>
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,,,

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

May 19 '06 #8
kavi wrote:

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.

--
pete
May 19 '06 #9
pete said:
kavi wrote:

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;


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

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 19 '06 #10
"kavi" writes:
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.
May 19 '06 #11

pete wrote:
kavi wrote:

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?

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)

May 19 '06 #12
On Fri, 19 May 2006 06:17:18 -0700, "osmium" <r1********@comcast.net>
wrote:
"kavi" writes:
Could any one tell the way of calculating the speed of c program
execution?
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, cr*@tiac.net
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.
May 19 '06 #13
Nelu wrote:

pete wrote:
kavi wrote:

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.

--
pete
May 19 '06 #14
kwikius wrote:
Richard Heathfield wrote:
Ian Collins said:
kavi wrote:
Hello friends,

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

Time it?

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


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.

--
Julian V. Noble
Professor Emeritus of Physics
University of Virginia
May 19 '06 #15
kavi wrote:
Hello friends,

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


Depends on how fast the guillotine is falling.

--
Julian V. Noble
Professor Emeritus of Physics
University of Virginia
May 19 '06 #16

pete wrote:
Nelu wrote:
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.

.... whatever is more appropriate :-).
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.

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.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)

May 19 '06 #17

"kavi" <ka**************@yahoo.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
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
May 19 '06 #18
"Richard Harter" writes:
On Fri, 19 May 2006 06:17:18 -0700, "osmium" <r1********@comcast.net>
wrote:
"kavi" writes:
Could any one tell the way of calculating the speed of c program
execution?

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.


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!
May 19 '06 #19
Richard Harter wrote:
"osmium" <r1********@comcast.net> wrote:
"kavi" writes:
Could any one tell the way of calculating the speed of c program
execution?

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.


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/>

May 19 '06 #20
kavi wrote:
yes. Exactly.

No. Inexactly.

Who are you talking to?
May 19 '06 #21
In article <11**********************@j73g2000cwa.googlegroups .com>, Nelu
<ta********@gmail.com> writes
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 :-).


I once had a customer call me to say that after the upgrade to the new
version of a compiler/simulator (from several versions older) the
simulator was complete CRAP!!!

Apparently.... and this is absolutely true, he had been timing programs
running in the simulator with a stopwatch!!! In the new simulator the
timing was way out.

It appeared that on the particular PC he used with that particular
version of the simulator for his particular application the simulator
was running in approximate real time. SO he could time it +/- a second
with a stopwatch.

He now expected me to fix the new version of the simulator so that on
his new PC and OS it ran in real time like the old one. If I couldn't as
far as he was concerned it was broken and he wanted his money back!!!

That is not something I saw on the net, or happened to a friend... It
happened to me and I had to convince this "engineer" that his new
simulator was not broken because it did not run in real time.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

May 19 '06 #22
On 2006-05-19, Richard Heathfield <in*****@invalid.invalid> wrote:
pete said:
kavi wrote:

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;


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

It's possible: http://physorg.com/news66582110.html

--
Andrew Poelstra [apoelstra@wp____ware.net] < http://www.wpsoftware.net/blog >
Get your game faces on, because this is not a game.
May 19 '06 #23
In article <44****************@news.sbtc.net>,
Richard Harter <cr*@tiac.net> wrote:
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.


Which threaded newsreaders did you use in 1982 (24 years ago)
and 1983 (23 years ago)? We should get the official histories
corrected, as they make the mistake of saying that the first
threaded newsreader was nn, written in 1984 (22 years ago).

http://en.wikipedia.org/wiki/Trn
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
May 19 '06 #24
In article <q6****************@newsread2.news.pas.earthlink.n et>,
Mike Wahler <mk******@mkwahler.net> wrote:
"kavi" <ka**************@yahoo.com> wrote in message
news:11**********************@u72g2000cwu.googleg roups.com...
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;
}


That's not very robust: it truncates the results, and so has
an accuracy that depends crucially on the units.

It also fails to check whether time is 0 before doing the division;
the probability of time being 0 is going to depend upon the units
in the best of circumstances, and if the time is the difference between
clock() readings then that difference is going to be 0 on implementations
that do not have a realtime clock available.
--
All is vanity. -- Ecclesiastes
May 19 '06 #25

Chris Hills wrote:
<snip>

Apparently.... and this is absolutely true, he had been timing programs
running in the simulator with a stopwatch!!! In the new simulator the
timing was way out.
<snip>


I had a coleague at the University like that. That's why I asked about
the multithreaded
environment. He was comparing MS DOS with other systems, but when he
was timing
the program under MS-DOS he was going for a smoke and when he was
timing
the one under Windows 95 he was playing some robots game that was using
enough CPU
to matter.
He was also using a stop watch :-).

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)

May 19 '06 #26
kavi wrote:
yes. Exactly.


warm. Partly-cloudy. See below.


Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
May 19 '06 #27

"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.ca> wrote in message
news:e4**********@canopus.cc.umanitoba.ca...
In article <q6****************@newsread2.news.pas.earthlink.n et>,
Mike Wahler <mk******@mkwahler.net> wrote:
"kavi" <ka**************@yahoo.com> wrote in message
news:11**********************@u72g2000cwu.google groups.com...

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;
}


That's not very robust:


It was not intended to be. :-)

-Mike


May 19 '06 #28

Richard Heathfield wrote:
Ian Collins said:
kavi wrote:
Hello friends,

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

Time it?


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.


This requires the existence of both time and space. I don't think
the standard requires either of these, so the entire idea of
judging the speed of a program is probably non-portable.

May 19 '06 #29
Bill Pursell said:

Richard Heathfield wrote:
Ian Collins said:
> kavi wrote:
>> Hello friends,
>>
>> Could any one tell the way of calculating the speed of c program
>> execution?
>>
> Time it?
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.


This requires the existence of both time


4.12.2.4 The time function

Synopsis

#include <time.h>
time_t time(time_t *timer);

Description

The time function determines the current calendar time. The
encoding of the value is unspecified.

and space.
2.2.1 Character sets

[...] Both the basic source and basic execution character sets shall have
at least the following members: the 26 upper-case letters of the
English alphabet [elided] the 26 lower-case letters of the English alphabet
[elided] the 10 decimal digits [elided] the following 29 graphic characters
[elided] the space character,"
I don't think
the standard requires either of these,


I beg to differ. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 19 '06 #30
Richard Heathfield wrote:
Ian Collins said:

kavi wrote:
Hello friends,

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


Time it?

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.


In these times, isn't it more important to know it's
fuel economy? i.e. distance / fuel used, preferably in
miles/gallon or kilometers/liter.

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
May 19 '06 #31
> >> 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.

It's possible: http://physorg.com/news66582110.html


Just an aside. In order to know the speed of code, you need to know what you
are executing. In the general case with "C" this is not possible as the
optimiser can reorder the code. I guess its should know about "clock()" but
as "start" and "stop" are local variables in the above code, I would assume
that some of the more basic optinizers could re-arrange the coide as :-

start =stop= clock();

/*
** Timed event gets moved here
*/

Because after all , if the code in timed event does not access any
externals, then it can't affect the results returned by clock....

Or have I just had too much "bombardier" preium bitter 5.2% abv.

Dave.

--
Andrew Poelstra [apoelstra@wp____ware.net] < http://www.wpsoftware.net/blog > Get your game faces on, because this is not a game.

May 19 '06 #32
kavi wrote:
Could any one tell the way of calculating the speed of c program
execution?


In general, it is very difficult. I have done it in special cases, such
as timing loops for an 8-bit embedded processor. You need to know the
machine instructions generated by the compiler, the number of processor
cycles each instruction takes to execute, and the processor clock frequency.

For desktop machines (and other large processors) it is much more
difficult because of pipelined execution, cache hit/miss, branch
prediction, interrupt loading, and other factors that make the machines
fast, but their timing less predictable.

If you want to know how to _measure_ the speed of code running on a
particular machine with a particular environment, that is a very
different question.

--
Thad
May 20 '06 #33
"kavi" <ka**************@yahoo.com> wrote
Hello friends,

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

Go into the inner loop of your program and count how many memory access it
makes, assuming it calls no library functions. Then add a bit.
--
www.personal.leeds.ac.uk/~bgy1mm


May 20 '06 #34
David Wade wrote:
Just an aside. In order to know the speed of code,
you need to know what you are executing.
In the general case with "C" this is not possible as the
optimiser can reorder the code.
I guess its should know about "clock()"
It's exactly the opposite.
The compiler doesn't know what any standard library functions do.
but as "start" and "stop" are local variables in the above code,
If they were external variables, then that would matter, how?
I would assume
that some of the more basic optinizers could re-arrange the coide as :-

start =stop= clock();

/*
** Timed event gets moved here
*/

Because after all , if the code in timed event does not access any
externals, then it can't affect the results returned by clock....
The compiler doesn't know what any functions do,
so it isn't free to replace two function calls with one.

x = getchar();
x = getchar();
Or have I just had too much "bombardier" preium bitter 5.2% abv.


By process of elimination, that's the problem.

--
pete
May 20 '06 #35

Richard Heathfield wrote:
Bill Pursell said:

Richard Heathfield wrote, regarding speed of a program:

[Timing it] 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.


This requires the existence of both time


4.12.2.4 The time function

Synopsis

#include <time.h>
time_t time(time_t *timer);

Description

The time function determines the current calendar time. The
encoding of the value is unspecified.

and space.


2.2.1 Character sets

[...] Both the basic source and basic execution character sets shall have
at least the following members: the 26 upper-case letters of the
English alphabet [elided] the 26 lower-case letters of the English alphabet
[elided] the 10 decimal digits [elided] the following 29 graphic characters
[elided] the space character,"
I don't think
the standard requires either of these,


I beg to differ. :-)


So if whitespace in the source is how space (and therefore
distance) is measured in a program, then increasing the
whitespace should make your code run faster since it
increases the distance without affecting the run time.
That certainly puts optimization in a different perspective. :)

May 20 '06 #36
pete <pf*****@mindspring.com> writes:
David Wade wrote:
Just an aside. In order to know the speed of code,
you need to know what you are executing.
In the general case with "C" this is not possible as the
optimiser can reorder the code.
I guess its should know about "clock()"


It's exactly the opposite.
The compiler doesn't know what any standard library functions do.


Actually, the compiler is allowed to use its knowledge of how standard
library functions behave, though it's not likely to be useful in the
case of clock().
but as "start" and "stop" are local variables in the above code,


If they were external variables, then that would matter, how?


It could matter in some cases, but not in this one. For example, if
they were local, then their values on leaving the block wouldn't
matter, which could introduce some opportunities for optimization.
I would assume
that some of the more basic optinizers could re-arrange the coide as :-

start =stop= clock();

/*
** Timed event gets moved here
*/

Because after all , if the code in timed event does not access any
externals, then it can't affect the results returned by clock....


The compiler doesn't know what any functions do,
so it isn't free to replace two function calls with one.

x = getchar();
x = getchar();


You're right in the case of clock() and getchar(), but not in general.
For example, given

y = sin(x);
y = sin(x);

the compiler is free to generate just one call to sin() (or none, if
it can determine the value of x at compile time, or if the result
isn't used).

I've seen this:
printf("hello, world\n");
compiled to the equivalent of this:
puts("hello, world");

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 21 '06 #37
Bill Pursell wrote:

Richard Heathfield wrote:
Bill Pursell said:

Richard Heathfield wrote, regarding speed of a program:
>
> [Timing it] only tells you the time of execution.

That would be the appropriate definition of "speed"
to use in this case.
So if whitespace in the source is how space (and therefore
distance) is measured in a program, then increasing the
whitespace should make your code run faster since it
increases the distance without affecting the run time.
That certainly puts optimization in a different perspective. :)


If you want to continue pretending that the
definition of "speed"
in the context of high school physics class,
is the appropriate definition to use here,
then yes.

http://dictionary.reference.com/search?q=speed&db=*

1.Physics. The rate or a measure of the rate of motion, especially:
a.Distance traveled divided by the time of travel.

2.Swiftness of action.

--
pete
May 21 '06 #38
On Fri, 19 May 2006 08:11:53 -0700, "osmium" <r1********@comcast.net>
wrote:
"Richard Harter" writes: [snip]
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?


Likely enough. There has been an enormous expansion of usenet traffic
since then, but not so much in the C newsgroup. I opine that the
difference in traffic between net.lang.c in the 80's and comp.lang.c
now is about a factor of two or three.
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!


Thank you for your kind words and your thoughtful consideration. I
have every confidence that you will reform your ways.

Richard Harter, cr*@tiac.net
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.
May 22 '06 #39
On Fri, 19 May 2006 16:04:34 +0000 (UTC), ro******@ibd.nrc-cnrc.gc.ca
(Walter Roberson) wrote:
In article <44****************@news.sbtc.net>,
Richard Harter <cr*@tiac.net> wrote:
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.


Which threaded newsreaders did you use in 1982 (24 years ago)
and 1983 (23 years ago)? We should get the official histories
corrected, as they make the mistake of saying that the first
threaded newsreader was nn, written in 1984 (22 years ago).

http://en.wikipedia.org/wiki/Trn


I stand corrected. It's been a while, you know.


Richard Harter, cr*@tiac.net
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.
May 22 '06 #40
On Fri, 19 May 2006 10:53:19 -0400, CBFalconer <cb********@yahoo.com>
wrote:
Richard Harter wrote:

[snip]

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.


This is true enough, but not to the point.

Richard Harter, cr*@tiac.net
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.
May 22 '06 #41

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Yang Li Ke | last post by:
Hi guys, Is it possible to know the internet speed of the visitors with php? Thanx -- Yang
4
by: EP | last post by:
On questions of the suitability of Python for CGI, embedded apps, etc., execution speed comes to mind. I previously read some comparisons which did not show Python in a good light in this regard:...
28
by: Maboroshi | last post by:
Hi I am fairly new to programming but not as such that I am a total beginner From what I understand C and C++ are faster languages than Python. Is this because of Pythons ability to operate on...
40
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the...
3
by: linvin333 | last post by:
Hi, Does function overloading affect the speed of execution of the program ? If so what is the reason ? How does it compare with a speed of a program using non-overloded functions ? Linny
9
by: nicolas.hilaire | last post by:
Hi all, i need to choose a langage for porting my vb application to dot net 2.0 in november. For some components, low-level components, i want to know if it can be better to use specific .net...
4
by: Il Prof | last post by:
Hi to everyone! ;) In C language on Linux, what string access method is faster? 1) Puntatori char str="hello"; char* pstr; pstr = str; // access such as "*pstr"
12
by: Marty | last post by:
Hi, I am building an application that need high speed of execution. There is a lot of string parsing that I do in VB.NET. Do I gain in speed if all that string parsing is made in a dll coded...
3
by: serge | last post by:
How do I determine which method I should use if I want to optimize the performance of a database. I took Northwind's database to run my example. My query is I want to retrieve the Employees'...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.