Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the functions in the standard library that can be implemented faster with programming hacks? [closed]

I have recently read an article about fast sqrt calculation. Therefore, I have decided to ask SO community and its experts to help me find out, which STL algorithms or mathematical calculations can be implemented faster with programming hacks?

It would be great if you can give examples or links.

Thanks in advance.

like image 885
baris.aydinoz Avatar asked Feb 01 '11 15:02

baris.aydinoz


2 Answers

System library developers have more concerns than just performance in mind:

  • Correctness and standards compliance: Critical!

  • General use: No optimisations are introduced, unless they benefit the majority of users.

  • Maintainability: Good hand-written assembly code can be faster, but you don't see much of it. Why?

  • Portability: Decent libraries should be portable to more than just Windows/x86/32bit.

Many optimisation hacks that you see around violate one or more of the requirements above. In addition, optimisations that will be useless or even break when the next generation CPU comes around the corner are not a welcome thing.

If you don't have profiler evidence on it being really useful, don't bother optimising the system libraries. If you do, work on your own algorithms and code first, anyway...

EDIT:

I should also mention a couple of other all-encompassing concerns:

  • The cost/effort to profit/result ratio: Optimisations are an investment. Some of them are seemingly-impressive bubbles. Others are deeper and more effective in the long run. Their benefits must always be considered in relation to the cost of developing and maintaining them.

  • The marketing people: No matter what you think, you'll end up doing whatever they want - or think they want.

like image 87
thkala Avatar answered Oct 18 '22 21:10

thkala


Probably all of them can be made faster for a specific problem domain.

Now the real question is, which ones should you hack to make faster? None, until the profiler tells you to.

like image 22
John Dibling Avatar answered Oct 18 '22 21:10

John Dibling