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

  • Home
  • SEARCH
  • 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 8805517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:53:17+00:00 2026-06-14T01:53:17+00:00

How do the following two blocks of pseudo-code compare in terms of speed for

  • 0

How do the following two blocks of pseudo-code compare in terms of speed for both compiled languages and interpreted languages? (Ignoring number of digits)

Essentially, is there any performance loss by writing variables as a function of several constants, rather than computing beforehand? This often makes code more clear.

permanentNum = (3.1416 / 3) + 1.5708
return permanentNumber / userInputNumber

.

permanentNum = 2.6179
return permanentNumber / userInputNumber

Thanks!

  • 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-06-14T01:53:18+00:00Added an answer on June 14, 2026 at 1:53 am

    Mitch Wheat’s comment is absolutely correct; optimization is something to do after you have clear and correct code, and only when necessary.

    To answer the question, though, it obviously depends on the language. Any decent compiler for the C-like languages has a constant-folding optimization pass. On GCC, or Oracle’s javac, or any widely used compiler, your two examples will generate the same code.

    Interpreted languages are likely slow enough that the cost of a few extra arithmetic operations is not your bottleneck, whether it does constant-folding at parse time or not. 🙂

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

Sidebar

Related Questions

Is there a difference between the following two code blocks in terms of the
I have the following two code blocks. Code block 1 var checkboxes = $(div.c1
In terms of garbage collection within Java (any version) are these two code blocks
Consider the following two blocks of Java psedo-code in a system that uses optimistic
The following two lines of code load an image from an SVG file and
I have the following two chunks of code, I am not so sure what
I have the following test, with two almost identical blocks. Now i am looking
Given the following two blocks of HTML markup: <div style=overflow:auto; line-height:22px;> <div style=float:left; display:inline;>Write</div>
I have a problem with the following blocks of code. I cannot have them
Is there a logical difference between the following two blocks? And is there one

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.