Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 210305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:59:36+00:00 2026-05-11T17:59:36+00:00

Q1. What are best practices for a writing a code that does not consume

  • 0

Q1. What are best practices for a writing a code that does not consume CPU but still achieve a great performance? The question is very generic. What I seek over here is to list down different practices used for different environments? debugging tips besides process-monitor/task manager

EDIT:
I am not speaking of IO bound processes. I am speaking of CPU bound process. But, here I do not want my process to keep on hogging CPU.
If i have a 4 core machines and if i run four simple loops within a process, the CPU consumption shoots up to 400% till the application/process is running.

I am seeking here some experience on the topic which everyone would have faced some time or other. e.g. I debugged once an application was hogging CPU on Windows as it was looping continuously to search for a non-existent file.

How can I write my program in a way that two different CPU bound applications run smoothly (give a good response)?

UPDATE:
Suggestions:

  1. Write good clean code, then Profile your application and then optimize. (Thanks ted for the tip)

  2. It is easier to rewrite/redesign/refactor code than profiling and fixing it.

  3. Use a profiler to debug your application

  4. Don’t use spinlocks for threads with long waits

  5. Algorithm choice

These suggestions go a long way for the beginner to understand the concepts.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:59:36+00:00Added an answer on May 11, 2026 at 5:59 pm

    First, write good clean code. Do things the simplest way possible.
    After that, do the following repeatedly until you are satisfied with speed of the program:

    1. Profile its execution.
    2. Find the parts where it is spending the most time.
    3. Speed up those parts.

    Do not fall into the trap of perverting your code up front in the name of optimization.

    Remember Amdhal’s Law. You aren’t going to get noticeable improvements by speeding up something that is already only consuming 1% of your program’s time. You get the best bang for your optimization buck by speeding up the part your program spends the most of its time doing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When writing a custom server, what are the best practices or techniques to determine
What best practices should be observed when implementing HDL code? What are the commonalities
What is the best practice for writing a rather large wcf service, containing a
What are the best practices to consider when catching exceptions and re-throwing them? I
What are the best practices around creating flat file database structures in PHP? A
What are the best practices for checking in BIN directories in a collaborative development
What's are the best practices for versioning web sites? Which revision control systems are
I am looking for best practices for detecting and preventing DOS in the service
Are there any best practices (or even standards) to store addresses in a consistent
What are the best practices for using Java's @Override annotation and why? It seems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.