- Back "Cross-platform away": .net vs. java on linux "
.NET test program
Using system;
Namespace consoleapplication7 {class test {static void main (string [] args) {int TEMP = 1; datetime a = datetime.now; for (int i = 1; i <= 1000000000; i ) {TEMP = i;} DateTime B = datetime.now; timespan c = b - a;
Console.writeline (C. TotalmilliseConds); console.writeLine (TEMP);}}}
Java test program
Public class my
{Public static void main (string args [])
{
Long a, b;
INT TEMP = 1;
a = system.currenttimemillis ();
For (int i = 1; i <= 1000000000; i ) {TEMP = I;}
B = system.currenttimemillis ();
System.out.println (B - a); System.out.Println (TEMP);
}
}
Test results DOT: 2437 Java (-HOTSPOT): 59796 Java (-server): 375
(I am in JDK1.4.0_01, basically comes from JDK1.3.1. Someone gets 0 results in JDK1.4.0, because there is no system.out.println (TEMP), the calculation process is optimized)
The second test, I will change the TEMP = I above the program to TEMP * = i, the result is as follows:
DOT NET: 10234 Java (-HOTSPOT): 21109 Java (-classic): 59984 Java (-server): 9625
What does these results mean, I don't want to say more.
The same calculation results in Delphi 6:
Add: 1514 Method: 9797
Delphi program program my;
{$ Apptype console}
Uses sysutils, dateutils;
VAR I, TEMP: Integer; B, E: TdateTime; Begin B: = NOW (); for i: = 1 to 1000000000 DO TEMP: = Temp * i; E: = NOW (); Writeln (MilliseCondsbetWeen (B, E ));
The same calculation results in C : VC7.0 addition: 1390 Method: 10281 BCB6.0 addition: 1422 Method: 9641C program #include
INT Main (int Argc, char * argv []) {Int b, e; int TEMP = 1; b = gettickcount ();
For (int i = 1; i <= 1000000000; i ) {TEMP = I;}
E = gettickcount (); Printf ("% d", e-b); Printf ("/ n% D", TEMP);
Return 0;}
(Note: All the above procedures are release version, speed optimization)
2. What is the compilation result of Java under Linux and Windows? I didn't install Linux, can't compare whether the compile results of the two platforms were different, but I believe that this result is reason, but I am hard to believe is due to platform issues. I don't know if the author checks if the version of JDK on both platforms is consistent.