Loop count = 1,000,000
Normal variable time : slightly higher Register variable time: slightly lower
#include <stdio.h>
#include <time.h>
int main() {
int i;
int normal = 0;
register int reg = 0;
clock_t start, end;
double time_normal, time_register;
/* ---- Normal variable loop ---- */
start = clock();
for (i = 0; i < 1000000; i++) {
normal++;
}
end = clock();
time_normal = (double)(end - start) / CLOCKS_PER_SEC;
/* ---- Register variable loop ---- */
start = clock();
for (i = 0; i < 1000000; i++) {
reg++;
}
end = clock();
time_register = (double)(end - start) / CLOCKS_PER_SEC;
printf("Normal variable value = %dn", normal);
printf("Register variable value = %dnn", reg);
printf("Time taken by normal variable = %f secondsn", time_normal);
printf("Time taken by register variable = %f secondsn", time_register);
return 0;
}
#include <stdio.h>
#include <time.h>
int main() {
int i;
int normal = 0;
register int reg = 0;
clock_t start, end;
double time_normal, time_register;
/* ---- Normal variable loop ---- */
start = clock();
for (i = 0; i < 1000000; i++) {
normal++;
}
end = clock();
time_normal = (double)(end - start) / CLOCKS_PER_SEC;
/* ---- Register variable loop ---- */
start = clock();
for (i = 0; i < 1000000; i++) {
reg++;
}
end = clock();
time_register = (double)(end - start) / CLOCKS_PER_SEC;
printf("Normal variable value = %dn", normal);
printf("Register variable value = %dnn", reg);
printf("Time taken by normal variable = %f secondsn", time_normal);
printf("Time taken by register variable = %f secondsn", time_register);
return 0;
}