SFML community forums

Help => General => Topic started by: Daniel Schreiber Mendes on July 29, 2019, 05:12:53 pm

Title: Should I use Vector2f or short int in terms of performance?
Post by: Daniel Schreiber Mendes on July 29, 2019, 05:12:53 pm
Hello guys, I was wondering whether I should use Vector2f or short int as member variable types. Short int makes it easier to understand the use of the variable, but then I have to convert them all the time when I call functions of the SFML library. Vector2f seems to be a pretty big type which I think can lead to a worse performance than short int but I don't have to convert them.  In terms of performance, which one should I use?
Title: Re: Should I use Vector2f or short int in terms of performance?
Post by: G. on July 29, 2019, 05:28:26 pm
Vector2f isn't a big thing, it's only a class with 2 float member variables and some operator overloads.
It's highly unlikely to cause you worse performance.
Title: Re: Should I use Vector2f or short int in terms of performance?
Post by: Daniel Schreiber Mendes on July 29, 2019, 05:36:19 pm
Alright, thanks!
Title: Re: Should I use Vector2f or short int in terms of performance?
Post by: Nexus on July 29, 2019, 10:20:36 pm
sf::Vector2f and short are two conceptually different things. One is a 2D vector, the other a scalar integer.

So it highly depends what your member variables represent. From what you're writing, it seems like sf::Vector2f fits perfectly and short int would be a workaround. You won't gain any performance by doing so -- so make your program simple and optimize when you get stuck. Micro-optimization at this scale are a bad idea, unless you know exactly what you're doing and why one choice would be faster than another. Also, speaking about speed in terms of types doesn't make sense -- it's operations that take time, not types.
Title: Re: Should I use Vector2f or short int in terms of performance?
Post by: Daniel Schreiber Mendes on September 01, 2019, 11:34:28 pm
Okay, I'll keep that in mind