Jump to content

[SOLVED] vector slow performance


photo

Recommended Posts

Posted

we found vector is slow in unigine script.

 

in init() put a 5000 items in vector

forloop(int i=0;5000)
  vvtest.append(i);

 

in update() try find a number not exist and loop 300 times per update`

 

forloop(int i=0;300)
  int xx=vvtest.find(-1);

 

on my computer it takes around 10ms for each update.

is there any way to optimize the performance?

thanks

 

Posted

Hi, 

 

Unfortunately, this is not a vector issue. Unigine script stores data types in Variable class, and by obvious reasons it's operator== is not as fast as comparing pod types in c++. I suggest you to use a map in such cases. If this is impossible, you can optimize Variable::operator== in engine for needed data type, for example for integers add: 

int Variable::operator==(const Variable &v) const
{
	if (type == 0 && v.type == 0)
		return (VARIABLE_INT_V == V_VARIABLE_INT_V);
        ... 

This speeds up your example by 2.5 times on my machine, but will slow down cases for other data types a bit.

Posted

Hi, 

 

Unfortunately, this is not a vector issue. Unigine script stores data types in Variable class, and by obvious reasons it's operator== is not as fast as comparing pod types in c++. I suggest you to use a map in such cases. If this is impossible, you can optimize Variable::operator== in engine for needed data type, for example for integers add: 

int Variable::operator==(const Variable &v) const
{
	if (type == 0 && v.type == 0)
		return (VARIABLE_INT_V == V_VARIABLE_INT_V);
        ... 

This speeds up your example by 2.5 times on my machine, but will slow down cases for other data types a bit.

thanks Maxi. we will give a try.

  • silent changed the title to [SOLVED] vector slow performance
×
×
  • Create New...