-
Optimization stuff
This post is aimed at anyone looking for optimization techniques. I am planning on making some other optimization programs, but for now I'll just upload the one that I have done.
The method I am going to show is to prove how much faster it is to use a for loop with strlen precalculated BEFORE the loop.
Many programs have the loop look something like this:
for(int a=0;a<strlen(someString);a++)
and a lot of people put that code in to their program without realizing how much of a bottleneck it is. Most people who have been programming for a while will/should hopefully notice this at some point or another, that's why I'm aiming this post more at beginners.
So anyways, I made a program that basically shows how much faster it is to preprocess the length of the string beforehand. I get about a 140x increase in speed when i use the precalculated method.
And again, I am aiming this post at anyone who is either new to programming and looking towards optimizations or even people who might have just overlooked this. I understand that this is an extremely simple program, so please don't start a flame war over it or something
-
It can also be applied to any other situation where a function is called a number of times, with the same result being returned each time. Also, mathematical calculations done within a loop could be done before hand instead.
-
Wow
Thks for the info. I am a noob so this is good to know. I ran the program and saw the diff. :eek: