Jump to content
  • Advertisement
Sign in to follow this  
Ben091986

Performance std::Vector Iterator vs integer

This topic is 3771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi folks, is an iterator faster than an integer? I have an vector with about 300 elements and a little loop every frame. so i coded two versions iterator vs integer, and integer was very much faster. did i make something wrong ?? Maybe i missed some optimization for the iterator or so... They are both completly equal beside the fact, that the first version is faster
//prtcl is a vector<T>
//size of vector 300

//version one 350 FPS
	for(int i = 0;i< maxPart_U;i++)
	{	
		if((*prtcl).time < 0)
		{
			if(run_U)
			{
			
				if(spawnCounter_U > spawnTime_U)
				{
					spawnCounter_U-= spawnTime_U;
					(*prtcl)    = updateCreateParticle(dt);	
				}
				else	 (*prtcl).col = D3DCOLOR_COLORVALUE(0,0,0,0);
			}
			else
			{
				(*prtcl).col = D3DCOLOR_COLORVALUE(0,0,0,0);
			}
			
		}
		else
		{
			effectChangeParticle((*prtcl),dt);
		}
		
	}

//version 2 280FPS
	for(vector<T>::iterator it = prtcl->begin();it != prtcl->end();it++)
	{	
		if((*it).time < 0)
		{
			if(run_U)
			{
			
				if(spawnCounter_U > spawnTime_U)
				{
					spawnCounter_U-= spawnTime_U;
					(*it)    = updateCreateParticle(dt);	
				}
				else	  (*it).col = D3DCOLOR_COLORVALUE(0,0,0,0);
			}
			else
			{
				(*it).col = D3DCOLOR_COLORVALUE(0,0,0,0);
			}
			
		}
		else
		{
			effectChangeParticle((*it),dt);
		}
		
	}

Share this post


Link to post
Share on other sites
Advertisement
Are you timing debug or release mode? Are you using MSVC or another STL implementation with runtime iterator checks?

Share this post


Link to post
Share on other sites
Using VC++ you'll have to define _SECURE_SCL 0 before including the standard headers to disable checked iterators even in a release build.

PS: Profiling for performance in debug mode is pretty much useless.

Share this post


Link to post
Share on other sites
In release mode they are both equal. 530 FPS

_SECURE_SCL 0 doesnt seem to work... it makes no difference

(i defined it before anything else!!)

Share this post


Link to post
Share on other sites
Disabling secure iterator checking only helps if you have a very tight loop with very little branching. Looking at your code you do plenty of branching already so I doubt disabling them will speed anything up.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ben091986
In release mode they are both equal. 530 FPS

The iterator is probably fractionally faster but you're unlikely to notice the difference when you're measuring frames per second as an integer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!