About writing optimized code.

Joined
Apr 6, 2023
Messages
21
Reaction score
0
Hello everyone!
I want to know about how we can write optimized code that is, code which has less time complexity ? Is there any method or way which we should follow while writing code to make our code optimized? I look forward to suggestions or resources about this.
Thank you.
 
Joined
Sep 4, 2022
Messages
129
Reaction score
16
have you got any idea about a quick answer from you ?

Which language are you coding with ?
 
Joined
Apr 6, 2023
Messages
21
Reaction score
0
I was writing code in C++. I wanted to know how can we make any code in C++ optimized that is, it can execute with less space and time.
 
Joined
Sep 4, 2022
Messages
129
Reaction score
16
It's some 'rules' look alike :

[ Structure ]
  • if you have two times ( or more ) the same code patterns, it could be relevant to write a function, then use it two times.
  • count all vars 'alive', do you need every same vars, or one could be used several times.

[ Knowledge Requirement ]

- use the language at its best, you have to deeply know it ( for you C++ : pointer , reference address, Class design ). Mastering a language is a kind of starting point, become an expert.

[ Self Improvement ]

- mind your code, read it again and again, criticize your code. by a visible default in the code : fix it in the minute coming.

[ Memory Management ]

- free your vars when they are unused. [ object / Array / high level container / var ]

[ Optimistic Code Design ]

- give up with processing all cases could happen in a code, go straight to it.
Beginners try functions and syntax, but your code change with the all years of work.
you will see that 'beginners' write too much code.

[ self-control and career ]
  • your code style and quality will change across the years ( with lot of work ), remind how hard was your first lines of code.
  • congrats yourself and your workmates.

[ Code Status ]
  • compare methods, and code; and choose the fast one : recursion is faster than a classic loop, pointer using is one speed upto a common coding ( C++ / C )
  • identify a low speed code, aside a fast speed code, make the difference between those two.

[ ASM ]

- ASM make CPU working better, always learn ASM. Codes are more light.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,283
Latest member
JoannaGrif

Latest Threads

Top