Copy link to clipboard
Copied
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.
on my computer using fp 24, the first is faster by about 4/10000000 milliseconds. ie, not very much difference.
Copy link to clipboard
Copied
copy and paste a sample of the line of code you want to test.
Copy link to clipboard
Copied
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?')
}
Copy link to clipboard
Copied
on my computer using fp 24, the first is faster by about 4/10000000 milliseconds. ie, not very much difference.
Copy link to clipboard
Copied
I will never use == true ever again
Copy link to clipboard
Copied
>>...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.
Copy link to clipboard
Copied
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.