English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

What are the different ways that we can optimize code? How can we use loop unrolling, instruction parallelism, or blocking in nested loops?

2006-10-26 04:44:13 · 5 answers · asked by adoodi_me 1 in Computers & Internet Programming & Design

5 answers

Anyone think that maybe the asker is writing an essay for his compilers class and wanting us to do his homework for him? And therefore not looking for answers like "let the compiler do it?"

Compilers do not appear by magic! Someone has to write them. Therefore someone has to know how to do this stuff. Someone in the next generation is going to have to know how to do this stuff too. Kudos to anyone here learning more about programming than "click the magic button in the IDE."

2006-10-26 09:49:46 · answer #1 · answered by Lisa A 7 · 0 1

Just write clean, comprehensible, tidy code. Trying to optimise it is a bad idea.

1. If you wait 6 months, the latest PCs will give you the same performance improvement for free.

2. The optimisation usually makes the code hard to understand and to make correct alterations to.

3. When you do alter the code afterwards, it will probably undo the optimisation, and worse.

4. Nearly every optimisation you can think of making will be done automatically by the compiler anyway.

2006-10-26 09:12:06 · answer #2 · answered by Anonymous · 0 1

Optimising for performance - optimising so that the code runs as fast as possible. This typically involves techniques like loop unrolling and Duff's device, and using one 64 bit register to set two adjacent 32bit memory locations. Also, using better algorithms - like using shellsort over bubble sort. BSP trees over array-like indexes.

Optimising for memory - optimising so that the code uses the least memory it needs to. Keeping memory allocation to minimal results. You tend to find this type of optimisation in embedded devices where memory is at a premium.

Optimising for energy use - writing routines in such a way as to lower the amount of electricity required. This is a harder subject. If you've ever seen the movie Apollo 13, there one astronaut in Cape Canaveral spends hours trying to optimise a start-up process to draw the least amount of power necessary.

When it comes to optimisation, its a trade off between memory and performance. There's a further tradeoff between whatever is being optimised and the maintainability of the code

2006-10-26 05:48:20 · answer #3 · answered by Isofarro 3 · 0 1

All the straight forward optimizations are well done by the compiler (see manual).

Of course it depends on the logic involved. You have to see if things are done in the best way. This requires a lot of experience to improve.

You could reorganize conditions, use threads for parallel processing, use loops instead of recursivity, find ways to avoid doing the same thing repeatedly, etc.

2006-10-26 04:51:37 · answer #4 · answered by juliepelletier 7 · 0 1

real, the 2d is greater suitable, yet you should use those by way of fact they're plural so it is going like this.. those technologies are regarded international and used for springing up interactive web pages and portals.

2016-10-16 10:36:10 · answer #5 · answered by Anonymous · 0 0

fedest.com, questions and answers