Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Should I use Vector2f or short int in terms of performance?  (Read 2044 times)

0 Members and 1 Guest are viewing this topic.

Daniel Schreiber Mendes

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
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?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Should I use Vector2f or short int in terms of performance?
« Reply #1 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.

Daniel Schreiber Mendes

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Should I use Vector2f or short int in terms of performance?
« Reply #2 on: July 29, 2019, 05:36:19 pm »
Alright, thanks!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Should I use Vector2f or short int in terms of performance?
« Reply #3 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Daniel Schreiber Mendes

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Should I use Vector2f or short int in terms of performance?
« Reply #4 on: September 01, 2019, 11:34:28 pm »
Okay, I'll keep that in mind

 

anything