I have some problems explaining the difference in running time:
plain lua: 4.061s
luajit 2.0.0 beta 8: 0.076s
gcc -O3: 1.480s
Can onyone shed some light on why the C implementation is more then 20 (!) times
slower then the luajit version ?
I'm testing on a Intel Core 2 Duo CPU @ 2.20GHz. Could this be some kind of
architectural issue ?
-- test.lua ----------------------------------------------------------
local N = 4000
local S = 1000
local t = {}
for i = 0, N do
t[i] = {
a = 0,
b = 1,
f = i * 0.25
}
end
for j = 0, S-1 do
for i = 0, N-1 do
t[i].a = t[i].a + t[i].b * t[i].f
t[i].b = t[i].b - t[i].a * t[i].f
end
print(string.format("%.6f", t[1].a))
end
-- test.c ------------------------------------------------------------
#include<stdio.h>
#define N 4000
#define S 1000
struct t {
double a, b, f;
};
int main(int argc, char **argv)
{
int i, j;
struct t t[N];
for(i=0; i<N; i++) {
t[i].a = 0;
t[i].b = 1;
t[i].f = i * 0.25;
};
for(j=0; j<S; j++) {
for(i=0; i<N; i++) {
t[i].a += t[i].b * t[i].f;
t[i].b -= t[i].a * t[i].f;
}
printf("%.6f\n", t[1].a);
}
return 0;
}