📜 ⬆️ ⬇️

Comparative performance testing of .Net, Java and Mono platforms

The idea of ​​Java vs. Net vs Mono


The very idea of ​​creating such a test came from, constantly giving me no peace, opposing .Net and Java, and I decided to objectively assess the real performance of these platforms as objectively as possible, then the interesting opensource development Mono (free implementation of .Net) came into view, and it was decided to include it, and at the same time to run tests for Linux. Accordingly, two similar testing programs were developed in C # and Java. Below are the fragments of source code in C #, the full source code can be obtained from the Google Code Repository:
http://code.google.com/p/dotnet-java-benchmark/source/checkout
The purpose of this test is to compare the performance of different virtual machines that are essentially the same code on the same computer. The following platforms took part in the competition:

No tuna, overclocking or optimization of operating systems has been done, just delivered, patched with the latest updates of the operating system.
Testing was done on my tacky Dell Inspirion 6400 Intel Core Duo T2300 1.66 GHz 1.5 GB RAM. The processor is 32-bit.
The test consists of several groups of microtests:

The result of each microtest is the average number of operations performed per microsecond. The entire test was cycled 10 times cyclically, and all the results of the microtests were again averaged. The estimated maximum amount of managed memory consumed by the program during the entire test was also estimated.

Java


The test for Java platforms was developed in the Eclipse IDE for Windows, when running it on Linux absolutely no problems arose, but in both cases we had to explicitly specify the maximum memory size for the Java machine at 768 MB, the default value was too small. Both Java machines started with the following parameters:
-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();
        }
    }
    ...
}

image

, , , , . .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();
        }
    }
    ...
}

image

.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();
        }
    }
    ...
}

image

.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();
        }
    }
    ...
}

image

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


image

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

image

Mono Java .Net, , - Mono , , .
Java , .Net .


:

updated

')

Source: https://habr.com/ru/post/120090/


All Articles