Cross-platform away: .NET vs. Java on Linux

xiaoxiao2021-03-06  65

Since.NET launched, .NET and Java have never stopped, but the battle has always been limited to the theoretical level, and there is only one pile of straightforward, and the saliva is drowned. But but never didn't have a real gun. why? The reason is .NET has not come out at home, and you will not go. They have no chance to truly touch.

But now they have finally have a chance to truly conduct a fair competition. A period of starting. Net open source program Mono has just launched the latest version 0.13, although it is still a development product, but I have already been tolerant I have to take her out and Java has passed.

Before the boring data is compared before, please see a romantic story first, learn about the relationship between .NET, MONO, thank you. :)

It is said that it is very java, although Java is going to find a few tricks in the door. Net is more popular, but the father of .Net is very unwelcome, and it is not better than win. Java is very angry: "What is nothing, isn't it more than I am young? The old lady is not born when the old lady is in the scenery, only in the family, I am still more than you, there is a kind! ".

This is very proud of this side: "Let's see, what is the big beauty. Net is a big beauty, and even the passengers don't see it. Most of them are stupid, and they are not clear. See how much Java, people People love, get a kitchen in the hall, let her go, and half of the sentence. "

This is the answer to the answer: "Who said that our home .NET can't? She not only has a famous door, the national color, and can understand the language of almost all countries, I also specially invite the woven master Anders to our home. I specially teach her embroidery. But she is a big show, I can run around the wild girl with your home, no one can touch it. Let's talk, most of the land belongs to our home, she can't go out, it is true. same."

Although the .NET is well received, someone is serving every day, but often sighs in the mirror: "Hey, we blame my father, limit people's freedom, although we can wear clothes every day, but only our people can see me, I All people in the world want to admire my beauty, let all the people tell me in different languages: 'I love you'. "

One day by .Net, he was heard by a handsome young man, he was developed Ximian, a famous X-Windows system gnome under Linux. He first saw that .Net was deeply impressed by her beauty. He said to someone to him: "I finally discovered that she is really what I really want." He also found that .NET is the only one in the Microsoft family wants to go out. So he told her a good story that happened there, saying that there were a lot of hard work, there was no level, there was no exploitation, everyone did not exploit, everyone's selfless contribution to your labor results Let everyone share together . It consciously abides by the equality of the equality of their own, the country of prosperity is Linux.

"Ah? Linux!". Net surprised, "I know! My father said that there is a bad guy, there is very poor people, they don't know how to make money, and only think about how to attack every day Plundered others' homes, I have always been to disassemble our home, and I have to take all our things! "

"Those who are not really" Ximian said: "I can take you to see, beautiful lady, you will be touched by their hard work and great gain."

"Really?" Net beautiful big eyes flashed forward and curious, and then firmly said: "I must go there, even if my father is not allowed, I must go!". That night, .NET offers noble Chinese suit, replaced the rough cloth, and starts with Ximian.

At this time, I didn't actually look at the eyes, but he didn't stop Ximian. He sighed: "Go, the child, after all, you will be the biggest glory of our family." ". At the same time, his mouth flashed a smile that is not easy to be perceived, and savvy is what is thinking about this moment?

The story is still developing, and now there is still no ending, .NET renamed Mono in the Linux country, she learned from the most basic beginning, slowly adapted Linux life, one year passed, Mono finally launched The latest version 0.13, in this release, we have seen many important progress, slowly start showing .NET talents and beauty.

Below, we have to do some tests, see if .NET is really adapted to Linux's life, and how much gap is that it is mainly comparable to it, and we also invited Java, as a friendship, she just provides some reference. Sex test data. Of course, this is not a very formal game with Java, it is a bit difficult for MONO. After all, Mono is just a product being developed.

First, let's carry out a loop test, and the loop test is accused of simply, and it is not very good to reflect the real operating environment, but its advantages are also simple, because the program is more complicated, the more writing, the more, The focus of the debate has become how to optimize the program, such as the famous pet store war. At the same time, because there is a very famous test, it is a JSP cycle speed test. The result is that JSP is 7 seconds, and the ASP and PHP are more than 80 seconds. It is a long time by Java lovers, I used it. ASP.NET test is 2 seconds, of course, the operating system environment is different, does not have too much reference value. Also after.

Below is a program for testing, the main function is to perform billion cycles, and there is an additional operation and an assignment operation in the loop. The hardware test environment is: P3-M 1.2G, 512M, 30G (laptop). Software test environment: mono 0.13 for Linux, mono 0.13 for windows, .NET Framework SDK 1.0.3705 (Chinese version), J2SE 1.4.0_01 for Linux, J2SE 1.4.0_01 for Windows, Windows operating system: Windows XP Chinese version The Linux operating system is: Mandrake Linux 8.2. The compilation mode uses the default option. The result of the output is the time required to run, in milliseconds.

The following is the C # program code of the test program:

Using system;

Class test

{

?????? static void main (String [] args

?????? {

?????? ?????? int TEMP;

?????? ?????? datetime a = datetime.now;

?????? ?????? for (int i = 0; I <1000000000; i )

????????????? {

??????????????????? TEMP = 1 1;

?????????????}

?????? ?????? datetime b = datetime.now;

?????? ?????? Timespan c = b - a;

?????? ?????? console.writeline (C. TotalmilliseConds);

??????}

}

The following is the corresponding Java program code:

Import java.util.date;

Public Class Test

{

?????? public static void main (String args [])

?????? {

?????? ?????? Date Before = new date ();

?????? ?????? long a, b;

?????? ?????? int TEMP;

????????????? a = before.gettime ();

?????? ?????? for (int i = 0; I <1000000000; i )

????????????? {

??????????????????? TEMP = 1 1;

?????????????}

?????? ?????? Date after = new date ();

????????????? b = after.getime ();

?????? ?????? system.out.println (b - a);

??????}

}

?

Since Mono has a compiler and execution environment, then we should test and compare compilers and execution environments respectively. The following is a test process and results:

(All test results are running ten times, take the shortest time)

Test under Windows:

Compile the above code command line using Mono's C # compiler:

Monomcs /out:mtest.exe test.cs

Tip compilation successfully, generate a mtest.exe file.

Enter MTEST directly, use Microsoft's .NET running environment to run, the program is running successfully, no error prompt, display operation results: 2613

Enter mono mtest.exe, use Mono's .NET running environment to run, the program runs successfully, no error prompts, display operation results: 4336

Compile the above code command line using Microsoft C # compile:

CSC / OUT: WTEST TEST.CS

Tip compilation success, but generated a warning: "TEMP variables have been assigned, but never use, this warning is normal, we can do it without taking it, it will not give this test. At the same time, a WTEST.EXE file is generated.

Enter WTEST directly, use Microsoft's .NET running environment to run, the program runs success, no error prompt, display operation results: 2563

Enter MONO WTEST.TEST, run with Mono's .NET running environment, program run success, no error prompt, display operation results: 2654

Compile the Java source file using the Java compiler:

Javac Test.java

The result does not have any errors and warning tips, and generate a Test.class file

Enter: Java Test, use the Java runtime environment to run, the program is running successfully, no error prompts, the display operation results are: 6039?

Test under Linux:

The above three executables: mtest.exe, wartest.exe, test.class, and source file test.cs, Test.java are copied under the Linux system.

There are not many differences under the specific operation and Windows, only report the results:

Mono mtest.exe results are 4205

Mono wartest.exe results are 2527

Java Test results are 4197

Then recompiled MONO and Java source code with the compiler under Linux, run:

Mono test.exe results are 4205

Java Test results are 5876

It is worth mentioning that the code compiled with the MONO's for Windows version and the for Linux version does not have any difference, and there is almost no gap between the operation results. The two Class files compiled with Java's for Windows and FOR Linux have a difference, and there is a big gap between operation results.

In addition, since Mono is exactly the same as the executable compiled under the two platforms, the program compiled under Linux is not tested on Windows, and only the executable executable compiled under Linux is tested on Windows. The result is 5087.

The following is a comparison table (milliseconds) of this test results:

translater

platform

.NET Framework

Mono.net

Java for Win

Java for Linux

.NET Framework

2563

2613

-

-

Windows

2654 (MONO)

4336 (MONO)

6039 (Java)

5087 (Java)

Linux

2527 (MONO)

4205 (Mono)

4197 (Java)

5876 (Java)

?????? By comparing this test results, we found two very interesting phenomena, one is the executable file that MONO's JIT is compiled by the original .NET compiler, the effect is very good, and native .NET JIT running efficiency is very close. But when running its own compiler, efficiency becomes very poor, this situation is the same under Windows and Linux. However, the executable of JIT running MONO compiled MONO is OK. Is Mono I don't like my own biological son? :)

The "cross-platform" capable of Java is the strongest, compiled under Windows, put it in Linux, and the program compiled under Linux is put into Windows. Is this the optimization of Java as cross-platform? :)

In addition, it is worth mentioning that this program compiled with Java in Windows is placed directly in Linux to use two warnings. The warning disappears after recompilation.

In this test, Mono is not expected to look forward to our unexpected results and .net stood on the same line (even can even see the best results in this test. It belongs to Mono, but I think the gap between tens of milliseconds is completely negligible, and cannot think that MONO is more efficient than .NET). At the same time, whether in the Windows platform, or in the Linux platform, Mono's performance exceeds Java. You know, she is just a product in development.

?????? .NET has the most advanced technology, with the fastest efficiency, now she can not only cross the language, but also cross the platform, even the source code, there is Linux, Power PC in Mono's development plan , Solaris, Strong ARM and other versions. There is also Microsoft supported FreeBSD version. Of course, Java will not be a water-saving lamp. I don't know how Sun's underlying chess will be able to resist the crazy attack of the .NET army.

转载请注明原文地址:https://www.9cbs.com/read-119076.html

New Post(0)