Perform the same operation with c, cs, and vala respectively: Code
# Include <stdlib. h>
# Include <stdio. h>
Int main ()
{
Printf ("c for begin \ n ");
Int count = 1000000000;
Int I;
For (I = 0; I <count; I ++)
{
;
}
Printf ("c for end \ n ");
Printf ("int add begin \ n ");
Int ncount = 1000000000;
Int n = 0;
Int j;
For (j = 0; j <ncount; j ++)
{
Int a = 3;
Int B = 4;
N = a + B;
}
Printf ("% d", n );
Printf ("int add end \ n ");
Printf ("float add begin \ n ");
Int fcount = 10000000;
Float f = 0.0f;
Int k;
For (k = 0; k <fcount; k ++)
{
Float a = 3.0f;
Float B = 4.0f;
F = a + B;
}
Printf ("% f", f );
Printf ("float add end \ n ");
Return 0;
}
Test result: Code
User @ mojo :~ /Projects/performance/c $ time./c
C for begin
C for end
Int add begin
7int add end
Float add begin
7.000000 float add end
Real 0m49. 264 s
User 0m46. 450 s
Sys 0m0. 010 s
User @ mojo :~ /Projects/performance/cs $ time mono main.exe
C for begin
C for end
Int add begin
7
Int add end
Float add begin
7
Float add end
Real 1m37. 252 s
User 1m31. 880 s
Sys 0m0. 135 s
User @ mojo :~ /Projects/performance/vala $ time./main
C for begin
C for end
Int add begin
7int add end
Float add begin
7.000000 float add end
Real 1m14. 979 s
User 1m10. 995 s
Sys 0m0. 020 s
Ps: all of the above tests were completed on SmartQ5 (cpu: cloud6410 arm11 667 MHz, ram: 128 M), and python and lua were also tested. The conclusion is basically incomparable, crash status.
/Files/zhongzf/src.zip