Jump to content
  • Advertisement
Sign in to follow this  
martyj2009

New fast way to loop!

This topic is 865 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

So there's the for loop. Which works great for most of our programming needs. What if there was a way to speed this up by up to HALF.

 

Well there is, it's called a five loop.

 

See below the code example.

// Change this to decide which loop to use!
#define FIVE 0

#if FIVE
#define five for
#endif

#include <time.h>
#include <stdio.h>

int main(int argc, const char *argv[])
{
	int loops = 10000000000;
	int a, b;

	clock_t start, end;
	start = clock();

#if FIVE
	five(int i = 0; i < loops; i++)
#else
	for (int i = 0; i < loops; i++)
#endif
	{
		int a = i;
		b = a * 3;
	}
	
	end = clock();

	double seconds = double(end - start) / CLOCKS_PER_SEC;
	printf("Time Diff: %f", seconds);

	getchar();
}

I know some of you may be doubtful, but the proof is in the pudding.

 

The for loop results:

QlfMuNz.png

 

Now compare that to the Five loop

 

Vw3o2Ix.png

 

 

Forget Moore's law. We can't rely on chip manufactures to keep up with our software needs. Five loop is here to save the day!

 

 

Share this post


Link to post
Share on other sites
Advertisement

Sorry, the latest news today is that "five loops" are obsolete tech:

 

#define six for

Share this post


Link to post
Share on other sites

This is even faster, guarantee:

#define magic(loopstuff) loopstuff; if(0)

just ignore the compiler warnings about statements with no effect, the compiler just can't handle my magic loops.

It's so fast you'll wonder if your loop is even running at all :)

Edited by nfries88

Share this post


Link to post
Share on other sites

Are we really using .h headings?

You can save some time there.

Edited by Mats1

Share this post


Link to post
Share on other sites

Wait, can someone explain what is going on or am I missing a big joke here?


You need to actually try the five loop and then you'll understand. Five loop is all... Five loop is life :lol:

Share this post


Link to post
Share on other sites

int loops = 10000000000;
lol  edit: did I ruin the game?

Nah, this is just premature optimisation :lol:

The compiler should do that... :P

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!