Created
June 10, 2015 01:41
-
-
Save sushihangover/e82fd97fa2e2255311d8 to your computer and use it in GitHub Desktop.
Mono/.Net C# Performace Test - http://sushihangover.github.io/mono-another-benchmark-between-32-bit-and-64-bit-mono-and-llvm/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
namespace TestNamespace | |
{ | |
public class TestClass | |
{ | |
static long ticks = 0; | |
static double globalvar; | |
public static void InitTicks() | |
{ | |
TestClass.ticks = DateTime.Now.Ticks; | |
} | |
public static void ShowTime(string str) | |
{ | |
long newTicks = DateTime.Now.Ticks; | |
//milliseconds, not Microsoft :) | |
double ms = (newTicks - TestClass.ticks) / TimeSpan.TicksPerMillisecond; | |
Console.WriteLine("{0}{1} ms", str.PadRight(35, '.'), ms); | |
TestClass.ticks = DateTime.Now.Ticks; | |
} | |
public static void Test1() | |
{ | |
ArrayList a = new ArrayList(); | |
for(int i=0;i<1000000;i++) | |
{ | |
string str = i.ToString(); | |
a.Add(str); | |
} | |
ShowTime("ArrayList strings test"); | |
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder(); | |
Random rnd = new Random(); | |
foreach(object strObj in a) | |
{ | |
strBuilder.Append(strObj as string); | |
strBuilder.Append(rnd.Next().ToString()); | |
} | |
string s = strBuilder.ToString(); | |
if(s == "Dsadasdasdsa") | |
{ | |
throw(new Exception("no way...")); | |
} | |
ShowTime("StringBuilder test"); | |
} | |
public static void Test2() | |
{ | |
int i = 0; | |
double d = 0.0; | |
for(i=0; i<1000000000; i++) | |
{ | |
d += i; | |
} | |
double d2 = d/2; | |
globalvar = d2; | |
ShowTime("Integer & Floating ADD"); | |
} | |
public static void Test3() | |
{ | |
int i = 0; | |
int sum = 0; | |
for(i=0;i<100000;i++) | |
{ | |
try | |
{ | |
if(i is int) | |
{ | |
throw(new Exception("the i integer is an integer.. oh no...")); | |
} | |
} | |
catch(Exception ex) | |
{ | |
if(ex is NotImplementedException) | |
{ | |
Console.Write("who's responsable for this ?"); | |
} | |
} | |
} | |
int res = sum/2; | |
if(res == -321) | |
throw(new Exception("this is odd")); | |
ShowTime("Exception test"); | |
} | |
public static void Recursive(string str) | |
{ | |
string name = System.Reflection.MethodBase.GetCurrentMethod().Name; | |
if(str.Substring(0, name.Length) == name) | |
{ | |
int i = Convert.ToInt32(str.Substring(name.Length)); | |
if(i < 1000) | |
{ | |
// Console.Write(i.ToString()+"\n"); | |
Recursive(name + (i+1).ToString()); | |
} | |
} | |
} | |
public static void Test4() | |
{ | |
for(int i=0;i<1000;i++) | |
{ | |
Recursive("Recursive0"); | |
} | |
ShowTime("Reflection and recursion"); | |
} | |
public static void Main() | |
{ | |
InitTicks(); | |
Test1(); | |
Test2(); | |
Test3(); | |
Test4(); | |
Console.Write(globalvar.ToString()+"\n"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment