Idea Java vs .Net vs Mono
このようなテストを作成するというアイデアは、.NetとJavaの対立に常に悩まされたために生まれたものであり、これらのプラットフォームの実際のパフォーマンスを可能な限り客観的に評価することにし、興味深いオープンソース開発Mono(.Netの無料実装)が登場しましたそれを含めることが決定され、同時にLinuxでテストを実行しました。 したがって、C#とJavaの2つの同様のテストプログラムが開発されました。 以下はC#のソースのスニペットです。完全なソースコードはGoogle Codeリポジトリから取得できます。
http://code.google.com/p/dotnet-java-benchmark/source/checkoutこのテストの目的は、同じコンピューターで基本的に同じコードを実行するさまざまな仮想マシンのパフォーマンスを比較することです。 次のプラットフォームが競争に参加しました。
- Microsoft .Net 4.0(Windows 7)
- Oracle Java SEバージョン6アップデート24(Windows 7)
- Oracle Java SEバージョン6アップデート24(Linux 2.6.35.27 Ubuntu 10.10)
- Novell Mono 2.11(Linux 2.6.35.27 Ubuntu 10.10)
オペレーティングシステムのチューニング、オーバークロック、最適化は行われず、配信されたばかりで、最新のOSアップデートがパッチされています。
テストはボロボロのラップトップDell Inspirion 6400 Intel Core Duo T2300 1.66 GHz 1.5 GB RAMで行われました。 プロセッサは32ビットです。
このテストは、いくつかのグループのマイクロテストで構成されています。
- 数学演算
- 乱数生成
- 配列を操作する
- コレクションを操作する
- 文字列変換
各マイクロテストの結果は、マイクロ秒ごとに実行される操作の平均数です。 テスト全体が10回周期的に実行され、マイクロテストによって得られたすべての結果が再び平均化されました。 テスト全体でプログラムが消費する管理メモリの最大量も概算でした。
Java
Javaプラットフォームのテストは、WindowsのEclipse IDEで開発されました。Linuxで起動した場合、まったく問題はありませんでしたが、どちらの場合もJavaマシンの最大メモリサイズを768 MBで明示的に指定する必要があり、デフォルト値は小さすぎました。 両方のJavaマシンは、次のパラメーターで開始しました。
-Xms32m -Xmx768m
C#
.Net Mono Visual Studio , Mono, int.TryParse(), . int.TryParse() int.Parse() , Linux MonoDevelop ( ). , . , , ( ) Linux .
Mono GC
, , . , Mono
--desktop (Currently this sets the GC system to avoid expanding the heap as much as possible at the expense of slowing down garbage collection a bit).
--gc : Boehm SGen, , Mono. 2.10.1, Ubuntu 10.10 2.6.7. : Git 2.11, . TryParse() , exe Windows Mono , . Boehm, SGen. Mono :
--desktop --gc=sgen
. Y .
, , .
namespace DotNetPerformance.Math
{
public class MathTestParams
{
public static readonly int iterationCount = 5000000;
}
class Div10Test : SomeTest
{
public Div10Test()
{
_name = " 10";
_iterationCount = MathTestParams.iterationCount * 10;
}
public override void Do()
{
StartTiming();
for (int i = 0; i < _iterationCount; ++i)
{
int x = i / 10;
}
StopTiming();
}
}
class SinTest : SomeTest
{
public SinTest()
{
_name = "";
_iterationCount = MathTestParams.iterationCount * 5;
}
public override void Do()
{
double val = 0;
double dt = System.Math.PI * 2;
dt /= _iterationCount;
StartTiming();
for (int i = 0; i < _iterationCount; ++i)
{
double x = System.Math.Sin(val);
val += dt;
}
StopTiming();
}
}
...
}

.Net ( ), , , 10, - , . . , .Net Mono. Mono . Java . Java Linux Windows .
namespace DotNetPerformance.RandomTests
{
public class RandomTestParams
{
public static readonly int count = 10000000;
}
class IntRandomTest : SomeTest
{
public IntRandomTest()
{
_name = " int";
_iterationCount = RandomTestParams.count;
}
private Random rnd = new Random();
public override void Do()
{
StartTiming();
for (int i = 0; i < _iterationCount; ++i)
{
int x = rnd.Next();
}
StopTiming();
}
}
...
}

, , , , . .Net , Mono .
namespace DotNetPerformance.ArraysTests
{
public class ArrayTestParams
{
public static readonly int arraySize = 50000000;
}
class ArrayIntAccessTest : SomeTest
{
public ArrayIntAccessTest()
{
_name = "int[] ";
_iterationCount = ArrayTestParams.arraySize;
}
public override void Do()
{
int[] array = null;
while (array == null)
{
try
{
array = new int[_iterationCount];
}
catch (OutOfMemoryException)
{
_iterationCount /= 2;
Console.WriteLine("!! ");
}
}
for (int i = 0; i < array.Length; ++i)
{
array[i] = i;
}
StartTiming();
for (int i = 0; i 0; –i)
{
int x = array[i];
}
StopTiming();
}
}
...
}

.Net , Java .
namespace DotNetPerformance.CollectionsTests
{
class ListTestParams
{
public static readonly int ListInsertRemoveSize = 500000;
public static readonly int ListAccessSize = 2000000;
}
class DynamicArrayInsertRemoveTest : SomeTest
{
public DynamicArrayInsertRemoveTest()
{
_name = "DynamicArray ";
_iterationCount = ListTestParams.ListInsertRemoveSize / 10;
}
public override void Do()
{
List list = new List();
StartTiming();
for (int i = 0; i 0)
{
list.RemoveAt(0);
}
StopTiming();
}
}
...
}

.Net, Java 4 , Mono . Java , Java , / .
namespace DotNetPerformance.StringConversions
{
public class StringConversionsTestParams
{
public static readonly int iterationCount = 10000000;
}
class IntParseTest : SomeTest
{
public IntParseTest()
{
_name = " int";
_iterationCount = StringConversionsTestParams.iterationCount / 10;
}
public override void Do()
{
string[] arr = new string[_iterationCount];
for (int i = 0; i < arr.Length; ++i)
{
arr[i] = i.ToString();
}
StartTiming();
for (int i = 0; i < arr.Length; ++i)
{
int x = int.Parse(arr[i]);
}
StopTiming();
}
}
...
}

Java , . .Net . double Java float. Mono StringBuilder.

, , , . .Net , . 4 5 Mono Java , (!) . Java Linux Windows .

Mono Java .Net, , - Mono , , .
Java , .Net .
:
updated