Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Does "== true" slow down the final project?

Contributor ,
Nov 13, 2016 Nov 13, 2016

I know it's nothing in the scheme of things, but anywhere with the expression "== true", that segment of code can be deleted and the program will be executed exactly the same. Does this mean that the program is running slightly slower, because it needs to return true if true? Or is the compiler smarter than that, and ignores "== true" treating it as a comment? I like having "== true" in my project because they help me remember I'm working with a Boolean value, but I will delete them if there is the smallest chance of a slight performance gain.

TOPICS
ActionScript
457
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 13, 2016 Nov 13, 2016

on my computer using fp 24, the first is faster by about 4/10000000 milliseconds.  ie, not very much difference.

Translate
Community Expert ,
Nov 13, 2016 Nov 13, 2016

copy and paste a sample of the line of code you want to test.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 13, 2016 Nov 13, 2016

Typing from my phone, so forgive me if I make a syntax error:

if(true)

{

trace('How fast was that?')

}

vs.

if(true == true)

{

trace('How fast was that?')

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 13, 2016 Nov 13, 2016

on my computer using fp 24, the first is faster by about 4/10000000 milliseconds.  ie, not very much difference.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 13, 2016 Nov 13, 2016

I will never use == true ever again

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 26, 2016 Nov 26, 2016

>>...because they help me remember I'm working with a Boolean value...

Just wanted to mention, if you name your variables properly you won't need help. For booleans using the prefix 'is' can be helpful - and is also somewhat of a convention.

isVisible, isMoving, isDead, etc.

And you can use == true if you want, it is not slower at all. If you test using debug player (ctrl-enter) you might see a small difference when using 10,000,000 iterations - but you will pretty much see no difference if you publish the movie and use the non-debug player.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 26, 2016 Nov 26, 2016
LATEST

Good tip on the "is". I'm just working on this project by myself, so it's not worth the effort of adding it to everything, but I will keep that in mind in future, especially if I ever get accepted onto a team, or have to include a variable in an API.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines