New fast way to loop!

Started by
11 comments, last by Dawoodoz 7 years, 10 months ago

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!

Advertisement

What if you define five to "ThreadedAsixcronous"?

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

#define six for

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 :)

Are we really using .h headings?

You can save some time there.

I get the same results.
It is confirmed that if you run the for-loop in debug mode and you run the five-loop in release mode you get these results.
Five-loop certainly wins in all cases.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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

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:

int loops = 10000000000;

lol

edit: did I ruin the game?

"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/

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

Nah, this is just premature optimisation :lol:

The compiler should do that... :P

This topic is closed to new replies.

Advertisement