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

Author Topic: sfml tcp socket performance  (Read 1824 times)

0 Members and 1 Guest are viewing this topic.

kaki2308

  • Newbie
  • *
  • Posts: 2
    • View Profile
sfml tcp socket performance
« on: December 15, 2014, 11:52:56 pm »
Hello

I was wondering what will be faster:
int length = 200;
char* data = new char[length];
... filling ...
socket->send(data, length);
delete[] data;

VS
int length = 10;
char* data = new char[length];

for(int i = 0; i < 20; i++)
{
   ... filling ...
   socket->send(data, length);
}
delete[] data;

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: sfml tcp socket performance
« Reply #1 on: December 16, 2014, 12:49:05 am »
I doubt 200 bytes is big enough for any micro-optimizations like this to matter; allocating your buffer on the stack (without new/delete) rather than the heap will probably make a bigger difference than whether or not you "batch" the requests like this.  Prefer the version with one request solely because it makes things simpler (for you and for the socket).

In general, the answer is almost certainly "depends on the network/data/traffic/etc".  Your best bet is to simply test and see if you actually notice a meaningful difference.  TCP in particular is already designed try and send things at the optimal rate given your current network conditions, so there's no point trying to "help" it with that.

Even more generally: Don't try to optimize until you're having an actual performance problem, and you've identified what the problem is with a profiler rather than guessing.  Otherwise you're likely to waste a lot of time on things that don't really help.
« Last Edit: December 16, 2014, 01:03:50 am by Ixrec »