Created
February 15, 2019 11:22
-
-
Save marijnz/3d92b4ab09683f697f2a40f1d7a4532a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| private struct StructTest | |
| { | |
| public float t; | |
| public float p; | |
| public bool a; | |
| public int i; | |
| public Vector2 v; | |
| public bool k1; | |
| public bool k2; | |
| public bool k3; | |
| public long p1; | |
| public long p2; | |
| public long p3; | |
| public long p4; | |
| public int v3; | |
| public int v4; | |
| public int v5; | |
| public int v6; | |
| public bool v7; | |
| public long p5; | |
| public long p6; | |
| public long p7; | |
| } | |
| private const int count = 1000; | |
| private const int count2 = 500; | |
| [Test] | |
| public void TestPerfStruct() | |
| { | |
| List<StructTest> list = new List<StructTest>(1000); | |
| for (int i = 0; i < 1000; i++) | |
| { | |
| list.Add(default(StructTest)); | |
| } | |
| Stopwatch stopwatch = Stopwatch.StartNew(); | |
| int num = 0; | |
| for (int j = 0; j < 500; j++) | |
| { | |
| for (int k = 0; k < list.Count; k++) | |
| { | |
| StructTest structTest = list[k]; | |
| num += structTest.i; | |
| } | |
| } | |
| stopwatch.Stop(); | |
| Debug.Log((object)(num + " size: " + Marshal.SizeOf(typeof(StructTest)) + " took: " + stopwatch.Elapsed + " and ms:" + stopwatch.ElapsedMilliseconds)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment