Is that with or without the printf statements at the end?
Also, does that time include the time it takes the OS to load your program, and then for the C runtime system to initialise itself before it even gets to calling main?
Also, does that time include any time spent inside interrupt service routines which may happen while your program is running?
Also, did you make use of any compiler optimisation flags?
How about compiling it with more warnings?
Code:
$ gcc -Wall foo.c
foo.c: In function ‘main’:
foo.c:11:17: warning: missing braces around initializer [-Wmissing-braces]
int H[4][6] = { 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1 };
^
foo.c:11:17: note: (near initialization for ‘H’)
foo.c:10:7: warning: variable ‘E’ set but not used [-Wunused-but-set-variable]
int E[4][6] = { 0 };
^
foo.c:6:7: warning: unused variable ‘y’ [-Wunused-variable]
int y[6] = { 0 };
^
foo.c:5:13: warning: variable ‘c’ set but not used [-Wunused-but-set-variable]
int n, r, c, no_e, S;
^
That E thing is a killer for you.
There's a whole bunch of code dedicated to setting E which serves no purpose whatsoever.
Code:
#include <stdio.h>
int main()
{
int n, r, no_e, S;
//!!int y[6] = { 0 };
int i, j, pos, I;
int Imax = 20;
//!!int E[4][6] = { 0 };
int H[4][6] = {
{ 1, 1, 0, 1, 0, 0 },
{ 0, 1, 1, 0, 1, 0 },
{ 1, 0, 0, 0, 1, 1 },
{ 0, 0, 1, 1, 0, 1 },
};
int M[6] = { 0, 0, 1, -1, -1, -1 };
n = 6;
r = 4;
//!! c = 6;
//Decoding using Message passing in Erasure channel
no_e = 0;
S = 0;
pos = 0;
I = 0;
for (j = 0; j < r && I < Imax; j++) {
for (i = 0; i < n; i++) {
if (H[j][i] == 1) {
if (M[i] < 0) {
no_e = no_e + 1;
pos = i; //The position of erasure bit
}
if (M[i] == 0 || M[i] == 1)
S = S + M[i];
}
}
//!! if (no_e > 1)
//!! for (i = 0; i < n; i++)
//!! E[I][i] = -1; //Make the entire jth row -1
//!! else
//!! for (i = 0; i < n; i++)
//!! E[I][i] = M[i];
if (no_e == 1) {
//!! E[I][pos] = S % 2; // Set the bit with the correct value
M[pos] = S % 2; //Replace the bit with the corrected
}
no_e = 0;
S = 0;
for (i = 0; i < n; i++)
if (M[i] < 0)
no_e = no_e + 1;
if (no_e == 0)
break;
I = I + 1;
no_e = 0;
if (j == r - 1)
j = 0;
}
printf("\n\n\nThe corrected Code Word is(%d): \n\n", I);
for (i = 0; i < n; i++)
printf("%d\t", M[i]);
printf("\n");
}
And still, you fail to provide details of your ALGORITHM. The single useful comment in your code suggests you're up to something to do with error detection and recovery.
Erasure channel - Wikipedia
It's like if you implemented bubble sort, then the best we could come up with is a slightly better bubble sort. But the real answer would be to throw the code away and implement quicksort.