Last active
November 9, 2023 12:06
-
-
Save kamyker/851696cfed9c2cd725b496e2ef2d1900 to your computer and use it in GitHub Desktop.
Unity Mono vs Il2cpp vs NET 6 vs NativeAOT (CoreRT)
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.Diagnostics; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// stopwatch.Restart(); | |
//benchmark.Run(); | |
// time = stopwatch.ElapsedTicks; | |
//Benchmarks.MainFake(); | |
//var watch = Stopwatch.StartNew(); | |
//BenchGC.RunClasses(); | |
//watch.Stop(); | |
//Console.WriteLine(watch.ElapsedTicks); | |
GC.Collect(); | |
var watch = Stopwatch.StartNew(); | |
BenchGC.RunStrings(); | |
watch.Stop(); | |
Console.WriteLine(watch.ElapsedTicks); | |
GC.Collect(); | |
watch = Stopwatch.StartNew(); | |
BenchGC.RunClasses(); | |
watch.Stop(); | |
Console.WriteLine(watch.ElapsedTicks); | |
GC.Collect(); | |
watch = Stopwatch.StartNew(); | |
BenchGC.RunArrays(); | |
watch.Stop(); | |
Console.WriteLine(watch.ElapsedTicks); | |
Console.ReadLine(); | |
} | |
} | |
class BenchGC | |
{ | |
public static int RunStrings() | |
{ | |
string text = "Hello"; | |
int a = 0; | |
for(int i = 0; i < 1_000_000_000; i++) | |
{ | |
text = text.Substring(0, text.Length - 1); | |
a += text.Length; | |
text += "a"; | |
} | |
return text.Length; | |
} | |
public static float RunClasses() | |
{ | |
ClassTest test; | |
float a= 0; | |
for(int j = 0; j < 5; j++) | |
{ | |
for(int i = 0; i < 1_000_000_000; i++) | |
{ | |
test = new ClassTest(); | |
test.Test1 = i; | |
a += test.Test1; | |
} | |
} | |
return a; | |
} | |
public static float RunStructs() | |
{ | |
StructTest test; | |
float a= 0; | |
for(int i = 0; i < 1_000_000_000; i++) | |
{ | |
test = new StructTest(); | |
test.Test1 = i; | |
a += test.Test1; | |
} | |
return a; | |
} | |
public static int RunArrays() | |
{ | |
int[] test; | |
int a = 0; | |
for(int i = 0; i < 300_000; i++) | |
{ | |
test = new int[i]; | |
a += test.Length; | |
} | |
return a; | |
} | |
} | |
class ClassTest | |
{ | |
public float Test1; | |
public float Test2; | |
public float Test3; | |
public float Test4; | |
public float Test5; | |
public float Test6; | |
public float Test7; | |
public float Test8; | |
public float Test9; | |
public float Test10; | |
} | |
struct StructTest | |
{ | |
public float Test1; | |
public float Test2; | |
public float Test3; | |
public float Test4; | |
public float Test5; | |
public float Test6; | |
public float Test7; | |
public float Test8; | |
public float Test9; | |
public float Test10; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result: