speeding up the code

Please, can anyone give some ideas about speeding up a C-code?
dont declare variables in any loop,
that is a couse of slowing up the process
Last edited on
@SteakRider:
Do you have any references or have you done any experiments to support this claim? I have to say I seriously doubt it.
I am not sure what you mean by speeding up the code, do you mean speeding up the process of compilation? or speeding up the process of execution? And when you say speed up, do you mean making it more efficient?
@ropez
i dont have any references about it right now, but i had some,
try to search on codeproject.com.

Run this code, then you will make sure that i was right@

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <stdlib.h>
#include <time.h>


int main()
{
	time_t begin, end;
	long ii,jj,mm,aa,bb,cc,dd;


	begin = time(NULL);
	for (long i =0;i<10000; i++)
		for (long j =0;j<10000; j++)
			for (long m =0;m<10000; m++)
			{
				long a,b,c,d;
				a = b = c = d = 0;
			}
	end = time(NULL);

	printf("\nIn loop: Pracess TIME: %d",end - begin);


	begin = time(NULL);

	for (ii =0;ii<10000; ii++)
		for (jj =0;jj<10000; jj++)
			for (mm =0;mm<10000; mm++)
			{
				aa = bb = cc = dd = 0;
			}
			end = time(NULL);

	printf("\nOut loop: Pracess TIME: %d",end - begin);                                    

	getchar();
}

Last edited on
closed account (z05DSL3A)

On a release build (with the loop set to 100000000000000000):
1
2
In loop: Pracess TIME: 0
Out loop: Pracess TIME: 0


@Grey Wolf

Then try it with debug build;)
Last edited on
Topic archived. No new replies allowed.