Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void TestGetComponent()
- {
- Stopwatch stopwatch = Stopwatch.StartNew();
- for (int i = 0; i < iterations; i++)
- {
- Camera.main.GetComponent<AudioListener>().enabled = true;
- }
- double getComponentTime = stopwatch.ElapsedMilliseconds;
- stopwatch.Reset();
- stopwatch.Start();
- AudioListener al = null;
- for (int i = 0; i < iterations; i++)
- {
- if (i == 0)
- al = Camera.main.GetComponent<AudioListener>();
- if (al != null)
- al.enabled = true;
- }
- double getComponentOnce = stopwatch.ElapsedMilliseconds;
- stopwatch.Reset();
- Debug.LogFormat(
- "GetComponent test results:\n" +
- "total GetComponent time: {0:G}ms\n" +
- "average GetComponent time: {1:G}ms\n" +
- "total single GetComponent time: {2:G}ms\n" +
- "average single GetComponent time: {3:G}ms\n",
- getComponentTime,
- (getComponentTime / iterations),
- getComponentOnce,
- (getComponentOnce / iterations)
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement