Tip for people who optimize their code

  • Thread starter kroni
  • Start date
  • Tags
    Code
In summary, Intel compiler and Intel profiler are available for free as student licenses without trial time.
  • #1
kroni
80
10
Hello everybody.

I am looking question for programming and computer science since 6 months and i see a lot of threat speaking about time consumption and optimization. I just want to say that INTEL COMPILER and INTEL PROFILER are available on intel website for FREE as a student license without trial time.

Intel compiler use inter function optimisation, powerfull optimisation, automatic partial parralélization. I see a mean of 30% time gain. (Don't forget to recompile the libs with it.)

Intel profiler give you a detailled (line by line) time description of your C++ file and give caches miss and if bad prédiction, and a lot of other interesting information.

When the algorithm and the program structure is optimized, you can reduce the time with this tool.
 
Technology news on Phys.org
  • #2
Thank you for sharing this tip!

I think the optimization threads that you've seen probably have something to do with homework where students are learning the whys of writing a program a certain way. Optimization tools don't always catch all optimizations which look like valid programming.

In my experience there is a kind of time / memory curve that your program falls into. Making use less time means saving data in intermediate structures using more memory. Conversely saving memory may mean recalculating results again which takes more time. The experienced programmer will try to balance these two parameters while trying to keep the program understandable and extendable for the future.
 
  • #3
I am agree, you have a memory / time curve but micro optimisation done by compiler as register optimisation, SIMD etc have no memory cost but are very effective.
For example this simple code :

double a = 32.0;
for (size_t i = 0; i<1000000; ++i)
{
a = (a+3.0)/2.0;
if (a<3.7 && a>2.1) std::cout << "toto" << std::endl;
}

There is no really big optimisation that can be done. But if you compile it in -O0 in G++ and in -O3 (full optimisation) then you will divide the execution time by 100. It's the reason why Intel compiler give better execution time with no effort.
 

What is code optimization?

Code optimization is the process of improving the efficiency and performance of a computer program. This can involve reducing the time it takes for the program to run, minimizing the amount of memory it uses, and improving the overall speed and functionality of the code.

Why is code optimization important?

Code optimization is important because it can significantly improve the performance of a program, making it run faster and more smoothly. This can save time and resources, and also improve the overall user experience.

What are some common tips for optimizing code?

Some common tips for optimizing code include using efficient algorithms and data structures, minimizing the use of global variables, avoiding unnecessary calculations and loops, and testing and profiling the code to identify and address any performance issues.

How can I measure the effectiveness of code optimization?

The effectiveness of code optimization can be measured by running performance tests before and after the optimization process. This can include measuring the execution time, memory usage, and other relevant metrics to see the impact of the changes made to the code.

Are there any potential drawbacks to code optimization?

While code optimization can bring many benefits, there are also potential drawbacks to consider. For example, optimizing code may make it more complex and difficult to maintain, and it may also require additional time and resources. Additionally, some optimizations may not work as expected and could potentially introduce bugs or other issues in the code.

Similar threads

Replies
1
Views
813
  • Programming and Computer Science
2
Replies
49
Views
10K
  • STEM Academic Advising
Replies
13
Views
2K
Replies
2
Views
3K
  • STEM Academic Advising
Replies
2
Views
4K
Replies
20
Views
9K
  • Special and General Relativity
Replies
13
Views
2K
Back
Top