Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using UnityEngine;
- class SomeClass {
- public List<int> list;
- }
- public class Benchmark : MonoBehaviour {
- const int _max = 10000000;
- void Start () {
- UnityEngine.Debug.Log ("Test");
- SomeClass someClass = new SomeClass ();
- someClass.list = new List<int> ();
- for (int i = 0; i < _max; i++) {
- someClass.list.Add (1);
- }
- var s1 = Stopwatch.StartNew ();
- for (int i = 0; i < someClass.list.Count; i++) {
- }
- s1.Stop ();
- var s2 = Stopwatch.StartNew ();
- int count = someClass.list.Count;
- for (int i = 0; i < count; i++) {
- }
- var s3 = Stopwatch.StartNew ();
- for (int i = 0; i < someClass.list.Count; i++) {
- }
- s1.Stop ();
- var s4 = Stopwatch.StartNew ();
- int count2 = someClass.list.Count;
- for (int i = 0; i < count2; i++) {
- }
- s2.Stop ();
- UnityEngine.Debug.Log (((double) (s1.Elapsed.TotalMilliseconds * 1000000) /
- _max).ToString ("0.00 ns"));
- UnityEngine.Debug.Log (((double) (s2.Elapsed.TotalMilliseconds * 1000000) /
- _max).ToString ("0.00 ns"));
- UnityEngine.Debug.Log (((double) (s3.Elapsed.TotalMilliseconds * 1000000) /
- _max).ToString ("0.00 ns"));
- UnityEngine.Debug.Log (((double) (s4.Elapsed.TotalMilliseconds * 1000000) /
- _max).ToString ("0.00 ns"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement