-
Notifications
You must be signed in to change notification settings - Fork 44
/
GCTest.cs
72 lines (64 loc) · 1.92 KB
/
GCTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GCTest : MonoBehaviour {
//------------------------List test PASS---------------------------------------
private List<int> _ListTest;
void List_Test_Update (int length) {
for (int i = 0; i < length; i++) {
// List<int> localList = new List<int> ();
// _ListTest.Clear();
_ListTest = new List<int> ();
}
}
//------------------------List test end---------------------------------------
//------------------------String test PASS-------------------------------
//----未优化----
public Text timerText;
private float timer;
void String_Test_Update () {
timer += Time.deltaTime;
timerText.text = "Time:" + timer.ToString ();
}
//----优化版:避免频繁拼接字符串----
public Text timerHeaderText;
public Text timerValueText;
private float _timer;
void String_Start () {
timerHeaderText.text = "TIME:";
}
void String_Test_optimize_Update () {
timerValueText.text = timer.ToString ();
}
//------------------------String test end---------------------------------------
// 为优化版
void StringPerformance(){
String str = "";
for (int i = 0; i < 1000; i++)
{
str += "sss";
}
}
// 优化版 :使用StringBuilder拼接字符串
void StringPerformance_O(){
StringBuilder str = new StringBuilder(1000);
for (int i = 0; i < 1000; i++)
{
str.Append("sss");
}
}
//
void Start () {
String_Start ();
}
void Update () {
// List_Test_Update (10000);
// String_Test_Update ();
// String_Test_optimize_Update ();
// StringPerformance();
// StringPerformance_O();
}
}