place help: When you are programming, does the program run faster if you - Help.com

When you are programming, does the program run faster

if you type every instance of a constant in its place, or dimension the constant as a variable and type the variable in its place?

This open post was written 1 year ago | V/U/S: 80, 13, 2 | Edit Post | Leave a reply | Report Post


Reciprocity (2) Many thank yous! The poster has helped others since their own post was made.

Since writing this post M. Wright has helped in 2 other users' posts within the last 4 days. M. Wright is a verified member, has been around for 1 year, 2 months and has 162 posts and 5,651 replies to their name.

Post Tags (8)

Replies (13)

Where were you?

Click and drag to move the map around. FAQ: How we place people on this map »
You can also watch events on Help.com as they happen
Mouse over the map for 2 seconds to see an expanded, interactive view

Ed23454 offline Unverified User #
An Unknown Location | 1 year ago (6 minutes after post)

I’m not completely sure, but I think instance of a constant in its place. This is becuse it dosn’t have to acess the programs alloacted space for random memory storage and withdrawl the variable. Either way, it only makes less than a millisecond diference. It is impossiable to see, in simple programs anyway.

But you can’t really go by me, becuse I am just a beginner programmer in C++, .NET, and Java.

Quote this reply Report this reply to moderators
This account has been deactivated.
Ed23454 offline Unverified User #
An Unknown Location | 1 year ago (8 minutes after post)

Awsome…lol

Quote this reply Report this reply to moderators
This account has been deactivated.
M. Wright offline Verified User (1 year, 2 months) Long Term User Shouts: 4 #
An Unknown Location | 1 year ago (8 minutes after post)

Somewhere in the future I am planning on writing a large program, and every bit of speed will matter. Right now I will use the variable because it is a long constant and just a small program.

Quote this reply Report this reply to moderators
Ed23454 offline Unverified User #
An Unknown Location | 1 year ago (10 minutes after post)

Yeah. If you are programming in C++ you can use a marco, so you can save time typing out.

You write with the other global declarations:

#define x2 = 2743345734.34538

somthing like that….I don’t think the format is right…
But thats only good for C++ anyway.

Quote this reply Report this reply to moderators
This account has been deactivated.
M. Wright offline Verified User (1 year, 2 months) Long Term User Shouts: 4 #
An Unknown Location | 1 year ago (11 minutes after post)

Macros. I heard about those.

Quote this reply Report this reply to moderators
Ed23454 offline Unverified User #
An Unknown Location | 1 year ago (12 minutes after post)

yeah…

than when you type out x2 the compiler changes it to the number.

Java and other languages might have them too…. what language is it in?

Quote this reply Report this reply to moderators
This account has been deactivated.
M. Wright offline Verified User (1 year, 2 months) Long Term User Shouts: 4 #
An Unknown Location | 1 year ago (13 minutes after post)

I’m learning Perl, Fortran, and Assembly just to learn about them. I know assembly has macros, but I’m not sure about the others.

Quote this reply Report this reply to moderators
Ed23454 offline Unverified User #
An Unknown Location | 1 year ago (15 minutes after post)

okay…. I don’t know those languages.

In C++, (I just looked ‘em up in my C++ Book =D)
they are written

#define var3 37474.343475

so whenever you type var3 it really means 37474.336….

It is prabely simular in those languages

Quote this reply Report this reply to moderators
This account has been deactivated.
Ed23454 offline Unverified User #
An Unknown Location | 1 year ago (17 minutes after post)

Goodluck with whatever it is =D

Quote this reply Report this reply to moderators
This account has been deactivated.
spiratec9 offline Verified User (1 year, 9 months) Long Term User Shouts: 5 #
Burnaby, BC, CA | 1 year ago (1 hour, 1 minute after post)

it won’t make any difference because the compiler will substitute
the variable in for you.

Quote this reply Report this reply to moderators
Ed23454 offline Unverified User #
An Unknown Location | 1 year ago (1 hour, 11 minutes after post)

spiratec9 wrote:
it won’t make any difference because the compiler will substitute
the variable in for you.

Only if the variable is defined as constant. If it is a changing variable than it couldn’t be replaced by the compiler, it would be constant than.

Marcos & Constants can be used to make the compiler subsitute, however vairables, are variant.

Quote this reply Report this reply to moderators
This account has been deactivated.

Invite Others to Help

A logged in and verified Help.com member has the ability to setup a Friends List and invite others to help with posts.