C/C++ speed optimization bible/resources/pointers needed!

This is a discussion on C/C++ speed optimization bible/resources/pointers needed! within the Other Technologies forums in category; > So the kay point is how > to arrange our C/C++ code to make it highly efficient in every aspect. > Could anybody give some advice/pointers on how to improve the speed of > C/C++ program? If it is general C++ advice you are looking for you could do worse than getting Scott Meyers 3 books: Effective C++ 3rd edition More Effective C++ Effective STL There are quite a few "best practice" books that help here. In general: Initialise constructor members in initialisation lists rather than bodies of constructors Pass by reference when you can, pointers otherwise than by ...

Go Back   Application Development Forum > Other Technologies

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #41  
Old 07-27-2007, 09:55 AM
Stephen Howe
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!

> So the kay point is how
> to arrange our C/C++ code to make it highly efficient in every aspect.
> Could anybody give some advice/pointers on how to improve the speed of
> C/C++ program?


If it is general C++ advice you are looking for you could do worse than
getting Scott Meyers 3 books:
Effective C++ 3rd edition
More Effective C++
Effective STL

There are quite a few "best practice" books that help here.

In general:
Initialise constructor members in initialisation lists rather than bodies of
constructors
Pass by reference when you can, pointers otherwise than by value (except
possibly builtin types).
And all the gotchas when using STL container classes.
Be aware of the different algorithms available to you.
Use static_cast when safe and correct to do so rather than dynamic_cast.
strstream with static buffers is faster than stringstream (because no heap
memory)

There is more, and in general writing "clean" C++ is fast.

Stephen Howe


Reply With Quote
  #42  
Old 07-27-2007, 10:09 AM
Les
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!


"Luna Moon" <lunamoonmoon@gmail.com> wrote in message
news:f8clk4$n0$1@news.Stanford.EDU...
>


<snip>

> As I said, I am confined to what I have. Let's focus on coding good C++...
>


Then why are you posting to comp.lang.fortran ? :-)

Take a look at the following link

www.flounder.com/optimization.htm

quote "Optimization matters only when it matters. When it matters, it
matters a lot, but until you know that it matters, don't waste a lot of time
doing it. Even if you know it matters, you need to know where it matters.
Without performance data, you won't know what to optimize, and you'll
probably optimize the wrong thing."

Les


Reply With Quote
  #43  
Old 07-27-2007, 10:15 AM
Androcles
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!


"Walter Banks" <walter@bytecraft.com> wrote in message
news:46A9DB6D.8E1F1BC5@bytecraft.com...
:
:
: srp@microtec.net wrote:
:
: > Short of going to straight assembly language, nothing is faster.
:
: Many C compilers easily beat most asm code in my experience

That shows the extent of your experence...





Reply With Quote
  #44  
Old 07-27-2007, 10:50 AM
Chip Eastham
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!

On Jul 27, 12:00 am, "Luna Moon" <lunamoonm...@gmail.com> wrote:
> "Chip Eastham" <hardm...@gmail.com> wrote in message
>
> news:1185498567.079147.230700@19g2000hsx.googlegro ups.com...
>
>
>
> > On Jul 26, 5:19 pm, lunamoonm...@gmail.com wrote:
> >> C/C++ speed optimization bible/resources/pointers needed!

>
> >> Hi all,

>
> >> I am in the middle of programming to solve an engineering problem
> >> where the speed is huge concern. The project involving lots of
> >> numerical integration and then there are several loops/levels of
> >> optimization on top of the function evaluation engine. As you probably
> >> know, the key to a successful optimization is a fast underlying
> >> objective function evaluator. The faster it is, the more promising the
> >> optimization result(perhaps global optimal). However our project
> >> requires many numerical integrations which prohibits us from making it
> >> super fast. At the heart of the numerical integration is a smart
> >> integrator and a super-fast integrand function evaluator. Even worse,
> >> our function evaluation is in complex-domain. So the kay point is how
> >> to arrange our C/C++ code to make it highly efficient in every aspect.
> >> Could anybody give some advice/pointers on how to improve the speed of
> >> C/C++ program? How to arrange code? How to make it highly efficient
> >> and super fast? What options do I have if I don't have luxury to use
> >> multi-threaded, multi-core or distributed computing? But I do have a
> >> P4 at least. Please recommend some good bibles and resources! Thank
> >> you!

>
> > You haven't described the problem in sufficient detail
> > to make specific recommendations. You should look for
> > ways to to reuse function evaluations. At one level
> > the numerical integrator should be (probably is) doing
> > this, and it isn't clear what you mean by saying "our
> > function evaluation is in complex-domain". You may
> > have some opportunities if you are carrying out line
> > integrations in the complex plane to pick up several
> > of the function values you need in one pass of the
> > line integration, or to pick up a line integration
> > from a nearby point at which a previous pass left
> > off.

>
> > regards, chip

>
> Thanks Chip. By "complex-domain" I meant the integrand numbers are
> complex-valued. Any more thoughts?


In your original post you mention optimization,
which suggests that ultimately you are getting
real function values. This may be several steps
away from where you are performing a complex
function evaluation, but perhaps there's some
advantage in reformulating the problem to make
the real computation as explicit as possible.

It might be helpful to know if the integration
is always being done on the same interval
(while varying parameters that affect the
complex-valued integrand) or if the same
complex-valued function is being integrated
over a variety of intervals.

regards, chip

Reply With Quote
  #45  
Old 07-27-2007, 10:55 AM
Gary Scott
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!

jimp@specsol.spam.sux.com wrote:
> In sci.physics Luna Moon <lunamoonmoon@gmail.com> wrote:
>
>
>><jimp@specsol.spam.sux.com> wrote in message
>>news:jtpnn4-ras.ln1@mail.specsol.com...
>>
>>>In sci.physics lunamoonmoon@gmail.com wrote:
>>>
>>>>C/C++ speed optimization bible/resources/pointers needed!
>>>
>>>>Hi all,
>>>
>>>>I am in the middle of programming to solve an engineering problem
>>>>where the speed is huge concern. The project involving lots of
>>>>numerical integration and then there are several loops/levels of
>>>>optimization on top of the function evaluation engine. As you probably
>>>>know, the key to a successful optimization is a fast underlying
>>>>objective function evaluator. The faster it is, the more promising the
>>>>optimization result(perhaps global optimal). However our project
>>>>requires many numerical integrations which prohibits us from making it
>>>>super fast. At the heart of the numerical integration is a smart
>>>>integrator and a super-fast integrand function evaluator. Even worse,
>>>>our function evaluation is in complex-domain. So the kay point is how
>>>>to arrange our C/C++ code to make it highly efficient in every aspect.
>>>>Could anybody give some advice/pointers on how to improve the speed of
>>>>C/C++ program? How to arrange code? How to make it highly efficient
>>>>and super fast? What options do I have if I don't have luxury to use
>>>>multi-threaded, multi-core or distributed computing? But I do have a
>>>>P4 at least. Please recommend some good bibles and resources! Thank
>>>>you!
>>>
>>>One more thought, both the OS and the compiler can make a big difference.
>>>
>>>Some years ago I did some benchmarking on a customer's application
>>>on windows, Linux, SCO Unix, Solaris X86, and Unixware both with
>>>the vendors compiler and GNU all on the same hardware.
>>>
>>>I lost the numbers long ago, but windows was the absolute slowest.
>>>
>>>Linux, Solaris X86, and the Sun compiler are all free for the download.
>>>
>>>It might not hurt to run some benchmarks on your app.
>>>
>>>--
>>>Jim Pennino
>>>
>>>Remove .spam.sux to reply.

>
>
>>Thanks! But I cannot ask our head to give me a linux box. I am confined
>>within what I have now. I have to do whatever I can and use whatever I have
>>from my part only.

>
>
> Sigh, Linux is free; all you have to do is download and install it.
>
> Linux will be a LOT faster than Windows when doing number crunching.
>

Don't know about a LOT faster...if the machine is dedicated to the task,
there's plenty of options available to tune the performance on windows.

--

Gary Scott
mailto:garylscott@sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford
Reply With Quote
  #46  
Old 07-27-2007, 10:57 AM
Chip Eastham
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!

On Jul 27, 10:15 am, "Androcles" <Engin...@hogwarts.physics> wrote:
> "Walter Banks" <wal...@bytecraft.com> wrote in message
>
> news:46A9DB6D.8E1F1BC5@bytecraft.com...
> :
> :: s...@microtec.net wrote:
>
> :
> : > Short of going to straight assembly language, nothing is faster.
> :
> : Many C compilers easily beat most asm code in my experience
>
> That shows the extent of your experence...


.... or perhaps the quality his asm code!

--c

Reply With Quote
  #47  
Old 07-27-2007, 10:58 AM
Jerry Avins
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!

Gianni Mariani wrote:
> srp@microtec.net wrote:
>> On 26 juil, 17:19, lunamoonm...@gmail.com wrote:

> ...
>> Your best bet with C/C++ is to get a fast computer. Optimization
>> is only nominal with these compilers.

>
> "nominal"? It's critical.
>
> I have no idea what you're alluding to but if you're trying to say that
> the optimizer is not one of the critical parts of a C++ compiler when it
> comes to performance, you're very mistaken.


He means that It is not strong optimization. Here, he means that it is
optimization in name only. That I explain doesn't mean that I agree.

Jerry
--
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Reply With Quote
  #48  
Old 07-27-2007, 11:02 AM
Jerry Avins
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!

Luna Moon wrote:

...

> thanks! It's good to know Forth is the fastest.


It's fast, but not necessarily fastest. There are many competing threads
in Windows. Do you have an assessment of the fraction of cycles they use?

Jerry
--
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Reply With Quote
  #49  
Old 07-27-2007, 11:23 AM
Jerry Avins
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!

Luna Moon wrote:

...

> I cannot build Linux myself, it is a large organization. I am confined.


You can run Linux on a Windows box from a single CD.
http://www.knopper.net/knoppix/index-en.html

You ask what you can do without changing anything. It may not seem
obvious while you grasp at straws to stay afloat, but if you change
nothing, then there will be no new result.

Your main task is making your boss happy. It is his responsibility to
supply you with the resources you need to do that. If your hands are
tied, circulate your resume.

Jerry
--
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Reply With Quote
  #50  
Old 07-27-2007, 11:25 AM
jimp@specsol.spam.sux.com
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!

In sci.physics glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:
> jimp@specsol.spam.sux.com wrote:


> (snip)


> > Sigh, Linux is free; all you have to do is download and install it.


> > Linux will be a LOT faster than Windows when doing number crunching.


> There is no reason Linux should be faster, in general, for number
> crunching. The numeric instructions take the same number of cycles
> independent of the OS. For speedy number crunching one should minimize
> the amount of paging, which could be OS dependent, as could I/O.


> If one is doing a lot of paging or I/O, then I would say that one
> is not doing number crunching. (That is, the task is I/O limited
> and not CPU limited.)


> (Not that I don't agree that Linux is a much better system to
> use than the others under consideration.)


> -- glen


I never said Linux was a better choice than any other 'nix.

What I said was windows was the worst possible choice.

The why is in the way windows implements multitasking.

Note that is TASKING, not PROCESSING.

Even though windows is not multiUSER, it is still multiTASKING as
all sorts of processes are running at the same time, not the
least of which is the windowing GUI system itself.

In a 'nix system, not only is the multiTASKING better, but you can
also turn off the GUI which is one less thing for the CPU to do.

Paging in any OS will slow things down significantly.

--
Jim Pennino

Remove .spam.sux to reply.
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 06:25 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.