c/c++ Code speed after threading ?? 
Author Message
 c/c++ Code speed after threading ??

Quote:

> The below code did some speed benchmarking for me.. I took a ratio of
> speeds  rather than the difference of speeds before and after
> threading. That would be OS independent i guess.

> //note WriteLog and ToString defined elsewhere
> void SpeedBenchmark(unsigned long Iterations)
> {
>         int Start=time(NULL);

>         //dummy loop
>         for(unsigned long i=0; i<Iterations;++i);

>         int SecondsElapsed=time(NULL)-Start;

>         WriteLog("Seconds taken for "+ToString(Iterations)+"
> iterations: "+ToString(SecondsElapsed),1);
> }

I think you mean

  double SecondsElapsed = difftime (Start, time());

My other comment is, for the poster's original question (how to
determine what impact another thread/process has on this one,) it would
be more accurate to measure the time taken by the normal functions of
this one. That is, this loop probably measures the performance of
register to register operations by a short bit of program that fits
easily in the processors instruction cache.

If the real work this thread performs is, say, receiving network
messages and writing to files, the thing you measure here may have
little relationship to the effect of a second thread or process on the
speed of those operations.



Thu, 29 Jan 2004 23:54:36 GMT  
 c/c++ Code speed after threading ??

Kinarivala) wrote in comp.lang.c:

Quote:
> I need to find the execution speed reduction of a parent thread after
> it spawns a child thread. Is there a CPU independent way of doing this
> ? What criteria should I use in calculation ?

> One approach is to calculate the execution time of a dummy for loop
> both before and after spawning a child, and see the difference.

> Other ideas ?

> Also, is there a way of assigning high priority to a thread ?

> Thanks
> Meetul Kinarivala

Since there is no such thing as a thread or spawning in either the C
or C++ language, you have posted an off-topic question to two
inappropriate groups.  Neither language so much as acknowledges the
existence of multiple streams of execution.

All such features are non-standard extensions and are based on
facilities provided by underlying operating systems, and are different
from one OS to the next.

Ask this in a programming group for your particular OS.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq



Fri, 30 Jan 2004 05:37:03 GMT  
 c/c++ Code speed after threading ??

Quote:

> I need to find the execution speed reduction of a parent thread after
> it spawns a child thread. Is there a CPU independent way of doing this
> ? What criteria should I use in calculation ?

> One approach is to calculate the execution time of a dummy for loop
> both before and after spawning a child, and see the difference.

First, there are no threads in Standard C (or in Standard C++ as far as
I know), so this is off-topic in both newsgroups. Second, it all
depends.

How many processors does your system have? If you have two processors,
and yours is the only running program, then before starting a second
thread you might have one processor running your program, and the other
one doing nothing. After starting a second thread, you may have two
processors running at full speed. Your first process runs at same speed
as before. Same situation on a single processor machine, speed of the
first process might go down by 50%. On the other hand, if there are ten
processes running on your machine anyway and each process gets 1/10th of
the processing power, then starting an eleventh process might reduce
everyones share to 1/11th or a nine percent speed reduction.

What are those programs doing? On a multi-processor machine, each single
processor should run at full speed except when accessing memory or the
harddisk; memory and harddisk are shared resources (but cache memory
most likely is not shared). So two dummy loops should each run at full
speed. Two calls to memset () filling 10 MB of memory with zeroes
probably do _not_ run at full speed. Do you have two processes, each
carefully tuned to take full advantage of L1 and L2 cache? Expect the
tuning to fail and performance going down on a single processor, but no
change in performance on two processors.



Fri, 30 Jan 2004 19:51:17 GMT  
 c/c++ Code speed after threading ??
Thanks for the good tip, Bruce. Why do you need double for SecondsElapsed ?


Quote:

> > The below code did some speed benchmarking for me.. I took a ratio of
> > speeds  rather than the difference of speeds before and after
> > threading. That would be OS independent i guess.

> > //note WriteLog and ToString defined elsewhere
> > void SpeedBenchmark(unsigned long Iterations)
> > {
> >         int Start=time(NULL);

> >         //dummy loop
> >         for(unsigned long i=0; i<Iterations;++i);

> >         int SecondsElapsed=time(NULL)-Start;

> >         WriteLog("Seconds taken for "+ToString(Iterations)+"
> > iterations: "+ToString(SecondsElapsed),1);
> > }

> I think you mean

>   double SecondsElapsed = difftime (Start, time());

> My other comment is, for the poster's original question (how to
> determine what impact another thread/process has on this one,) it would
> be more accurate to measure the time taken by the normal functions of
> this one. That is, this loop probably measures the performance of
> register to register operations by a short bit of program that fits
> easily in the processors instruction cache.

> If the real work this thread performs is, say, receiving network
> messages and writing to files, the thing you measure here may have
> little relationship to the effect of a second thread or process on the
> speed of those operations.



Sat, 31 Jan 2004 03:08:09 GMT  
 c/c++ Code speed after threading ??

Quote:



> > >         int SecondsElapsed=time(NULL)-Start;

> > I think you mean

> >   double SecondsElapsed = difftime (Start, time());

> Thanks for the good tip, Bruce. Why do you need double for SecondsElapsed ?

That's what difftime returns. I suppose it's designed to allow for
systems that
record sub-second intervals int a time_t. Or for systems that run for a
very
long time.


Sat, 31 Jan 2004 10:29:58 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Problem with Visual Studio .NET (C++) - Maximise Speed (/O2) - Unmanaged Code

2. C++ objects in memory VS C structs - Efficiency code/speed/space

3. How to speed optimize c/c++ code

4. Visual C++ 7 speed vs Visual C# speed

5. UI Thread better than Worker thread for speed?

6. Calling C++ from C/Linking (was: C++ code to C Code)

7. Bad Address from Speed Optimized Code

8. Speed difference in Managed and Unmanaged code

9. Optimization for Maximum speed generates wrong code

10. how to speed up the code?

11. Need code to compare speed of two computers.

12. How to optimize execution speed of code ??

 

 
Powered by phpBB® Forum Software