├── .gitignore
├── Assets
├── Scenes.meta
├── Scenes
│ ├── Raycast.unity
│ ├── Raycast.unity.meta
│ ├── ScriptPerformance.unity
│ └── ScriptPerformance.unity.meta
├── Scripts.meta
└── Scripts
│ ├── ColliderHitData.cs
│ ├── ColliderHitData.cs.meta
│ ├── FastList.cs
│ ├── FastList.cs.meta
│ ├── ITestController.cs
│ ├── ITestController.cs.meta
│ ├── RaycastHelper.cs
│ ├── RaycastHelper.cs.meta
│ ├── RaycastHitData.cs
│ ├── RaycastHitData.cs.meta
│ ├── TestController.cs
│ ├── TestController.cs.meta
│ ├── Test_Accessors.cs
│ ├── Test_Accessors.cs.meta
│ ├── Test_Action.cs
│ ├── Test_Action.cs.meta
│ ├── Test_Collection_Add_GameObject.cs
│ ├── Test_Collection_Add_GameObject.cs.meta
│ ├── Test_Collection_Add_Int32.cs
│ ├── Test_Collection_Add_Int32.cs.meta
│ ├── Test_Collection_Contains_GameObject.cs
│ ├── Test_Collection_Contains_GameObject.cs.meta
│ ├── Test_Collection_Contains_Int32.cs
│ ├── Test_Collection_Contains_Int32.cs.meta
│ ├── Test_Collection_Iteration_Int32.cs
│ ├── Test_Collection_Iteration_Int32.cs.meta
│ ├── Test_Collection_Remove_Key_Int32.cs
│ ├── Test_Collection_Remove_Key_Int32.cs.meta
│ ├── Test_Collection_Remove_Value_Int32.cs
│ ├── Test_Collection_Remove_Value_Int32.cs.meta
│ ├── Test_DictionaryCompare.cs
│ ├── Test_DictionaryCompare.cs.meta
│ ├── Test_Equals.cs
│ ├── Test_Equals.cs.meta
│ ├── Test_EventsController.cs
│ ├── Test_EventsController.cs.meta
│ ├── Test_FastList.cs
│ ├── Test_FastList.cs.meta
│ ├── Test_GameObject.cs
│ ├── Test_GameObject.cs.meta
│ ├── Test_GameObjectController.cs
│ ├── Test_GameObjectController.cs.meta
│ ├── Test_List.cs
│ ├── Test_List.cs.meta
│ ├── Test_RayCast.cs
│ ├── Test_RayCast.cs.meta
│ ├── Test_SendMessage.cs
│ ├── Test_SendMessage.cs.meta
│ ├── Test_StringPerf.cs
│ ├── Test_StringPerf.cs.meta
│ ├── Test_Transform.cs
│ ├── Test_Transform.cs.meta
│ ├── Test_TransformController.cs
│ ├── Test_TransformController.cs.meta
│ ├── Test_UnityEvents.cs
│ ├── Test_UnityEvents.cs.meta
│ ├── Test_UnityMessage.cs
│ ├── Test_UnityMessage.cs.meta
│ ├── Utils_Perf.cs
│ └── Utils_Perf.cs.meta
├── Packages
└── manifest.json
├── ProjectSettings
├── AudioManager.asset
├── ClusterInputManager.asset
├── DynamicsManager.asset
├── EditorBuildSettings.asset
├── EditorSettings.asset
├── GraphicsSettings.asset
├── InputManager.asset
├── NavMeshAreas.asset
├── NetworkManager.asset
├── Physics2DSettings.asset
├── ProjectSettings.asset
├── ProjectVersion.txt
├── QualitySettings.asset
├── TagManager.asset
├── TimeManager.asset
└── UnityConnectSettings.asset
├── README.md
└── UnityPackageManager
└── manifest.json
/.gitignore:
--------------------------------------------------------------------------------
1 | # =============== #
2 | # Unity generated #
3 | # =============== #
4 | [Tt]emp/
5 | [Oo]bj/
6 | [Bb]uild/
7 | [Ll]ibrary/
8 | [Aa]ssets/StreamingAssets/build_info.txt
9 | sysinfo.txt
10 |
11 | # ===================================== #
12 | # Visual Studio / MonoDevelop generated #
13 | # ===================================== #
14 | [Ee]xported[Oo]bj/
15 | /*.userprefs
16 | /*.csproj
17 | /*.pidb
18 | /*.suo
19 | /*.sln*
20 | /*.user
21 | /*.unityproj
22 | /*.booproj
23 | .vs/
24 |
25 | # ============ #
26 | # OS generated #
27 | # ============ #
28 | .DS_Store*
29 | ._*
30 | .Spotlight-V100
31 | .Trashes
32 | #Icon?
33 | ehthumbs.db
34 | [Tt]humbs.db
35 | Assets/xARM/_xARM User Guide.pdf
36 | Assets/xARM/_xARM User Guide.pdf.meta
37 |
--------------------------------------------------------------------------------
/Assets/Scenes.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7c0422f91bc2c1e4ba039c0d28079030
3 | folderAsset: yes
4 | timeCreated: 1481251508
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/Scenes/Raycast.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5f6adb0cbf0e1b54592f2d595cbb8988
3 | timeCreated: 1524351783
4 | licenseType: Free
5 | DefaultImporter:
6 | externalObjects: {}
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/Scenes/ScriptPerformance.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6531f4b9c30a62949a06d1bd80053a0d
3 | timeCreated: 1481251519
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Assets/Scripts.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8281f014627b28d40a574c6e3ea17933
3 | folderAsset: yes
4 | timeCreated: 1481251283
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/Assets/Scripts/ColliderHitData.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using UnityEngine;
5 |
6 | namespace GP.Utils
7 | {
8 | ///
9 | /// Data class for the non-alloc Physics helper functions in RaycastHelper
10 | ///
11 | [System.Serializable]
12 | public class ColliderHitData
13 | {
14 | [Header("SETUP")]
15 | ///
16 | /// A Layer mask that is used to selectively ignore colliders when casting.
17 | ///
18 | [SerializeField]
19 | public LayerMask layerMask = Physics.DefaultRaycastLayers;
20 |
21 | ///
22 | /// Specifies whether this query should hit Triggers.
23 | ///
24 | [SerializeField]
25 | public QueryTriggerInteraction triggerInteraction = QueryTriggerInteraction.UseGlobal;
26 |
27 | ///
28 | /// Will resize the hitResults array
29 | /// if the results array is smaller (or equal to)
30 | /// the number of results from Physics. You
31 | /// will always get ALL the hits back, not just
32 | /// the amount you allocated for.
33 | ///
34 | [SerializeField]
35 | public bool autoResize = true;
36 |
37 | ///
38 | /// The casting functions will allocate the collResults
39 | /// array for you if this is greater than zero.
40 | /// This variable makes it easier to setup in the
41 | /// editor.
42 | ///
43 | [SerializeField]
44 | public int sizeAtInit = 0;
45 |
46 | [Space(10)]
47 | [Header("RUNTIME RESULTS")]
48 | ///
49 | /// The amount of hits stored into the results buffer.
50 | ///
51 | /// [SerializeField]
52 | public int numHits = 0;
53 |
54 | [SerializeField]
55 | ///
56 | /// Results returned from Physics calls
57 | ///
58 | public Collider[] collResults;
59 |
60 | public const int DEFAULT_SIZE = 16;
61 |
62 | public ColliderHitData()
63 | {
64 | if (sizeAtInit > 0)
65 | Init(sizeAtInit);
66 | }
67 |
68 | ///
69 | /// Initialize the collResults array
70 | ///
71 | /// Array size
72 | public ColliderHitData(int size)
73 | {
74 | if (size > 0)
75 | Init(size);
76 | }
77 |
78 | ///
79 | /// Initialize the collResults array
80 | ///
81 | ///
82 | public void Init (int hitCapacity)
83 | {
84 | if (hitCapacity == 0)
85 | collResults = new Collider[DEFAULT_SIZE];
86 | else
87 | collResults = new Collider[hitCapacity];
88 | numHits = 0;
89 | }
90 | }
91 | }
92 |
93 | /*
94 | Revised BSD License
95 |
96 | Copyright(c) 2018, Garret Polk
97 | All rights reserved.
98 |
99 | Redistribution and use in source and binary forms, with or without
100 | modification, are permitted provided that the following conditions are met:
101 | * Redistributions of source code must retain the above copyright
102 | notice, this list of conditions and the following disclaimer.
103 | * Redistributions in binary form must reproduce the above copyright
104 | notice, this list of conditions and the following disclaimer in the
105 | documentation and/or other materials provided with the distribution.
106 | * Neither the name of the Garret Polk nor the
107 | names of its contributors may be used to endorse or promote products
108 | derived from this software without specific prior written permission.
109 |
110 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
111 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
112 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
113 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
114 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
115 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
116 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
117 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
118 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
119 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
120 | */
121 |
--------------------------------------------------------------------------------
/Assets/Scripts/ColliderHitData.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 686381170d5422f42848a49670ad1a8b
3 | timeCreated: 1524290201
4 | licenseType: Free
5 | MonoImporter:
6 | externalObjects: {}
7 | serializedVersion: 2
8 | defaultReferences: []
9 | executionOrder: 0
10 | icon: {instanceID: 0}
11 | userData:
12 | assetBundleName:
13 | assetBundleVariant:
14 |
--------------------------------------------------------------------------------
/Assets/Scripts/FastList.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using System.Collections;
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | namespace GP.Utils
7 | {
8 | ///
9 | /// This is an EXPERIMENTAL collection similar to a List<>
10 | /// but faster. The idea is to have a collection with the
11 | /// convenience of a List<> but more speed like an array.
12 | ///
13 | /// USE THE CUSTOM VERSIONS IF THEY MATCH YOUR NEEDS.
14 | /// i.e. Use FastListInt, not FastList
15 | ///
16 | /// This class is as fast or faster than
17 | /// List, ArrayList, LinkedList for all uses,
18 | /// if custom versions are used where needed.
19 | ///
20 | /// The regular generic T version uses .Equals()
21 | /// which is usually much SLOWER than == for a basic type.
22 | /// So at the bottom I have included custom list types
23 | /// which are much FASTER than the generic version. You
24 | /// can also implement your own versions by deriving from
25 | /// FastList the same way.
26 | ///
27 | /// FastList implements a generic array.
28 | /// It will grow automatically on Add() but not shrink
29 | /// unless Resize() is specifically called. This is to reduce Garbage
30 | /// Collection performance hits, just like an array.
31 | ///
32 | /// The disadvantage of FastList over a regular List
33 | /// is that this can allocate more memory and not release
34 | /// it until instructed. Of course, that's the whole point.
35 | ///
36 | /// See also:
37 | /// C# IList : https://msdn.microsoft.com/en-us/library/system.collections.ilist(v=vs.110).aspx
38 | /// Foreach : https://docs.google.com/document/d/1daaIK8k7PTdYZetywLo1WAnAZv_zfMHOn15s_Px6VHc/
39 | /// GameObject == : https://blogs.unity3d.com/2014/05/16/custom-operator-should-we-keep-it/
40 | ///
41 | /// If you are careful, you can use RawArray() to perform operations
42 | /// on the underlying array elements. For example, you can sort the
43 | /// array much faster than List using :
44 | /// System.Array.Sort(fastList.RawArray(), 0, fastList.Count);
45 | ///
46 | ///
47 | public class FastList : IList
48 | {
49 | ///
50 | /// Contents of the collection
51 | ///
52 | protected T[] _entries;
53 |
54 | ///
55 | /// Number of items added to the array (not the length)
56 | /// Use Count to access.
57 | ///
58 | protected int _count;
59 |
60 | ///
61 | /// When re-allocating the array, multiply the existing size by this size
62 | ///
63 | public static int ALLOCATION_INCREMENT = 2;
64 |
65 | ///
66 | /// Initial size of a new collection
67 | ///
68 | public const int START_SIZE = 16;
69 |
70 | ///
71 | /// Length of the internal array
72 | /// (not the Count of the elements in the list)
73 | ///
74 | public int Capacity
75 | {
76 | get
77 | {
78 | if (_entries == null)
79 | return 0;
80 | return _entries.Length;
81 | }
82 | }
83 |
84 | ///
85 | /// Returns the normally protected array.
86 | ///
87 | /// You can improve iteration performance if you use
88 | /// this raw array when iterating
89 | /// (without adding/removing items).
90 | ///
91 | /// Warning : modifying it may invalidate the FastList
92 | ///
93 | ///
94 | public T[] RawArray()
95 | {
96 | return _entries;
97 | }
98 |
99 | ///
100 | /// Allocates a new array of default size START_SIZE
101 | ///
102 | /// Length of the array
103 | public FastList(int size = START_SIZE)
104 | {
105 | if ( size != 0 )
106 | Resize(size);
107 | _count = 0;
108 | }
109 |
110 | public bool IsFixedSize
111 | {
112 | get { return false; }
113 | }
114 |
115 | public bool IsReadOnly
116 | {
117 | get { return false; }
118 | }
119 |
120 | public int Count
121 | {
122 | get { return _count; }
123 | }
124 |
125 | public bool IsSynchronized
126 | {
127 | get { return false; }
128 | }
129 |
130 | public object SyncRoot
131 | {
132 | get { return this; }
133 | }
134 |
135 | public T GetAt (int index)
136 | {
137 | return _entries[index];
138 | }
139 |
140 | public T this[int index]
141 | {
142 | get { return _entries[index]; }
143 | set
144 | {
145 | _entries[index] = value;
146 | if (index > _count)
147 | _count = index + 1;
148 | }
149 | }
150 |
151 | public void Add(T value)
152 | {
153 | // Allocate if needed
154 | if ( _count == _entries.Length )
155 | {
156 | Resize(_entries.Length * ALLOCATION_INCREMENT);
157 | }
158 |
159 | _entries[_count] = value;
160 | _count++;
161 | }
162 |
163 | // Don't de-allocate, don't hit GC
164 | public void Clear()
165 | {
166 | System.Array.Clear(_entries, 0, _entries.Length);
167 | _count = 0;
168 | }
169 |
170 | public bool Contains(T value)
171 | {
172 | return (IndexOf(value) == -1)?false:true;
173 | }
174 |
175 | virtual public int IndexOf(T value)
176 | {
177 | for (int i = 0; i < _count; i++)
178 | {
179 | if (_entries[i].Equals(value))
180 | {
181 | return i;
182 | }
183 | }
184 | return -1;
185 | }
186 |
187 | // TODO - need to handle inserting beyond the current capacity
188 | public void Insert(int index, T value)
189 | {
190 | // 0 1 2 3 4 5 6 7 8 9 = 10
191 | // Allocate if needed
192 | if (_count == _entries.Length)
193 | {
194 | Resize(_entries.Length * ALLOCATION_INCREMENT);
195 | }
196 |
197 | // Move everything down one
198 | // MUCH faster than a for() loop
199 | System.Array.Copy(_entries, index, _entries, index + 1, _entries.Length - index - 1);
200 | _entries[index] = value;
201 | _count++;
202 | }
203 |
204 | public bool Remove(T value)
205 | {
206 | int index = IndexOf(value);
207 | if (index != -1)
208 | {
209 | RemoveAt(index);
210 | return true;
211 | }
212 | return false;
213 | }
214 |
215 | public void RemoveAt(int index)
216 | {
217 | // Move everything up one
218 | if ((index >= 0) && (index < _count))
219 | {
220 | // MUCH faster than a for() loop
221 | System.Array.Copy(_entries, index + 1, _entries, index, _count - index );
222 | _count--;
223 | }
224 | }
225 |
226 | // ICollection Members
227 | ///
228 | /// Copies ALL elements to the specified array
229 | /// starting at the specified destination array index.
230 | ///
231 | /// Destination array
232 | /// Starting destination index
233 | ///
234 | public void CopyTo(Array array, int index)
235 | {
236 | System.Array.Copy(_entries, 0, array, index, _count);
237 | }
238 |
239 | ///
240 | /// Copies ALL elements to the specified array
241 | /// starting at the specified destination array index.
242 | ///
243 | /// Destination array
244 | /// Starting destination index
245 | ///
246 | public void CopyTo (T[] array, int index)
247 | {
248 | System.Array.Copy(_entries, 0, array, index, _count);
249 | }
250 |
251 | ///
252 | /// Copies ALL elements to the specified array
253 | /// starting at the specified destination array index.
254 | ///
255 | /// Destination list
256 | /// Starting destination index
257 | ///
258 | public void CopyTo(FastList list, int index)
259 | {
260 | if (list.Capacity < _count)
261 | list.Resize(_count);
262 |
263 | System.Array.Copy(_entries, 0, list._entries, index, _count);
264 | }
265 |
266 | public FastListEnumerator GetEnumerator()
267 | {
268 | FastListEnumerator fastEnum = new FastListEnumerator();
269 | fastEnum._list = this;
270 | fastEnum.Reset();
271 | return fastEnum;
272 | }
273 |
274 | // Needed as well as version
275 | IEnumerator IEnumerable.GetEnumerator()
276 | {
277 | return ((IList)_entries).GetEnumerator();
278 | }
279 |
280 | // IEnumerable Members
281 | IEnumerator IEnumerable.GetEnumerator()
282 | {
283 | FastListEnumerator fastEnum = new FastListEnumerator();
284 | fastEnum._list = this;
285 | fastEnum.Reset();
286 | return (IEnumerator)fastEnum;
287 | }
288 |
289 | // CUSTOM FUNCTIONS
290 | public void Resize(int newLength)
291 | {
292 | System.Array.Resize(ref _entries, newLength);
293 | }
294 |
295 | //void ICollection.Add(T item)
296 | //{
297 | // ((ICollection)_entries).Add(item);
298 | //}
299 |
300 | //IEnumerator IEnumerable.GetEnumerator()
301 | //{
302 | // return ((ICollection)_entries).GetEnumerator();
303 | //}
304 |
305 | public struct FastListEnumerator : IEnumerator
306 | {
307 | public int _index;
308 | public FastList _list;
309 | private E _current;
310 |
311 | public E Current
312 | {
313 | get { return _current; }
314 | }
315 |
316 | object IEnumerator.Current
317 | {
318 | get { return (object)_current; }
319 | }
320 |
321 | public bool MoveNext()
322 | {
323 | if (_index < _list._count - 1)
324 | {
325 | _index++;
326 | _current = _list[_index];
327 | return true;
328 | }
329 | else
330 | return false;
331 | }
332 |
333 | public void Reset()
334 | {
335 | _index = -1;
336 | }
337 |
338 | void IDisposable.Dispose()
339 | {
340 | }
341 | }
342 | }
343 |
344 | ///
345 | /// Custom classes for FastList
346 | /// These exist for types where the .Equals operation is slower than ==
347 | ///
348 | /// Use these classes (if available) if you use the search
349 | /// functions Contains(), IndexOf(), or Remove(T value)
350 | ///
351 | public class FastListInt : FastList
352 | {
353 | public FastListInt() : base()
354 | {
355 | }
356 |
357 | public FastListInt(int size) : base(size)
358 | {
359 | }
360 |
361 | override public int IndexOf(int value)
362 | {
363 | int itemIndex = -1;
364 | for (int i = 0; i < _count; i++)
365 | {
366 | if (_entries[i] == value)
367 | {
368 | itemIndex = i;
369 | break;
370 | }
371 | }
372 | return itemIndex;
373 | }
374 | }
375 |
376 | public class FastListBool : FastList
377 | {
378 | public FastListBool(int size = START_SIZE) : base(size)
379 | {
380 | }
381 |
382 | override public int IndexOf(bool value)
383 | {
384 | int itemIndex = -1;
385 | for (int i = 0; i < _count; i++)
386 | {
387 | if (_entries[i] == value)
388 | {
389 | itemIndex = i;
390 | break;
391 | }
392 | }
393 | return itemIndex;
394 | }
395 | }
396 |
397 | public class FastListFloat : FastList
398 | {
399 | public FastListFloat(int size = START_SIZE) : base(size)
400 | {
401 | }
402 |
403 | override public int IndexOf(float value)
404 | {
405 | int itemIndex = -1;
406 | for (int i = 0; i < _count; i++)
407 | {
408 | if (_entries[i] == value)
409 | {
410 | itemIndex = i;
411 | break;
412 | }
413 | }
414 | return itemIndex;
415 | }
416 | }
417 |
418 | public class FastListGO : FastList
419 | {
420 | public FastListGO(int size = START_SIZE) : base(size)
421 | {
422 | }
423 |
424 | override public int IndexOf(UnityEngine.GameObject value)
425 | {
426 | int itemIndex = -1;
427 | for (int i = 0; i < _count; i++)
428 | {
429 | if (_entries[i] == value)
430 | {
431 | itemIndex = i;
432 | break;
433 | }
434 | }
435 | return itemIndex;
436 | }
437 | }
438 | }
439 |
440 | /*
441 | Revised BSD License
442 |
443 | Copyright(c) 2018, Garret Polk
444 | All rights reserved.
445 |
446 | Redistribution and use in source and binary forms, with or without
447 | modification, are permitted provided that the following conditions are met:
448 | * Redistributions of source code must retain the above copyright
449 | notice, this list of conditions and the following disclaimer.
450 | * Redistributions in binary form must reproduce the above copyright
451 | notice, this list of conditions and the following disclaimer in the
452 | documentation and/or other materials provided with the distribution.
453 | * Neither the name of the Garret Polk nor the
454 | names of its contributors may be used to endorse or promote products
455 | derived from this software without specific prior written permission.
456 |
457 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
458 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
459 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
460 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
461 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
462 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
463 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
464 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
465 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
466 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
467 | */
468 |
--------------------------------------------------------------------------------
/Assets/Scripts/FastList.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8ff47763b163b2449a360377e80f770f
3 | timeCreated: 1524024655
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/ITestController.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 |
5 | ///
6 | /// Simple interface for a test controller
7 | ///
8 | public interface ITestController
9 | {
10 | void Init();
11 | void Test();
12 | }
13 |
14 | /*
15 | Revised BSD License
16 |
17 | Copyright(c) 2018, Garret Polk
18 | All rights reserved.
19 |
20 | Redistribution and use in source and binary forms, with or without
21 | modification, are permitted provided that the following conditions are met:
22 | * Redistributions of source code must retain the above copyright
23 | notice, this list of conditions and the following disclaimer.
24 | * Redistributions in binary form must reproduce the above copyright
25 | notice, this list of conditions and the following disclaimer in the
26 | documentation and/or other materials provided with the distribution.
27 | * Neither the name of the Garret Polk nor the
28 | names of its contributors may be used to endorse or promote products
29 | derived from this software without specific prior written permission.
30 |
31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
35 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 | */
42 |
--------------------------------------------------------------------------------
/Assets/Scripts/ITestController.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6aa9d35a5e1a9534b9751ba5a00338e5
3 | timeCreated: 1511232968
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/RaycastHelper.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c6279d3721362dd4bbeda53bc521d611
3 | timeCreated: 1524290201
4 | licenseType: Free
5 | MonoImporter:
6 | externalObjects: {}
7 | serializedVersion: 2
8 | defaultReferences: []
9 | executionOrder: 0
10 | icon: {instanceID: 0}
11 | userData:
12 | assetBundleName:
13 | assetBundleVariant:
14 |
--------------------------------------------------------------------------------
/Assets/Scripts/RaycastHitData.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using UnityEngine;
5 |
6 | namespace GP.Utils
7 | {
8 | ///
9 | /// Data class for the non-alloc Physics helper functions in RaycastHelper
10 | ///
11 | [System.Serializable]
12 | public class RaycastHitData
13 | {
14 | [Header("SETUP")]
15 | ///
16 | /// A Layer mask that is used to selectively ignore colliders when casting.
17 | ///
18 | [SerializeField]
19 | public LayerMask layerMask = Physics.DefaultRaycastLayers;
20 |
21 | ///
22 | /// Specifies whether this query should hit Triggers.
23 | ///
24 | [SerializeField]
25 | public QueryTriggerInteraction triggerInteraction = QueryTriggerInteraction.UseGlobal;
26 |
27 | ///
28 | /// Will resize the hitResults array
29 | /// if the results array is smaller (or equal to)
30 | /// the number of results from Physics. You
31 | /// will always get ALL the hits back, not just
32 | /// the amount you allocated for.
33 | ///
34 | [SerializeField]
35 | public bool autoResize = true;
36 |
37 | ///
38 | /// The casting functions will allocate the hitResults
39 | /// array for you if this is greater than zero.
40 | /// This variable makes it easier to setup in the
41 | /// editor.
42 | ///
43 | [SerializeField]
44 | public int sizeAtInit = 0;
45 |
46 | [Space(10)]
47 | [Header("RUNTIME RESULTS")]
48 | ///
49 | /// The amount of hits stored into the results buffer.
50 | ///
51 | [SerializeField]
52 | public int numHits = 0;
53 |
54 | ///
55 | /// Results returned from Physics calls
56 | ///
57 | [SerializeField]
58 | public RaycastHit[] hitResults;
59 |
60 | public const int DEFAULT_SIZE = 16;
61 |
62 | public RaycastHitData()
63 | {
64 | if (sizeAtInit > 0)
65 | Init(sizeAtInit);
66 | }
67 |
68 | ///
69 | /// Initialize the collResults array
70 | ///
71 | /// Array size
72 | public RaycastHitData(int size)
73 | {
74 | if (size > 0)
75 | Init(size);
76 | }
77 |
78 | ///
79 | /// Initialize the hitResults array
80 | ///
81 | /// Set to 0 for default size
82 | public void Init(int hitCapacity = 0)
83 | {
84 | if ( hitCapacity == 0 )
85 | hitResults = new RaycastHit[DEFAULT_SIZE];
86 | else
87 | hitResults = new RaycastHit[hitCapacity];
88 | numHits = 0;
89 | }
90 | }
91 | }
92 | /*
93 | Revised BSD License
94 |
95 | Copyright(c) 2018, Garret Polk
96 | All rights reserved.
97 |
98 | Redistribution and use in source and binary forms, with or without
99 | modification, are permitted provided that the following conditions are met:
100 | * Redistributions of source code must retain the above copyright
101 | notice, this list of conditions and the following disclaimer.
102 | * Redistributions in binary form must reproduce the above copyright
103 | notice, this list of conditions and the following disclaimer in the
104 | documentation and/or other materials provided with the distribution.
105 | * Neither the name of the Garret Polk nor the
106 | names of its contributors may be used to endorse or promote products
107 | derived from this software without specific prior written permission.
108 |
109 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
110 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
111 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
112 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
113 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
114 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
115 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
116 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
117 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
118 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
119 | */
120 |
--------------------------------------------------------------------------------
/Assets/Scripts/RaycastHitData.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ad5012918d44c434cba87f97bdf9dff9
3 | timeCreated: 1524290201
4 | licenseType: Free
5 | MonoImporter:
6 | externalObjects: {}
7 | serializedVersion: 2
8 | defaultReferences: []
9 | executionOrder: 0
10 | icon: {instanceID: 0}
11 | userData:
12 | assetBundleName:
13 | assetBundleVariant:
14 |
--------------------------------------------------------------------------------
/Assets/Scripts/TestController.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | #if UNITY_EDITOR
4 | using UnityEditor;
5 | #endif
6 | using System.Collections;
7 |
8 | ///
9 | /// Top-level test manager.
10 | /// This MonoBehaviour will run any ITestController
11 | /// tests on the child objects. To enable/disable a
12 | /// test just turn the child object on/off.
13 | ///
14 | public class TestController : MonoBehaviour
15 | {
16 | [Header("This object will run tests on all active child test objects")]
17 | public int numIterations = 10;
18 |
19 | private ITestController[] tests;
20 | private int currentIteration;
21 |
22 | private void Awake()
23 | {
24 | UnityEngine.Profiling.Profiler.enabled = true;
25 | }
26 |
27 | void Start()
28 | {
29 | UnityEngine.Profiling.Profiler.BeginSample("Init tests");
30 | currentIteration = 0;
31 | tests = GetComponentsInChildren();
32 |
33 | for ( int iTest = 0, iTestLen = tests.Length;
34 | iTest < iTestLen;
35 | iTest++)
36 | {
37 | if (tests[iTest] != null)
38 | {
39 | tests[iTest].Init();
40 | }
41 | }
42 | UnityEngine.Profiling.Profiler.EndSample();
43 | }
44 |
45 | void Update()
46 | {
47 | if (currentIteration < numIterations)
48 | {
49 | for (int iTest = 0, iTestLen = tests.Length;
50 | iTest < iTestLen;
51 | iTest++)
52 | {
53 | tests[iTest].Test();
54 | }
55 | currentIteration++;
56 |
57 | // Done, stop running
58 | if (currentIteration == numIterations)
59 | {
60 | #if UNITY_EDITOR
61 | UnityEditor.EditorApplication.isPlaying = false;
62 | #endif
63 | Application.Quit();
64 | }
65 | else
66 | {
67 | // Try to flush memory for the next run
68 | System.GC.Collect();
69 | }
70 | }
71 | }
72 | }
73 |
74 | /*
75 | Revised BSD License
76 |
77 | Copyright(c) 2018, Garret Polk
78 | All rights reserved.
79 |
80 | Redistribution and use in source and binary forms, with or without
81 | modification, are permitted provided that the following conditions are met:
82 | * Redistributions of source code must retain the above copyright
83 | notice, this list of conditions and the following disclaimer.
84 | * Redistributions in binary form must reproduce the above copyright
85 | notice, this list of conditions and the following disclaimer in the
86 | documentation and/or other materials provided with the distribution.
87 | * Neither the name of the Garret Polk nor the
88 | names of its contributors may be used to endorse or promote products
89 | derived from this software without specific prior written permission.
90 |
91 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
92 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
93 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
94 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
95 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
96 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
97 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
98 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
99 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
100 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
101 | */
102 |
--------------------------------------------------------------------------------
/Assets/Scripts/TestController.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 44fbce6c0d432454382618c908f2d00e
3 | timeCreated: 1511232968
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Accessors.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using UnityEngine;
5 | using GP.Utils;
6 |
7 | ///
8 | /// Harness for accessor (get/set) tests.
9 | ///
10 | public class Test_Accessors : MonoBehaviour, ITestController
11 | {
12 | int accessorIterations = 10000;
13 | int vector3Iterations = 1000;
14 |
15 | bool genericValueAccessors { get; set; }
16 | bool genericValue;
17 |
18 | public void Init()
19 | {
20 | genericValue = true;
21 | genericValueAccessors = true;
22 | }
23 |
24 | public void Test()
25 | {
26 | UnityEngine.Profiling.Profiler.BeginSample("Accessors functions (yes)");
27 | for (int iTest = 0; iTest < accessorIterations; iTest++)
28 | genericValueAccessors = !genericValueAccessors;
29 | UnityEngine.Profiling.Profiler.EndSample();
30 |
31 | UnityEngine.Profiling.Profiler.BeginSample("Accessors functions (no)");
32 | for (int iTest = 0; iTest < accessorIterations; iTest++)
33 | genericValue = !genericValue;
34 | UnityEngine.Profiling.Profiler.EndSample();
35 |
36 | UnityEngine.Profiling.Profiler.BeginSample("Vector3 (Unity)");
37 | for (int iTest = 0; iTest < vector3Iterations; iTest++)
38 | {
39 | Vector3 newVec = Vector3.zero;
40 | }
41 | UnityEngine.Profiling.Profiler.EndSample();
42 |
43 | UnityEngine.Profiling.Profiler.BeginSample("Vector3 (static)");
44 | for (int iTest = 0; iTest < vector3Iterations; iTest++)
45 | {
46 | Vector3 newVec = Utils_Perf.vec3_zero;
47 | }
48 | UnityEngine.Profiling.Profiler.EndSample();
49 | }
50 | }
51 | /*
52 | Revised BSD License
53 |
54 | Copyright(c) 2018, Garret Polk
55 | All rights reserved.
56 |
57 | Redistribution and use in source and binary forms, with or without
58 | modification, are permitted provided that the following conditions are met:
59 | * Redistributions of source code must retain the above copyright
60 | notice, this list of conditions and the following disclaimer.
61 | * Redistributions in binary form must reproduce the above copyright
62 | notice, this list of conditions and the following disclaimer in the
63 | documentation and/or other materials provided with the distribution.
64 | * Neither the name of the Garret Polk nor the
65 | names of its contributors may be used to endorse or promote products
66 | derived from this software without specific prior written permission.
67 |
68 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
69 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
70 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
71 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
72 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
73 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
74 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
75 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
76 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
77 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
78 | */
79 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Accessors.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9a7cd9ef46ae9ac48ad0c3b30c1d5f39
3 | timeCreated: 1485466566
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Action.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 | using System;
5 |
6 | ///
7 | /// Testing standard C# Action as an event system.
8 | ///
9 | public class Test_Action : MonoBehaviour
10 | {
11 | public Action actionChanged;
12 | private int numReceived = 0;
13 |
14 | public void Init()
15 | {
16 | actionChanged += ReceiveEvent;
17 | }
18 |
19 | public void SendEvent()
20 | {
21 | actionChanged.Invoke(1);
22 | }
23 |
24 | public void ReceiveEvent(int value)
25 | {
26 | numReceived++;
27 | }
28 | }
29 |
30 | /*
31 | Revised BSD License
32 |
33 | Copyright(c) 2018, Garret Polk
34 | All rights reserved.
35 |
36 | Redistribution and use in source and binary forms, with or without
37 | modification, are permitted provided that the following conditions are met:
38 | * Redistributions of source code must retain the above copyright
39 | notice, this list of conditions and the following disclaimer.
40 | * Redistributions in binary form must reproduce the above copyright
41 | notice, this list of conditions and the following disclaimer in the
42 | documentation and/or other materials provided with the distribution.
43 | * Neither the name of the Garret Polk nor the
44 | names of its contributors may be used to endorse or promote products
45 | derived from this software without specific prior written permission.
46 |
47 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
48 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
49 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
51 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
52 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
53 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
54 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
56 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 | */
58 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Action.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 139ea1b67d30d9f4b84e62fa53f2dbd4
3 | timeCreated: 1513113416
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Add_GameObject.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 | using System.Diagnostics;
6 | using System.Text;
7 | using GP.Utils;
8 |
9 | ///
10 | /// Test various C# collections for
11 | /// speed of adding values.
12 | /// (Int32 and GameObjects)
13 | ///
14 | public class Test_Collection_Add_GameObject : MonoBehaviour, ITestController
15 | {
16 | public int numIterations = 1000;
17 | GameObject[] goTests;
18 |
19 | public void Init()
20 | {
21 | goTests = new GameObject[numIterations];
22 | for (int i = 0; i < numIterations; i++)
23 | {
24 | goTests[i] = new GameObject();
25 | }
26 | }
27 | public void Test()
28 | {
29 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : Array, resize");
30 | {
31 | GameObject[] arrayGO = new GameObject[numIterations];
32 | //System.Array.Resize(ref arrayGO, numIterations);
33 | for (int i = 0; i < numIterations; i++)
34 | {
35 | arrayGO[i] = goTests[i];
36 | }
37 | }
38 | UnityEngine.Profiling.Profiler.EndSample();
39 |
40 | // LISTS
41 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : List, resize");
42 | {
43 | List listGO = new List(numIterations);
44 |
45 | for (int i = 0; i < numIterations; i++)
46 | {
47 | listGO.Add(goTests[i]);
48 | }
49 | }
50 | UnityEngine.Profiling.Profiler.EndSample();
51 |
52 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : List");
53 | {
54 | List listGO = new List();
55 |
56 | for (int i = 0; i < numIterations; i++)
57 | {
58 | listGO.Add(goTests[i]);
59 | }
60 | }
61 | UnityEngine.Profiling.Profiler.EndSample();
62 |
63 | // ARRAYLIST
64 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : ArrayList, resize");
65 | {
66 | ArrayList listGO = new ArrayList(numIterations);
67 |
68 | for (int i = 0; i < numIterations; i++)
69 | {
70 | listGO.Add(goTests[i]);
71 | }
72 | }
73 | UnityEngine.Profiling.Profiler.EndSample();
74 |
75 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : ArrayList");
76 | {
77 | ArrayList listGO = new ArrayList();
78 |
79 | for (int i = 0; i < numIterations; i++)
80 | {
81 | listGO.Add(goTests[i]);
82 | }
83 | }
84 | UnityEngine.Profiling.Profiler.EndSample();
85 |
86 |
87 | // HASHSET
88 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : HashSet");
89 | {
90 | HashSet hashset = new HashSet();
91 |
92 | for (int i = 0; i < numIterations; i++)
93 | {
94 | hashset.Add(goTests[i]);
95 | }
96 | }
97 | UnityEngine.Profiling.Profiler.EndSample();
98 |
99 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : Dictionary");
100 | {
101 | Dictionary dict = new Dictionary();
102 |
103 | for (int i = 0; i < numIterations; i++)
104 | {
105 | dict[goTests[i]] = i;
106 | }
107 | }
108 | UnityEngine.Profiling.Profiler.EndSample();
109 |
110 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : Dictionary, resize");
111 | {
112 | Dictionary dict = new Dictionary(numIterations);
113 |
114 | for (int i = 0; i < numIterations; i++)
115 | {
116 | dict[goTests[i]] = i;
117 | }
118 | }
119 | UnityEngine.Profiling.Profiler.EndSample();
120 |
121 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : Stack");
122 | {
123 | Stack stack = new Stack();
124 |
125 | for (int i = 0; i < numIterations; i++)
126 | {
127 | stack.Push(goTests[i]);
128 | }
129 | }
130 | UnityEngine.Profiling.Profiler.EndSample();
131 |
132 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : Stack, resize");
133 | {
134 | Stack stack = new Stack(numIterations);
135 |
136 | for (int i = 0; i < numIterations; i++)
137 | {
138 | stack.Push(goTests[i]);
139 | }
140 | }
141 | UnityEngine.Profiling.Profiler.EndSample();
142 |
143 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : Queue");
144 | {
145 | Queue q = new Queue();
146 |
147 | for (int i = 0; i < numIterations; i++)
148 | {
149 | q.Enqueue(goTests[i]);
150 | }
151 | }
152 | UnityEngine.Profiling.Profiler.EndSample();
153 |
154 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : Queue, resize");
155 | {
156 | Queue q = new Queue(numIterations);
157 |
158 | for (int i = 0; i < numIterations; i++)
159 | {
160 | q.Enqueue(goTests[i]);
161 | }
162 | }
163 | UnityEngine.Profiling.Profiler.EndSample();
164 |
165 | //NEW
166 |
167 | // Generic FastList
168 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : FastList, resize");
169 | FastList abListGOResized = new FastList(numIterations);
170 | for (int i = 0; i < numIterations; i++)
171 | {
172 | abListGOResized.Add(goTests[i]);
173 | }
174 | UnityEngine.Profiling.Profiler.EndSample();
175 |
176 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : FastList");
177 | FastList abListGO = new FastList();
178 | for (int i = 0; i < numIterations; i++)
179 | {
180 | abListGO.Add(goTests[i]);
181 | }
182 | UnityEngine.Profiling.Profiler.EndSample();
183 |
184 | // Specialized FastList
185 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : FastListGO, resize");
186 | FastListGO fastListGOResized = new FastListGO(numIterations);
187 | for (int i = 0; i < numIterations; i++)
188 | {
189 | fastListGOResized.Add(goTests[i]);
190 | }
191 | UnityEngine.Profiling.Profiler.EndSample();
192 |
193 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, GameObject) : FastListGO");
194 | FastListGO fastListGO = new FastListGO();
195 | for (int i = 0; i < numIterations; i++)
196 | {
197 | fastListGO.Add(goTests[i]);
198 | }
199 | UnityEngine.Profiling.Profiler.EndSample();
200 | }
201 | }
202 | /*
203 | Revised BSD License
204 |
205 | Copyright(c) 2018, Garret Polk
206 | All rights reserved.
207 |
208 | Redistribution and use in source and binary forms, with or without
209 | modification, are permitted provided that the following conditions are met:
210 | * Redistributions of source code must retain the above copyright
211 | notice, this list of conditions and the following disclaimer.
212 | * Redistributions in binary form must reproduce the above copyright
213 | notice, this list of conditions and the following disclaimer in the
214 | documentation and/or other materials provided with the distribution.
215 | * Neither the name of the Garret Polk nor the
216 | names of its contributors may be used to endorse or promote products
217 | derived from this software without specific prior written permission.
218 |
219 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
220 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
221 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
222 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
223 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
224 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
225 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
226 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
227 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
228 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
229 | */
230 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Add_GameObject.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 01d07f24ccc7bda45bd0addd343d344b
3 | timeCreated: 1524037184
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Add_Int32.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 | using System.Diagnostics;
6 | using System.Text;
7 | using GP.Utils;
8 |
9 | ///
10 | /// Test various C# collections for
11 | /// speed of adding values.
12 | /// (Int32 and GameObjects)
13 | ///
14 | public class Test_Collection_Add_Int32 : MonoBehaviour, ITestController
15 | {
16 | public int numIterations = 1000;
17 | GameObject[] goTests;
18 |
19 | public void Init()
20 | {
21 | goTests = new GameObject[numIterations];
22 | for (int i = 0; i < numIterations; i++)
23 | {
24 | goTests[i] = new GameObject();
25 | }
26 | }
27 | public void Test()
28 | {
29 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : [], resize");
30 | {
31 | int[] arrayInt = new int[numIterations];
32 | //System.Array.Resize(ref arrayInt, numIterations);
33 | for (int i = 0; i < numIterations; i++)
34 | {
35 | arrayInt[i] = i;
36 | }
37 | }
38 | UnityEngine.Profiling.Profiler.EndSample();
39 |
40 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : Array Class, resize");
41 | {
42 | System.Array arrayClass = System.Array.CreateInstance(typeof(int), numIterations);
43 | //System.Array.Resize(ref arrayInt, numIterations);
44 | for (int i = 0; i < numIterations; i++)
45 | {
46 | arrayClass.SetValue(i, i);
47 | }
48 | }
49 | UnityEngine.Profiling.Profiler.EndSample();
50 |
51 | // LISTS
52 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : List, resize");
53 | {
54 | List listInt = new List(numIterations);
55 |
56 | for (int i = 0; i < numIterations; i++)
57 | {
58 | listInt.Add(i);
59 | }
60 | }
61 | UnityEngine.Profiling.Profiler.EndSample();
62 |
63 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : List");
64 | {
65 | List listInt = new List();
66 |
67 | for (int i = 0; i < numIterations; i++)
68 | {
69 | listInt.Add(i);
70 | }
71 | }
72 | UnityEngine.Profiling.Profiler.EndSample();
73 |
74 | // ARRAYLIST
75 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : ArrayList, resize");
76 | {
77 | ArrayList arrayList = new ArrayList(numIterations);
78 |
79 | for (int i = 0; i < numIterations; i++)
80 | {
81 | arrayList.Add(i);
82 | }
83 | }
84 | UnityEngine.Profiling.Profiler.EndSample();
85 |
86 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : ArrayList");
87 | {
88 | ArrayList listInt = new ArrayList();
89 |
90 | for (int i = 0; i < numIterations; i++)
91 | {
92 | listInt.Add(i);
93 | }
94 | }
95 | UnityEngine.Profiling.Profiler.EndSample();
96 |
97 | // HASHSET
98 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : HashSet");
99 | {
100 | HashSet hashset = new HashSet();
101 |
102 | for (int i = 0; i < numIterations; i++)
103 | {
104 | hashset.Add(i);
105 | }
106 | }
107 | UnityEngine.Profiling.Profiler.EndSample();
108 |
109 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : Dictionary");
110 | {
111 | Dictionary dict = new Dictionary();
112 |
113 | for (int i = 0; i < numIterations; i++)
114 | {
115 | dict[i] = i;
116 | }
117 | }
118 | UnityEngine.Profiling.Profiler.EndSample();
119 |
120 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : Dictionary, resize");
121 | {
122 | Dictionary dict = new Dictionary(numIterations);
123 |
124 | for (int i = 0; i < numIterations; i++)
125 | {
126 | dict[i] = i;
127 | }
128 | }
129 | UnityEngine.Profiling.Profiler.EndSample();
130 |
131 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : Linked List");
132 | {
133 | LinkedList linkedList = new LinkedList();
134 |
135 | for (int i = 0; i < numIterations; i++)
136 | {
137 | linkedList.AddLast(i);
138 | }
139 | }
140 | UnityEngine.Profiling.Profiler.EndSample();
141 |
142 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : Stack");
143 | {
144 | Stack stack = new Stack();
145 |
146 | for (int i = 0; i < numIterations; i++)
147 | {
148 | stack.Push(i);
149 | }
150 | }
151 | UnityEngine.Profiling.Profiler.EndSample();
152 |
153 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : Stack, resize");
154 | {
155 | Stack stack = new Stack(numIterations);
156 |
157 | for (int i = 0; i < numIterations; i++)
158 | {
159 | stack.Push(i);
160 | }
161 | }
162 | UnityEngine.Profiling.Profiler.EndSample();
163 |
164 |
165 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : Queue");
166 | {
167 | Queue q = new Queue();
168 |
169 | for (int i = 0; i < numIterations; i++)
170 | {
171 | q.Enqueue(i);
172 | }
173 | }
174 | UnityEngine.Profiling.Profiler.EndSample();
175 |
176 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : Queue, resize");
177 | {
178 | Queue q = new Queue(numIterations);
179 |
180 | for (int i = 0; i < numIterations; i++)
181 | {
182 | q.Enqueue(i);
183 | }
184 | }
185 | UnityEngine.Profiling.Profiler.EndSample();
186 |
187 | //NEW
188 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : FastList, resize");
189 | FastList abListResized = new FastList(numIterations);
190 | for (int i = 0; i < numIterations; i++)
191 | {
192 | abListResized.Add(i);
193 | }
194 | UnityEngine.Profiling.Profiler.EndSample();
195 |
196 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : FastList");
197 | FastList abList = new FastList();
198 | for (int i = 0; i < numIterations; i++)
199 | {
200 | abList.Add(i);
201 | }
202 | UnityEngine.Profiling.Profiler.EndSample();
203 |
204 | // Specialized list
205 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : FastListInt, resize");
206 | FastListInt fastListIntResized = new FastListInt(numIterations);
207 | for (int i = 0; i < numIterations; i++)
208 | {
209 | fastListIntResized.Add(i);
210 | }
211 | UnityEngine.Profiling.Profiler.EndSample();
212 |
213 | UnityEngine.Profiling.Profiler.BeginSample("Collection (add, Int32) : FastListInt");
214 | FastListInt fastList = new FastListInt();
215 | for (int i = 0; i < numIterations; i++)
216 | {
217 | fastList.Add(i);
218 | }
219 | UnityEngine.Profiling.Profiler.EndSample();
220 | }
221 | }
222 | /*
223 | Revised BSD License
224 |
225 | Copyright(c) 2018, Garret Polk
226 | All rights reserved.
227 |
228 | Redistribution and use in source and binary forms, with or without
229 | modification, are permitted provided that the following conditions are met:
230 | * Redistributions of source code must retain the above copyright
231 | notice, this list of conditions and the following disclaimer.
232 | * Redistributions in binary form must reproduce the above copyright
233 | notice, this list of conditions and the following disclaimer in the
234 | documentation and/or other materials provided with the distribution.
235 | * Neither the name of the Garret Polk nor the
236 | names of its contributors may be used to endorse or promote products
237 | derived from this software without specific prior written permission.
238 |
239 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
240 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
241 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
242 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
243 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
244 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
245 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
246 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
247 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
248 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
249 | */
250 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Add_Int32.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fa03fa202a221f44890bc2ec4e952c70
3 | timeCreated: 1511250506
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Contains_GameObject.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 | using GP.Utils;
6 |
7 | ///
8 | /// Test various C# collections for
9 | /// speed of checking Contains().
10 | /// (GameObjects)
11 | ///
12 | public class Test_Collection_Contains_GameObject : MonoBehaviour, ITestController
13 | {
14 | public static int numIterations = 100;
15 |
16 | GameObject[] checkVals = new GameObject[numIterations];
17 | GameObject[] array = new GameObject[numIterations];
18 | List list = new List(numIterations);
19 | HashSet hashset = new HashSet();
20 | Dictionary dict = new Dictionary(numIterations);
21 | LinkedList linkedList = new LinkedList();
22 | Stack stack = new Stack(numIterations);
23 | Queue q = new Queue(numIterations);
24 | FastListGO fastList = new FastListGO(numIterations);
25 |
26 | public void Init()
27 | {
28 | for (int i = 0; i < numIterations; i++)
29 | {
30 | checkVals[i] = new GameObject();
31 | }
32 | for (int i = 0; i < numIterations; i++)
33 | {
34 | array[i] = checkVals[i];
35 | list.Add(checkVals[i]);
36 | hashset.Add(checkVals[i]);
37 | dict[checkVals[i]] = i;
38 | linkedList.AddLast(checkVals[i]);
39 | stack.Push(checkVals[i]);
40 | q.Enqueue(checkVals[i]);
41 | fastList.Add(checkVals[i]);
42 | }
43 | }
44 |
45 | public void Test()
46 | {
47 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, GameObject) : Array");
48 | {
49 | for (int cv = 0; cv < numIterations; cv++)
50 | {
51 | for (int i = 0; i < numIterations; i++)
52 | {
53 | if (array[i] == checkVals[cv])
54 | break;
55 | }
56 | }
57 | }
58 | UnityEngine.Profiling.Profiler.EndSample();
59 |
60 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, GameObject) : List");
61 | {
62 | for (int cv = 0; cv < numIterations; cv++)
63 | {
64 | if (!list.Contains(checkVals[cv]))
65 | {
66 | Debug.LogError("Bug!");
67 | return;
68 | }
69 | }
70 | }
71 | UnityEngine.Profiling.Profiler.EndSample();
72 |
73 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, GameObject) : List");
74 | {
75 | for (int cv = 0; cv < numIterations; cv++)
76 | {
77 | for (int i = 0; i < numIterations; i++)
78 | {
79 | if (list[i] == checkVals[cv])
80 | break;
81 | }
82 | }
83 | }
84 | UnityEngine.Profiling.Profiler.EndSample();
85 |
86 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, GameObject) : HashSet");
87 | {
88 | for (int cv = 0; cv < numIterations; cv++)
89 | {
90 | if (!hashset.Contains(checkVals[cv]))
91 | {
92 | Debug.LogError("Bug!");
93 | return;
94 | }
95 | }
96 | }
97 | UnityEngine.Profiling.Profiler.EndSample();
98 |
99 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, GameObject) : Dictionary");
100 | {
101 | for (int cv = 0; cv < numIterations; cv++)
102 | {
103 | if (!dict.ContainsKey(checkVals[cv]))
104 | {
105 | Debug.LogError("Bug!");
106 | return;
107 | }
108 | }
109 | }
110 | UnityEngine.Profiling.Profiler.EndSample();
111 |
112 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, GameObject) : Linked List");
113 | {
114 | for (int cv = 0; cv < numIterations; cv++)
115 | {
116 | if (!linkedList.Contains(checkVals[cv]))
117 | {
118 | Debug.LogError("Bug!");
119 | return;
120 | }
121 | }
122 | }
123 | UnityEngine.Profiling.Profiler.EndSample();
124 |
125 |
126 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, GameObject) : Stack");
127 | {
128 | for (int cv = 0; cv < numIterations; cv++)
129 | {
130 | if (!stack.Contains(checkVals[cv]))
131 | {
132 | Debug.LogError("Bug!");
133 | return;
134 | }
135 | }
136 | }
137 | UnityEngine.Profiling.Profiler.EndSample();
138 |
139 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, GameObject) : Queue");
140 | {
141 | for (int cv = 0; cv < numIterations; cv++)
142 | {
143 | if (!q.Contains(checkVals[cv]))
144 | {
145 | Debug.LogError("Bug!");
146 | return;
147 | }
148 | }
149 | }
150 | UnityEngine.Profiling.Profiler.EndSample();
151 |
152 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, GameObject) : FastListGO ");
153 | for (int cv = 0; cv < numIterations; cv++)
154 | {
155 | if (!fastList.Contains(checkVals[cv]))
156 | {
157 | Debug.LogError("Bug!");
158 | return;
159 | }
160 | }
161 | UnityEngine.Profiling.Profiler.EndSample();
162 | }
163 | }
164 |
165 | /*
166 | Revised BSD License
167 |
168 | Copyright(c) 2018, Garret Polk
169 | All rights reserved.
170 |
171 | Redistribution and use in source and binary forms, with or without
172 | modification, are permitted provided that the following conditions are met:
173 | * Redistributions of source code must retain the above copyright
174 | notice, this list of conditions and the following disclaimer.
175 | * Redistributions in binary form must reproduce the above copyright
176 | notice, this list of conditions and the following disclaimer in the
177 | documentation and/or other materials provided with the distribution.
178 | * Neither the name of the Garret Polk nor the
179 | names of its contributors may be used to endorse or promote products
180 | derived from this software without specific prior written permission.
181 |
182 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
183 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
184 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
185 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
186 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
187 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
188 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
189 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
190 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
191 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
192 | */
193 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Contains_GameObject.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c7989179db119cc4b925e0e08dd5a472
3 | timeCreated: 1511339882
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Contains_Int32.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 | using GP.Utils;
6 |
7 | ///
8 | /// Test various C# collections for
9 | /// speed of checking Contains().
10 | /// (Int32)
11 | ///
12 | public class Test_Collection_Contains_Int32 : MonoBehaviour, ITestController
13 | {
14 | // Collection contains random values from 0 to numIteration
15 | public int collectionSize = 1000;
16 |
17 | // Check each collection for each numCheckVals
18 | public static int numCheckVals = 100;
19 |
20 | int[] checkVals;
21 | int[] arrayInt;
22 | List listInt;
23 | HashSet hashset;
24 | Dictionary dict;
25 | LinkedList linkedList;
26 | Stack stack;
27 | Queue q;
28 | FastListInt fastList;
29 | System.Array arrayClass;
30 |
31 | public void Init()
32 | {
33 | checkVals = new int[collectionSize];
34 | arrayInt = new int[collectionSize];
35 | listInt = new List(collectionSize);
36 | hashset = new HashSet();
37 | dict = new Dictionary(collectionSize);
38 | linkedList = new LinkedList();
39 | stack = new Stack(collectionSize);
40 | q = new Queue(collectionSize);
41 | fastList = new FastListInt(collectionSize);
42 | arrayClass = System.Array.CreateInstance(typeof(int), collectionSize);
43 |
44 | for (int i = 0; i < numCheckVals; i++)
45 | {
46 | checkVals[i] = UnityEngine.Random.Range(0, collectionSize);
47 | }
48 | for (int i = 0; i < collectionSize; i++)
49 | {
50 | arrayInt[i] = i;
51 | listInt.Add(i);
52 | hashset.Add(i);
53 | dict[i] = i;
54 | linkedList.AddLast(i);
55 | stack.Push(i);
56 | q.Enqueue(i);
57 | fastList.Add(i);
58 | arrayClass.SetValue(i, i);
59 | }
60 | }
61 |
62 | public void Test()
63 | {
64 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, Int32) : iterate [] : " + collectionSize);
65 | {
66 | for (int cv = 0; cv < numCheckVals; cv++)
67 | {
68 | for (int i = 0; i < collectionSize; i++)
69 | {
70 | if (arrayInt[i] == checkVals[cv])
71 | break;
72 | }
73 | }
74 | }
75 | UnityEngine.Profiling.Profiler.EndSample();
76 |
77 | // GetValue() allocates memory!!??!
78 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, Int32) : iterate Array Class : " + collectionSize);
79 | {
80 | for (int cv = 0; cv < numCheckVals; cv++)
81 | {
82 | for (int i = 0; i < collectionSize; i++)
83 | {
84 | if (arrayClass.GetValue(i).Equals (checkVals[cv]))
85 | break;
86 | }
87 | }
88 | }
89 | UnityEngine.Profiling.Profiler.EndSample();
90 |
91 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, Int32) : List : " + collectionSize);
92 | {
93 | for (int cv = 0; cv < numCheckVals; cv++)
94 | {
95 | if (!listInt.Contains(checkVals[cv]))
96 | {
97 | Debug.LogError("Bug!");
98 | return;
99 | }
100 | }
101 | }
102 | UnityEngine.Profiling.Profiler.EndSample();
103 |
104 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, Int32) : HashSet : " + collectionSize);
105 | {
106 | for (int cv = 0; cv < numCheckVals; cv++)
107 | {
108 | if (!hashset.Contains(checkVals[cv]))
109 | {
110 | Debug.LogError("Bug!");
111 | return;
112 | }
113 | }
114 | }
115 | UnityEngine.Profiling.Profiler.EndSample();
116 |
117 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, Int32) : Dictionary : " + collectionSize);
118 | {
119 | for (int cv = 0; cv < numCheckVals; cv++)
120 | {
121 | if (!dict.ContainsKey(checkVals[cv]))
122 | {
123 | Debug.LogError("Bug!");
124 | return;
125 | }
126 | }
127 | }
128 | UnityEngine.Profiling.Profiler.EndSample();
129 |
130 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, Int32) : Linked List : " + collectionSize);
131 | {
132 | for (int cv = 0; cv < numCheckVals; cv++)
133 | {
134 | if (!linkedList.Contains(checkVals[cv]))
135 | {
136 | Debug.LogError("Bug!");
137 | return;
138 | }
139 | }
140 | }
141 | UnityEngine.Profiling.Profiler.EndSample();
142 |
143 |
144 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, Int32) : Stack : " + collectionSize);
145 | {
146 | for (int cv = 0; cv < numCheckVals; cv++)
147 | {
148 | if (!stack.Contains(checkVals[cv]))
149 | {
150 | Debug.LogError("Bug!");
151 | return;
152 | }
153 | }
154 | }
155 | UnityEngine.Profiling.Profiler.EndSample();
156 |
157 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, Int32) : Queue : " + collectionSize);
158 | {
159 | for (int cv = 0; cv < numCheckVals; cv++)
160 | {
161 | if (!q.Contains(checkVals[cv]))
162 | {
163 | Debug.LogError("Bug!");
164 | return;
165 | }
166 | }
167 | }
168 | UnityEngine.Profiling.Profiler.EndSample();
169 |
170 | UnityEngine.Profiling.Profiler.BeginSample("Collection (contains, Int32) : FastListInt : " + collectionSize);
171 | for (int cv = 0; cv < numCheckVals; cv++)
172 | {
173 | if (!fastList.Contains(checkVals[cv]))
174 | {
175 | Debug.LogError("Bug!");
176 | return;
177 | }
178 | }
179 | UnityEngine.Profiling.Profiler.EndSample();
180 | }
181 | }
182 |
183 | /*
184 | Revised BSD License
185 |
186 | Copyright(c) 2018, Garret Polk
187 | All rights reserved.
188 |
189 | Redistribution and use in source and binary forms, with or without
190 | modification, are permitted provided that the following conditions are met:
191 | * Redistributions of source code must retain the above copyright
192 | notice, this list of conditions and the following disclaimer.
193 | * Redistributions in binary form must reproduce the above copyright
194 | notice, this list of conditions and the following disclaimer in the
195 | documentation and/or other materials provided with the distribution.
196 | * Neither the name of the Garret Polk nor the
197 | names of its contributors may be used to endorse or promote products
198 | derived from this software without specific prior written permission.
199 |
200 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
201 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
202 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
203 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
204 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
205 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
206 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
207 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
208 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
209 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
210 | */
211 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Contains_Int32.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4491a666210c6b049b92fdb66393ac9d
3 | timeCreated: 1511254163
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Iteration_Int32.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 | using System.Diagnostics;
6 | using System.Text;
7 | using GP.Utils;
8 |
9 | ///
10 | /// Test various C# collections for
11 | /// speed of iterating over values.
12 | /// (Int32)
13 | ///
14 | public class Test_Collection_Iteration_Int32 : MonoBehaviour, ITestController
15 | {
16 | public int numItems = 100000;
17 | int[] arrayInt;
18 | List listInt;
19 | HashSet hashset;
20 | Dictionary dict;
21 | LinkedList linkedList;
22 | Stack stack;
23 | Queue q;
24 | FastListInt fastList;
25 | System.Array arrayClass;
26 |
27 | public void Init()
28 | {
29 | arrayInt = new int[numItems];
30 | listInt = new List(numItems);
31 | hashset = new HashSet();
32 | dict = new Dictionary(numItems);
33 | linkedList = new LinkedList();
34 | stack = new Stack(numItems);
35 | q = new Queue(numItems);
36 | fastList = new FastListInt(numItems);
37 | arrayClass = System.Array.CreateInstance(typeof(int), numItems);
38 |
39 | for (int i = 0; i < numItems; i++)
40 | {
41 | arrayInt[i] = i;
42 | listInt.Add(i);
43 | hashset.Add(i);
44 | dict[i] = i;
45 | linkedList.AddLast(i);
46 | stack.Push(i);
47 | q.Enqueue(i);
48 | fastList.Add(i);
49 | arrayClass.SetValue(i, i);
50 | }
51 | }
52 |
53 | public void Test()
54 | {
55 | int item = 0;
56 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : array [] : " + numItems);
57 | {
58 | for (int i = 0; i < numItems; ++i)
59 | {
60 | item = arrayInt[i];
61 | }
62 | }
63 | UnityEngine.Profiling.Profiler.EndSample();
64 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : List[] : " + numItems);
65 | {
66 | for (int i = 0; i < numItems; ++i)
67 | {
68 | item = listInt[i];
69 | }
70 | }
71 | UnityEngine.Profiling.Profiler.EndSample();
72 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : List foreach : " + numItems);
73 | {
74 | foreach (int i in listInt)
75 | {
76 | item = i;
77 | }
78 | }
79 | UnityEngine.Profiling.Profiler.EndSample();
80 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : Hashset foreach : " + numItems);
81 | {
82 | foreach (int i in hashset)
83 | {
84 | item = i;
85 | }
86 | }
87 | UnityEngine.Profiling.Profiler.EndSample();
88 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : Dictionary foreach : " + numItems);
89 | {
90 | foreach (KeyValuePair pair in dict)
91 | {
92 | item = pair.Value;
93 | }
94 | }
95 | UnityEngine.Profiling.Profiler.EndSample();
96 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : Linked List foreach : " + numItems);
97 | {
98 | foreach (int i in linkedList)
99 | {
100 | item = i;
101 | }
102 | }
103 | UnityEngine.Profiling.Profiler.EndSample();
104 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : Stack foreach : " + numItems);
105 | {
106 | foreach (int i in stack)
107 | {
108 | item = i;
109 | }
110 | }
111 | UnityEngine.Profiling.Profiler.EndSample();
112 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : Queue foreach : " + numItems);
113 | {
114 | foreach (int i in q)
115 | {
116 | item = i;
117 | }
118 | }
119 | UnityEngine.Profiling.Profiler.EndSample();
120 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : FastListInt [] : " + numItems);
121 | {
122 | for (int i = 0; i < numItems; ++i)
123 | {
124 | item = fastList[i];
125 | }
126 | }
127 | UnityEngine.Profiling.Profiler.EndSample();
128 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : FastListInt for/GetAt : " + numItems);
129 | {
130 | for (int i = 0; i < numItems; ++i)
131 | {
132 | item = fastList.GetAt(i);
133 | }
134 | }
135 | UnityEngine.Profiling.Profiler.EndSample();
136 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : FastListInt for/RawArray : " + numItems);
137 | {
138 | int[] entries = fastList.RawArray();
139 | for (int i = 0; i < numItems; ++i)
140 | {
141 | item = entries[i];
142 | }
143 | }
144 | UnityEngine.Profiling.Profiler.EndSample();
145 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : FastListInt foreach : " + numItems);
146 | {
147 | foreach (int i in fastList)
148 | {
149 | item = i;
150 | }
151 | }
152 | UnityEngine.Profiling.Profiler.EndSample();
153 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : Array class [] : " + numItems);
154 | {
155 | for (int i = 0; i < numItems; ++i)
156 | {
157 | item = (int)arrayClass.GetValue(i);
158 | }
159 | }
160 | UnityEngine.Profiling.Profiler.EndSample();
161 | UnityEngine.Profiling.Profiler.BeginSample("Collection (iterate, Int32) : Array class foreach : " + numItems);
162 | {
163 | foreach (int i in arrayClass)
164 | {
165 | item = i;
166 | }
167 | }
168 | UnityEngine.Profiling.Profiler.EndSample();
169 | }
170 | }
171 | /*
172 | Revised BSD License
173 |
174 | Copyright(c) 2018, Garret Polk
175 | All rights reserved.
176 |
177 | Redistribution and use in source and binary forms, with or without
178 | modification, are permitted provided that the following conditions are met:
179 | * Redistributions of source code must retain the above copyright
180 | notice, this list of conditions and the following disclaimer.
181 | * Redistributions in binary form must reproduce the above copyright
182 | notice, this list of conditions and the following disclaimer in the
183 | documentation and/or other materials provided with the distribution.
184 | * Neither the name of the Garret Polk nor the
185 | names of its contributors may be used to endorse or promote products
186 | derived from this software without specific prior written permission.
187 |
188 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
189 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
190 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
191 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
192 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
193 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
194 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
195 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
196 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
197 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
198 | */
199 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Iteration_Int32.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c09a90a4b66f47641b4837a43dd48c39
3 | timeCreated: 1537668090
4 | licenseType: Free
5 | MonoImporter:
6 | externalObjects: {}
7 | serializedVersion: 2
8 | defaultReferences: []
9 | executionOrder: 0
10 | icon: {instanceID: 0}
11 | userData:
12 | assetBundleName:
13 | assetBundleVariant:
14 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Remove_Key_Int32.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 |
6 | ///
7 | /// Test various C# collections for
8 | /// speed of removing keys.
9 | /// (Int32)
10 | ///
11 | public class Test_Collection_Remove_Key_Int32 : MonoBehaviour, ITestController
12 | {
13 | public static int numIterations = 100;
14 | HashSet hashset = new HashSet();
15 | Dictionary dict = new Dictionary(numIterations);
16 | LinkedList linkedList = new LinkedList();
17 |
18 | public void Init()
19 | {
20 | for (int i = 0; i < numIterations; i++)
21 | {
22 | hashset.Add(i);
23 | dict[i] = i;
24 | linkedList.AddLast(i);
25 | }
26 | }
27 |
28 | // Remove all, one at a time
29 | public void Test()
30 | {
31 | // Reset
32 | Init();
33 |
34 | UnityEngine.Profiling.Profiler.BeginSample("Collection (remove, key) : HashSet");
35 | {
36 | for (int i = 0; i < numIterations; i++)
37 | {
38 | hashset.Remove(i);
39 | }
40 | }
41 | UnityEngine.Profiling.Profiler.EndSample();
42 |
43 | UnityEngine.Profiling.Profiler.BeginSample("Collection (remove, key) : Dictionary");
44 | {
45 | for (int i = 0; i < numIterations; i++)
46 | {
47 | dict.Remove(i);
48 | }
49 | }
50 | UnityEngine.Profiling.Profiler.EndSample();
51 | }
52 | }
53 |
54 |
55 | /*
56 | Revised BSD License
57 |
58 | Copyright(c) 2018, Garret Polk
59 | All rights reserved.
60 |
61 | Redistribution and use in source and binary forms, with or without
62 | modification, are permitted provided that the following conditions are met:
63 | * Redistributions of source code must retain the above copyright
64 | notice, this list of conditions and the following disclaimer.
65 | * Redistributions in binary form must reproduce the above copyright
66 | notice, this list of conditions and the following disclaimer in the
67 | documentation and/or other materials provided with the distribution.
68 | * Neither the name of the Garret Polk nor the
69 | names of its contributors may be used to endorse or promote products
70 | derived from this software without specific prior written permission.
71 |
72 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
73 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
74 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
75 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
76 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
77 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
78 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
79 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
80 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
81 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
82 | */
83 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Remove_Key_Int32.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9d227c54252465e45b96302acdcab293
3 | timeCreated: 1511255919
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Remove_Value_Int32.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 | using GP.Utils;
6 |
7 | ///
8 | /// Test various C# collections for
9 | /// speed of removing values.
10 | /// (Int32)
11 | ///
12 | public class Test_Collection_Remove_Value_Int32 : MonoBehaviour, ITestController
13 | {
14 | public static int numIterations = 1000;
15 | int[] arrayInt = new int[numIterations];
16 | List listInt = new List(numIterations);
17 | HashSet hashset = new HashSet();
18 | Dictionary dict = new Dictionary(numIterations);
19 | LinkedList linkedList = new LinkedList();
20 | Stack stack = new Stack(numIterations);
21 | Queue q = new Queue(numIterations);
22 | GP.Utils.FastListInt fastList;
23 |
24 | public void Init()
25 | {
26 | if (fastList == null)
27 | fastList = new GP.Utils.FastListInt(numIterations);
28 |
29 | fastList.Clear();
30 | listInt.Clear();
31 | hashset.Clear();
32 | dict.Clear();
33 | linkedList.Clear();
34 | stack.Clear();
35 | q.Clear();
36 |
37 | for (int i = 0; i < numIterations; i++)
38 | {
39 | arrayInt[i] = i;
40 | listInt.Add(i);
41 | hashset.Add(i);
42 | dict[i] = i;
43 | linkedList.AddLast(i);
44 | stack.Push(i);
45 | q.Enqueue(i);
46 | }
47 | }
48 |
49 | // Remove half the values
50 | public void Test()
51 | {
52 | // Reset
53 | Init();
54 |
55 | UnityEngine.Profiling.Profiler.BeginSample("Collection (remove, Int32) : Array");
56 | {
57 | // Technically this isn't removing, just
58 | // setting the value. This won't effect
59 | // memory so it's not exactly comparable.
60 | for (int i = 0; i < numIterations; i++)
61 | {
62 | if (i % 2 == 0)
63 | arrayInt[i] = 0;
64 | }
65 | }
66 | UnityEngine.Profiling.Profiler.EndSample();
67 |
68 | UnityEngine.Profiling.Profiler.BeginSample("Collection (remove, Int32) : List");
69 | {
70 | for (int i = 0; i < numIterations; i++)
71 | {
72 | if (i % 2 == 0)
73 | listInt.Remove(i);
74 | }
75 | }
76 | UnityEngine.Profiling.Profiler.EndSample();
77 |
78 | UnityEngine.Profiling.Profiler.BeginSample("Collection (remove, Int32) : HashSet");
79 | {
80 | for (int i = 0; i < numIterations; i++)
81 | {
82 | if (i % 2 == 0)
83 | hashset.Remove(i);
84 | }
85 | }
86 | UnityEngine.Profiling.Profiler.EndSample();
87 |
88 | UnityEngine.Profiling.Profiler.BeginSample("Collection (remove, Int32) : Dictionary");
89 | {
90 | for ( int i = 0; i < numIterations; i++)
91 | {
92 | if (i % 2 == 0)
93 | dict.Remove(i);
94 | }
95 | }
96 | UnityEngine.Profiling.Profiler.EndSample();
97 |
98 | UnityEngine.Profiling.Profiler.BeginSample("Collection (remove, Int32) : Linked List");
99 | {
100 | for (int i = 0; i < numIterations; i++)
101 | {
102 | if (i % 2 == 0)
103 | linkedList.Remove(i);
104 | }
105 | }
106 | UnityEngine.Profiling.Profiler.EndSample();
107 |
108 | // Stack - not really Remove, but Pop is
109 | // close.
110 | UnityEngine.Profiling.Profiler.BeginSample("Collection (remove, Int32) : Stack");
111 | {
112 | for (int i = 0; i < numIterations; i++)
113 | {
114 | if (i % 2 == 0)
115 | stack.Pop();
116 | }
117 | }
118 | UnityEngine.Profiling.Profiler.EndSample();
119 |
120 | // Queue - not really Remove, but Dequeue is
121 | // close.
122 | UnityEngine.Profiling.Profiler.BeginSample("Collection (remove, Int32) : Queue");
123 | {
124 | for (int i = 0; i < numIterations; i++)
125 | {
126 | if (i % 2 == 0)
127 | q.Dequeue();
128 | }
129 | }
130 | UnityEngine.Profiling.Profiler.EndSample();
131 |
132 | UnityEngine.Profiling.Profiler.BeginSample("Collection (remove, Int32) : FastListInt");
133 | {
134 | for (int i = 0; i < numIterations; i++)
135 | {
136 | if (i % 2 == 0)
137 | fastList.Remove(i);
138 | }
139 | }
140 | UnityEngine.Profiling.Profiler.EndSample();
141 | }
142 | }
143 |
144 | /*
145 | Revised BSD License
146 |
147 | Copyright(c) 2018, Garret Polk
148 | All rights reserved.
149 |
150 | Redistribution and use in source and binary forms, with or without
151 | modification, are permitted provided that the following conditions are met:
152 | * Redistributions of source code must retain the above copyright
153 | notice, this list of conditions and the following disclaimer.
154 | * Redistributions in binary form must reproduce the above copyright
155 | notice, this list of conditions and the following disclaimer in the
156 | documentation and/or other materials provided with the distribution.
157 | * Neither the name of the Garret Polk nor the
158 | names of its contributors may be used to endorse or promote products
159 | derived from this software without specific prior written permission.
160 |
161 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
162 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
163 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
164 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
165 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
166 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
167 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
168 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
169 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
170 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
171 | */
172 |
173 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Collection_Remove_Value_Int32.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4e57ee1f81faaaf4995ce76562b0abc6
3 | timeCreated: 1511255919
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_DictionaryCompare.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using UnityEngine;
5 | using GP.Utils;
6 |
7 | ///
8 | /// Examples of performance improvements with containers.
9 | /// Using containers with keys of type Enum.
10 | ///
11 | public class Test_DictionaryCompare : MonoBehaviour, ITestController
12 | {
13 | public enum TEST_KEY
14 | {
15 | thing1,
16 | thing2,
17 | thing3
18 | }
19 |
20 | public enum TEST_KEY_INT
21 | {
22 | thing1 = 1,
23 | thing2 = 2,
24 | thing3 = 3,
25 | }
26 |
27 | // Use these to avoid GC memory allocations when
28 | // using Enums as a key
29 | Utils_Perf.EnumIntEqComp noboxCompare;
30 | Utils_Perf.EnumIntEqComp noboxCompareInt;
31 |
32 | // Key : string
33 | Dictionary dictStrInt = new Dictionary();
34 |
35 | // Key : int
36 | Dictionary dictIntInt = new Dictionary();
37 |
38 | // Key : enum
39 | Dictionary dictEnumInt = new Dictionary();
40 |
41 | // Key : enum
42 | Dictionary dictEnumIntNoBox;
43 |
44 | // Key : enum of integers
45 | Dictionary dictEnumInt2Int = new Dictionary();
46 |
47 | int numIterations = 1000;
48 |
49 | public void Init()
50 | {
51 | // Dictionaries
52 | noboxCompare = new Utils_Perf.EnumIntEqComp();
53 | dictEnumIntNoBox = new Dictionary(noboxCompare);
54 | dictEnumIntNoBox.Add(TEST_KEY.thing2, 12);
55 |
56 | dictEnumInt2Int = new Dictionary(noboxCompareInt);
57 | dictEnumInt2Int.Add(TEST_KEY_INT.thing2, 12);
58 |
59 | dictEnumInt.Add(TEST_KEY.thing2, 12);
60 | dictIntInt.Add(12, 12);
61 | dictStrInt.Add("12", 12);
62 | }
63 |
64 | public void Test()
65 | {
66 | // Collections
67 |
68 | int number = 0;
69 | // Dictionary of ints
70 | UnityEngine.Profiling.Profiler.BeginSample("Dictionary (iterate and add) : int");
71 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
72 | {
73 | if (dictIntInt.ContainsKey(12))
74 | {
75 | number += dictIntInt[12];
76 | }
77 | }
78 | UnityEngine.Profiling.Profiler.EndSample();
79 |
80 | // Dictionary of strings
81 | // No GC allocs! Wow! ~1.21ms
82 | number = 0;
83 | UnityEngine.Profiling.Profiler.BeginSample("Dictionary (iterate and add) : string");
84 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
85 | {
86 | if (dictStrInt.ContainsKey("12"))
87 | {
88 | number += dictStrInt["12"];
89 | }
90 | }
91 | UnityEngine.Profiling.Profiler.EndSample();
92 |
93 | // Allocs 117.2KB in ~2.03ms
94 | number = 0;
95 | UnityEngine.Profiling.Profiler.BeginSample("Dictionary (iterate and add) : enum, boxing");
96 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
97 | {
98 | if (dictEnumInt.ContainsKey(TEST_KEY.thing2))
99 | {
100 | number += dictEnumInt[TEST_KEY.thing2];
101 | }
102 | }
103 | UnityEngine.Profiling.Profiler.EndSample();
104 |
105 | // No GC allocs in ~1.73ms
106 | number = 0;
107 | UnityEngine.Profiling.Profiler.BeginSample("Dictionary (iterate and add) : enum, no-boxing");
108 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
109 | {
110 | if (dictEnumIntNoBox.ContainsKey(TEST_KEY.thing2))
111 | {
112 | number += dictEnumIntNoBox[TEST_KEY.thing2];
113 | }
114 | }
115 | UnityEngine.Profiling.Profiler.EndSample();
116 |
117 | // Identical performance as EnumNoBoxing
118 | // No GC allocs in ~1.73ms
119 | number = 0;
120 | UnityEngine.Profiling.Profiler.BeginSample("Dictionary (iterate and add) : enum of int");
121 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
122 | {
123 | if (dictEnumInt2Int.ContainsKey(TEST_KEY_INT.thing2))
124 | {
125 | number += dictEnumInt2Int[TEST_KEY_INT.thing2];
126 | }
127 | }
128 | UnityEngine.Profiling.Profiler.EndSample();
129 | }
130 | }
131 | /*
132 | Revised BSD License
133 |
134 | Copyright(c) 2018, Garret Polk
135 | All rights reserved.
136 |
137 | Redistribution and use in source and binary forms, with or without
138 | modification, are permitted provided that the following conditions are met:
139 | * Redistributions of source code must retain the above copyright
140 | notice, this list of conditions and the following disclaimer.
141 | * Redistributions in binary form must reproduce the above copyright
142 | notice, this list of conditions and the following disclaimer in the
143 | documentation and/or other materials provided with the distribution.
144 | * Neither the name of the Garret Polk nor the
145 | names of its contributors may be used to endorse or promote products
146 | derived from this software without specific prior written permission.
147 |
148 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
149 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
150 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
151 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
152 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
153 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
154 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
155 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
156 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
157 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
158 | */
159 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_DictionaryCompare.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 436a11477047ee94cb13c4ca84ea88c1
3 | timeCreated: 1484990081
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Equals.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 | using GP.Utils;
6 |
7 | ///
8 | /// Test speed of == vs. .Equals for various types
9 | ///
10 | public class Test_Equals : MonoBehaviour, ITestController
11 | {
12 | public static int numIterations = 10000;
13 |
14 | public void Init()
15 | {
16 | }
17 |
18 | public void Test()
19 | {
20 | GameObject go1 = new GameObject();
21 | GameObject go2 = new GameObject();
22 |
23 | UnityEngine.Profiling.Profiler.BeginSample("Equals (GameObject) : ==");
24 | {
25 | for (int i = 0; i < numIterations; i++)
26 | {
27 | if (go1 == go2)
28 | Debug.LogError("Bug!");
29 | }
30 | }
31 | UnityEngine.Profiling.Profiler.EndSample();
32 |
33 | UnityEngine.Profiling.Profiler.BeginSample("Equals (GameObject) : .Equals");
34 | {
35 | for (int i = 0; i < numIterations; i++)
36 | {
37 | if (go1.Equals(go2))
38 | Debug.LogError("Bug!");
39 | }
40 | }
41 | UnityEngine.Profiling.Profiler.EndSample();
42 |
43 | UnityEngine.Profiling.Profiler.BeginSample("Equals (GameObject) : !go1");
44 | {
45 | for (int i = 0; i < numIterations; i++)
46 | {
47 | if (!go1)
48 | Debug.LogError("Bug!");
49 | }
50 | }
51 | UnityEngine.Profiling.Profiler.EndSample();
52 |
53 | UnityEngine.Profiling.Profiler.BeginSample("Equals (GameObject) : == null");
54 | {
55 | for (int i = 0; i < numIterations; i++)
56 | {
57 | if (go1 == null)
58 | Debug.LogError("Bug!");
59 | }
60 | }
61 | UnityEngine.Profiling.Profiler.EndSample();
62 |
63 | int i1 = 1;
64 | int i2 = 2;
65 |
66 | UnityEngine.Profiling.Profiler.BeginSample("Equals (int) : ==");
67 | {
68 | for (int i = 0; i < numIterations; i++)
69 | {
70 | if (i1 == i2)
71 | Debug.LogError("Bug!");
72 | }
73 | }
74 | UnityEngine.Profiling.Profiler.EndSample();
75 |
76 | UnityEngine.Profiling.Profiler.BeginSample("Equals (int) : .Equals");
77 | {
78 | for (int i = 0; i < numIterations; i++)
79 | {
80 | if (i1.Equals(i2))
81 | Debug.LogError("Bug!");
82 | }
83 | }
84 | UnityEngine.Profiling.Profiler.EndSample();
85 |
86 | // String
87 | string s1 = "1";
88 | string s2 = "2";
89 |
90 | UnityEngine.Profiling.Profiler.BeginSample("Equals (string) : .Equals");
91 | {
92 | for (int i = 0; i < numIterations; i++)
93 | {
94 | if (s1.Equals(s2))
95 | Debug.LogError("Bug!");
96 | }
97 | }
98 | UnityEngine.Profiling.Profiler.EndSample();
99 |
100 | UnityEngine.Profiling.Profiler.BeginSample("Equals (string) : ==");
101 | {
102 | for (int i = 0; i < numIterations; i++)
103 | {
104 | if (s1 == s2)
105 | Debug.LogError("Bug!");
106 | }
107 | }
108 | UnityEngine.Profiling.Profiler.EndSample();
109 |
110 | // bool
111 | bool b1 = true;
112 | bool b2 = false;
113 |
114 | UnityEngine.Profiling.Profiler.BeginSample("Equals (bool) : .Equals");
115 | {
116 | for (int i = 0; i < numIterations; i++)
117 | {
118 | if (b1.Equals(b2))
119 | Debug.LogError("Bug!");
120 | }
121 | }
122 | UnityEngine.Profiling.Profiler.EndSample();
123 |
124 | UnityEngine.Profiling.Profiler.BeginSample("Equals (bool) : ==");
125 | {
126 | for (int i = 0; i < numIterations; i++)
127 | {
128 | if (b1 == b2)
129 | Debug.LogError("Bug!");
130 | }
131 | }
132 | UnityEngine.Profiling.Profiler.EndSample();
133 | }
134 | }
135 | /*
136 | Revised BSD License
137 |
138 | Copyright(c) 2018, Garret Polk
139 | All rights reserved.
140 |
141 | Redistribution and use in source and binary forms, with or without
142 | modification, are permitted provided that the following conditions are met:
143 | * Redistributions of source code must retain the above copyright
144 | notice, this list of conditions and the following disclaimer.
145 | * Redistributions in binary form must reproduce the above copyright
146 | notice, this list of conditions and the following disclaimer in the
147 | documentation and/or other materials provided with the distribution.
148 | * Neither the name of the Garret Polk nor the
149 | names of its contributors may be used to endorse or promote products
150 | derived from this software without specific prior written permission.
151 |
152 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
153 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
154 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
155 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
156 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
157 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
158 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
159 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
160 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
161 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
162 | */
163 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Equals.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3e7bfa900b00a5e40af1addd2a4dd7b2
3 | timeCreated: 1524094310
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_EventsController.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 |
5 | public class Test_EventsController : MonoBehaviour, ITestController
6 | {
7 | public int numIterations = 1000;
8 | Test_UnityEvents unityEvents;
9 | Test_Action actionEvents;
10 | Test_SendMessage sendMsg;
11 | Test_UnityMessage unityMsg;
12 |
13 | public void Init()
14 | {
15 | unityEvents = GetComponentInChildren();
16 | unityEvents.Init();
17 |
18 | actionEvents = GetComponentInChildren();
19 | actionEvents.Init();
20 |
21 | sendMsg = GetComponentInChildren();
22 | sendMsg.Init();
23 |
24 | unityMsg = GetComponentInChildren();
25 | unityMsg.Init();
26 | }
27 |
28 | public void Test()
29 | {
30 | UnityEngine.Profiling.Profiler.BeginSample("Unity events");
31 | for (int a = 0; a < numIterations; a++)
32 | {
33 | unityEvents.SendEvent();
34 | }
35 | UnityEngine.Profiling.Profiler.EndSample();
36 |
37 | UnityEngine.Profiling.Profiler.BeginSample("Action events");
38 | for (int a = 0; a < numIterations; a++)
39 | {
40 | actionEvents.SendEvent();
41 | }
42 | UnityEngine.Profiling.Profiler.EndSample();
43 |
44 | UnityEngine.Profiling.Profiler.BeginSample("Send message");
45 | for (int a = 0; a < numIterations; a++)
46 | {
47 | sendMsg.SendEvent();
48 | }
49 | UnityEngine.Profiling.Profiler.EndSample();
50 |
51 | UnityEngine.Profiling.Profiler.BeginSample("Unity messaging");
52 | for (int a = 0; a < numIterations; a++)
53 | {
54 | unityMsg.SendEvent();
55 | }
56 | UnityEngine.Profiling.Profiler.EndSample();
57 | }
58 | }
59 | /*
60 | Revised BSD License
61 |
62 | Copyright(c) 2018, Garret Polk
63 | All rights reserved.
64 |
65 | Redistribution and use in source and binary forms, with or without
66 | modification, are permitted provided that the following conditions are met:
67 | * Redistributions of source code must retain the above copyright
68 | notice, this list of conditions and the following disclaimer.
69 | * Redistributions in binary form must reproduce the above copyright
70 | notice, this list of conditions and the following disclaimer in the
71 | documentation and/or other materials provided with the distribution.
72 | * Neither the name of the Garret Polk nor the
73 | names of its contributors may be used to endorse or promote products
74 | derived from this software without specific prior written permission.
75 |
76 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
77 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
78 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
79 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
80 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
81 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
82 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
83 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
84 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
85 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86 | */
87 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_EventsController.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0915dee1d9a4a0e4a8b143e268de4a5f
3 | timeCreated: 1513113416
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_FastList.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 |
6 | ///
7 | /// Performance test for FastList vs. regular List
8 | ///
9 | public class Test_FastList : MonoBehaviour, ITestController
10 | {
11 | public int numIterations = 1000;
12 |
13 | GP.Utils.FastListInt fastListInt;
14 | List listInt;
15 |
16 | public void Init()
17 | {
18 | fastListInt = new GP.Utils.FastListInt(numIterations);
19 | listInt = new List(numIterations);
20 | for (int i = 0; i < numIterations; i++)
21 | {
22 | fastListInt.Add(i);
23 | listInt.Add(i);
24 | }
25 |
26 | }
27 |
28 | bool CheckArray(GP.Utils.FastListInt fastListInt, int[] correctArray)
29 | {
30 | if (fastListInt.Count != correctArray.Length)
31 | return false;
32 |
33 | for (int iCheck = 0; iCheck < correctArray.Length; iCheck++)
34 | {
35 | if (fastListInt[iCheck] != correctArray[iCheck])
36 | return false;
37 | }
38 | return true;
39 | }
40 |
41 | public void Test()
42 | {
43 | // Functional testing of FastList
44 | //
45 | //int[] correctArray = new int[] { 0, 1, 2, 3, 4, 5 };
46 | //GP.Utils.FastListInt fastListInt = new GP.Utils.FastListInt(6);
47 | //fastListInt.Add(0);
48 | //fastListInt.Add(1);
49 | //fastListInt.Add(2);
50 | //fastListInt.Add(2);
51 | //fastListInt.Add(3);
52 | //fastListInt.Add(4);
53 | //fastListInt.Add(5);
54 | //fastListInt.Add(6);
55 | //fastListInt.Remove(2);
56 | //fastListInt.Remove(6);
57 | //if (!CheckArray(fastListInt, correctArray))
58 | // Debug.LogError("BUG");
59 | //fastListInt.RemoveAt (3);
60 | //fastListInt.Insert(3, 3);
61 | //if (!CheckArray(fastListInt, correctArray))
62 | // Debug.LogError("BUG");
63 |
64 | GameObject go = new GameObject();
65 |
66 | // Add
67 | UnityEngine.Profiling.Profiler.BeginSample("FastList (add)");
68 | GP.Utils.FastList fastList = new GP.Utils.FastList();
69 | {
70 | for (int i = 0; i < numIterations; i++)
71 | {
72 | fastList.Add(go);
73 | }
74 | }
75 | UnityEngine.Profiling.Profiler.EndSample();
76 |
77 | UnityEngine.Profiling.Profiler.BeginSample("FastListGO (add)");
78 | GP.Utils.FastListGO fastListGO = new GP.Utils.FastListGO();
79 | {
80 | for (int i = 0; i < numIterations; i++)
81 | {
82 | fastListGO.Add(go);
83 | }
84 | }
85 | UnityEngine.Profiling.Profiler.EndSample();
86 |
87 | UnityEngine.Profiling.Profiler.BeginSample("List (add)");
88 | List list = new List();
89 | {
90 | for (int i = 0; i < numIterations; i++)
91 | {
92 | list.Add(go);
93 | }
94 | }
95 | UnityEngine.Profiling.Profiler.EndSample();
96 |
97 | // Contains
98 | UnityEngine.Profiling.Profiler.BeginSample("FastList (contains)");
99 | {
100 | for (int i = 0; i < numIterations; i++)
101 | {
102 | if (!fastList.Contains(go))
103 | Debug.LogError("Bug!");
104 | }
105 | }
106 | UnityEngine.Profiling.Profiler.EndSample();
107 |
108 | UnityEngine.Profiling.Profiler.BeginSample("FastListGO (contains)");
109 | {
110 | for (int i = 0; i < numIterations; i++)
111 | {
112 | if (!fastListGO.Contains(go))
113 | Debug.LogError("Bug!");
114 | }
115 | }
116 | UnityEngine.Profiling.Profiler.EndSample();
117 |
118 | UnityEngine.Profiling.Profiler.BeginSample("List (contains)");
119 | {
120 | for (int i = 0; i < numIterations; i++)
121 | {
122 | if (!list.Contains(go))
123 | Debug.LogError("Bug!");
124 | }
125 | }
126 | UnityEngine.Profiling.Profiler.EndSample();
127 |
128 | // Sort
129 | UnityEngine.Profiling.Profiler.BeginSample("FastListInt (Sort)");
130 | System.Array.Sort(fastListInt.RawArray(), 0, fastListInt.Count);
131 | UnityEngine.Profiling.Profiler.EndSample();
132 |
133 | UnityEngine.Profiling.Profiler.BeginSample("ListInt (Sort)");
134 | listInt.Sort();
135 | UnityEngine.Profiling.Profiler.EndSample();
136 |
137 |
138 | // Shallow copy
139 | {
140 | UnityEngine.Profiling.Profiler.BeginSample("FastList (CopyTo)");
141 | for (int i = 0; i < numIterations; i++)
142 | {
143 | GP.Utils.FastList fastList2 = new GP.Utils.FastList(0);
144 | fastList.CopyTo(fastList2, 0);
145 | }
146 | UnityEngine.Profiling.Profiler.EndSample();
147 | }
148 |
149 | {
150 | UnityEngine.Profiling.Profiler.BeginSample("FastListGO (CopyTo)");
151 | for (int i = 0; i < numIterations; i++)
152 | {
153 | GP.Utils.FastListGO fastListGO2 = new GP.Utils.FastListGO(0);
154 | fastListGO.CopyTo(fastListGO2, 0);
155 | }
156 | UnityEngine.Profiling.Profiler.EndSample();
157 | }
158 |
159 | {
160 | UnityEngine.Profiling.Profiler.BeginSample("List (CopyTo)");
161 | for (int i = 0; i < numIterations; i++)
162 | {
163 | List list2 = new List(list);
164 | }
165 | UnityEngine.Profiling.Profiler.EndSample();
166 | }
167 |
168 | // foreach
169 | int iAdd = 0;
170 | UnityEngine.Profiling.Profiler.BeginSample("FastList (foreach)");
171 | foreach (GameObject go1 in fastList)
172 | {
173 | if (go1.activeSelf)
174 | iAdd++;
175 | }
176 | UnityEngine.Profiling.Profiler.EndSample();
177 |
178 | UnityEngine.Profiling.Profiler.BeginSample("FastListGO (foreach)");
179 | foreach (GameObject go1 in fastListGO)
180 | {
181 | if (go1.activeSelf)
182 | iAdd++;
183 | }
184 | UnityEngine.Profiling.Profiler.EndSample();
185 |
186 | UnityEngine.Profiling.Profiler.BeginSample("List (foreach)");
187 | foreach (GameObject go1 in list)
188 | {
189 | if (go1.activeSelf)
190 | iAdd++;
191 | }
192 | UnityEngine.Profiling.Profiler.EndSample();
193 |
194 | // for (backwards)
195 | UnityEngine.Profiling.Profiler.BeginSample("FastList (for)");
196 | for (int i = fastList.Count-1; i > 0; i--)
197 | {
198 | if (fastList[i].activeSelf)
199 | iAdd++;
200 | }
201 | UnityEngine.Profiling.Profiler.EndSample();
202 |
203 | UnityEngine.Profiling.Profiler.BeginSample("FastListGO (for)");
204 | for (int i = fastListGO.Count-1; i > 0; i--)
205 | {
206 | if (fastListGO[i].activeSelf)
207 | iAdd++;
208 | }
209 | UnityEngine.Profiling.Profiler.EndSample();
210 |
211 | UnityEngine.Profiling.Profiler.BeginSample("List (for)");
212 | for (int i = list.Count-1; i > 0; i--)
213 | {
214 | if (list[i].activeSelf)
215 | iAdd++;
216 | }
217 | UnityEngine.Profiling.Profiler.EndSample();
218 |
219 |
220 | // RemoveAt for 1/2
221 | UnityEngine.Profiling.Profiler.BeginSample("FastListGO (RemoveAt)");
222 | {
223 | for (int i = 0; i < numIterations / 2; i++)
224 | {
225 | fastListGO.RemoveAt(i);
226 | }
227 | }
228 | UnityEngine.Profiling.Profiler.EndSample();
229 |
230 | UnityEngine.Profiling.Profiler.BeginSample("List (RemoveAt)");
231 | {
232 | int lCount = list.Count / 2;
233 | for (int i = 0; i < lCount; i++)
234 | {
235 | list.RemoveAt(i);
236 | }
237 | }
238 | UnityEngine.Profiling.Profiler.EndSample();
239 |
240 | // Remove
241 | UnityEngine.Profiling.Profiler.BeginSample("FastList (remove)");
242 | {
243 | int flCount = fastList.Count;
244 | for (int i = 0; i < flCount; i++)
245 | {
246 | fastList.Remove(go);
247 | }
248 | }
249 | UnityEngine.Profiling.Profiler.EndSample();
250 |
251 | UnityEngine.Profiling.Profiler.BeginSample("FastListGO (remove)");
252 | {
253 | int flGOCount = fastListGO.Count;
254 | for (int i = 0; i < flGOCount; i++)
255 | {
256 | fastListGO.Remove(go);
257 | }
258 | }
259 | UnityEngine.Profiling.Profiler.EndSample();
260 |
261 |
262 | UnityEngine.Profiling.Profiler.BeginSample("List (remove)");
263 | {
264 | int lCount = list.Count;
265 | for (int i = 0; i < lCount; i++)
266 | {
267 | list.Remove(go);
268 | }
269 | }
270 | UnityEngine.Profiling.Profiler.EndSample();
271 |
272 | // Insert
273 | UnityEngine.Profiling.Profiler.BeginSample("FastList (insert)");
274 | {
275 | for (int i = 0; i < numIterations; i++)
276 | {
277 | fastList.Insert(0, go);
278 | }
279 | }
280 | UnityEngine.Profiling.Profiler.EndSample();
281 |
282 | UnityEngine.Profiling.Profiler.BeginSample("FastListGO (insert)");
283 | {
284 | for (int i = 0; i < numIterations; i++)
285 | {
286 | fastListGO.Insert(0, go);
287 | }
288 | }
289 | UnityEngine.Profiling.Profiler.EndSample();
290 |
291 | UnityEngine.Profiling.Profiler.BeginSample("List (insert)");
292 | {
293 | for (int i = 0; i < numIterations; i++)
294 | {
295 | list.Insert(0, go);
296 | }
297 | }
298 | UnityEngine.Profiling.Profiler.EndSample();
299 |
300 | // Clear
301 | UnityEngine.Profiling.Profiler.BeginSample("FastList (clear)");
302 | {
303 | fastList.Clear();
304 | }
305 | UnityEngine.Profiling.Profiler.EndSample();
306 |
307 | UnityEngine.Profiling.Profiler.BeginSample("FastListGO (clear)");
308 | {
309 | fastListGO.Clear();
310 | }
311 | UnityEngine.Profiling.Profiler.EndSample();
312 |
313 | UnityEngine.Profiling.Profiler.BeginSample("List (clear)");
314 | {
315 | list.Clear();
316 | }
317 | UnityEngine.Profiling.Profiler.EndSample();
318 | }
319 | }
320 | /*
321 | Revised BSD License
322 |
323 | Copyright(c) 2018, Garret Polk
324 | All rights reserved.
325 |
326 | Redistribution and use in source and binary forms, with or without
327 | modification, are permitted provided that the following conditions are met:
328 | * Redistributions of source code must retain the above copyright
329 | notice, this list of conditions and the following disclaimer.
330 | * Redistributions in binary form must reproduce the above copyright
331 | notice, this list of conditions and the following disclaimer in the
332 | documentation and/or other materials provided with the distribution.
333 | * Neither the name of the Garret Polk nor the
334 | names of its contributors may be used to endorse or promote products
335 | derived from this software without specific prior written permission.
336 |
337 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
338 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
339 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
340 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
341 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
342 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
343 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
344 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
345 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
346 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
347 | */
348 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_FastList.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4b0b7dd2061304d4aae3044352a93861
3 | timeCreated: 1524099027
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_GameObject.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using UnityEngine;
5 |
6 | ///
7 | /// Tests speed of caching the GameObject for a MonoBehaviour
8 | ///
9 | public class Test_GameObject : MonoBehaviour
10 | {
11 | public GameObject _go;
12 |
13 | void Awake()
14 | {
15 | _go = gameObject;
16 | }
17 |
18 | // Test doing the least intrusive thing I can think of.
19 | public void Update_GameObject()
20 | {
21 | GameObject goTest = gameObject;
22 | //gameObject.SetActive(true);
23 | }
24 |
25 | // Test doing the least intrusive thing I can think of.
26 | public void Update_CachedGameObject()
27 | {
28 | GameObject goTest = _go;
29 | //_go.SetActive(true);
30 | }
31 | }
32 | /*
33 | Revised BSD License
34 |
35 | Copyright(c) 2018, Garret Polk
36 | All rights reserved.
37 |
38 | Redistribution and use in source and binary forms, with or without
39 | modification, are permitted provided that the following conditions are met:
40 | * Redistributions of source code must retain the above copyright
41 | notice, this list of conditions and the following disclaimer.
42 | * Redistributions in binary form must reproduce the above copyright
43 | notice, this list of conditions and the following disclaimer in the
44 | documentation and/or other materials provided with the distribution.
45 | * Neither the name of the Garret Polk nor the
46 | names of its contributors may be used to endorse or promote products
47 | derived from this software without specific prior written permission.
48 |
49 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
50 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
51 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
52 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
53 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
54 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
55 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
56 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
58 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 | */
60 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_GameObject.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fb1f7cff130036443b2c67958fe33c6f
3 | timeCreated: 1511231669
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_GameObjectController.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 |
5 | ///
6 | /// Test controller for the Test_GameObject class.
7 | ///
8 | public class Test_GameObjectController : MonoBehaviour, ITestController
9 | {
10 | Test_GameObject obj;
11 | private int iterations = 10000;
12 |
13 | // Use this for initialization
14 | public void Init()
15 | {
16 | GameObject go = new GameObject();
17 | obj = go.AddComponent();
18 | }
19 |
20 | // Update is called once per frame
21 | public void Test()
22 | {
23 | UnityEngine.Profiling.Profiler.BeginSample("Access GameObject (cached)");
24 | for (int iObj = 0; iObj < iterations; iObj++)
25 | {
26 | obj.Update_CachedGameObject();
27 | }
28 | UnityEngine.Profiling.Profiler.EndSample();
29 |
30 | UnityEngine.Profiling.Profiler.BeginSample("Access GameObject (standard)");
31 | for (int iObj = 0; iObj < iterations; iObj++)
32 | {
33 | obj.Update_GameObject();
34 | }
35 | UnityEngine.Profiling.Profiler.EndSample();
36 | }
37 | }
38 | /*
39 | Revised BSD License
40 |
41 | Copyright(c) 2018, Garret Polk
42 | All rights reserved.
43 |
44 | Redistribution and use in source and binary forms, with or without
45 | modification, are permitted provided that the following conditions are met:
46 | * Redistributions of source code must retain the above copyright
47 | notice, this list of conditions and the following disclaimer.
48 | * Redistributions in binary form must reproduce the above copyright
49 | notice, this list of conditions and the following disclaimer in the
50 | documentation and/or other materials provided with the distribution.
51 | * Neither the name of the Garret Polk nor the
52 | names of its contributors may be used to endorse or promote products
53 | derived from this software without specific prior written permission.
54 |
55 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
56 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
57 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
58 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
59 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
60 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
61 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
62 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
64 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 | */
66 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_GameObjectController.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e27d27bf714fe804595b85a2d92a64ae
3 | timeCreated: 1511231668
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_List.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 |
6 | ///
7 | /// Test various methods of looping a C# List
8 | ///
9 | public class Test_List : MonoBehaviour, ITestController
10 | {
11 | List scriptList = new List();
12 | private int numIterations = 10000;
13 |
14 | public void Init()
15 | {
16 | // Build the test data
17 | for (int i = 0; i < numIterations; ++i)
18 | {
19 | scriptList.Add(i);
20 | }
21 | }
22 |
23 | public void Test()
24 | {
25 | int iTest = 0;
26 |
27 | // Basic for loop with cached length
28 | UnityEngine.Profiling.Profiler.BeginSample("List : basic loop");
29 | for (int i = 0; i < numIterations; ++i)
30 | {
31 | iTest = scriptList[i];
32 | }
33 | UnityEngine.Profiling.Profiler.EndSample();
34 |
35 | // Basic loop accessing .Count
36 | UnityEngine.Profiling.Profiler.BeginSample("List : using .Count");
37 | for (int i = 0; i < scriptList.Count; i++)
38 | {
39 | iTest = scriptList[i];
40 | }
41 | UnityEngine.Profiling.Profiler.EndSample();
42 |
43 | // foreach()
44 | UnityEngine.Profiling.Profiler.BeginSample("List : foreach()");
45 | foreach ( int i in scriptList)
46 | {
47 | iTest = i;
48 | }
49 | UnityEngine.Profiling.Profiler.EndSample();
50 | }
51 | }
52 |
53 | /*
54 | Revised BSD License
55 |
56 | Copyright(c) 2018, Garret Polk
57 | All rights reserved.
58 |
59 | Redistribution and use in source and binary forms, with or without
60 | modification, are permitted provided that the following conditions are met:
61 | * Redistributions of source code must retain the above copyright
62 | notice, this list of conditions and the following disclaimer.
63 | * Redistributions in binary form must reproduce the above copyright
64 | notice, this list of conditions and the following disclaimer in the
65 | documentation and/or other materials provided with the distribution.
66 | * Neither the name of the Garret Polk nor the
67 | names of its contributors may be used to endorse or promote products
68 | derived from this software without specific prior written permission.
69 |
70 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
71 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
72 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
73 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
74 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
75 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
76 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
77 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
78 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
79 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
80 | */
81 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_List.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b692c423cbce316428df8895a1b76325
3 | timeCreated: 1511249317
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_RayCast.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using GP.Utils;
4 | using System;
5 |
6 | ///
7 | /// Test for the non-allocating Physics functions
8 | ///
9 | public class Test_RayCast : MonoBehaviour, ITestController
10 | {
11 | public int numIterations = 1000;
12 |
13 | public float range = 100;
14 |
15 | [Header ("RaycastHitData")]
16 | [SerializeField]
17 | public RaycastHitData rhd;
18 |
19 | [Space(5)]
20 | [Header("ColliderHitData")]
21 | [SerializeField]
22 | public ColliderHitData chd;
23 |
24 | private LayerMask layerMask;
25 |
26 | public void Init()
27 | {
28 | // Reuse the layermask from RHD for standard Raycast
29 | layerMask = rhd.layerMask;
30 |
31 | if (range == 0)
32 | Debug.LogError("Set the range");
33 | }
34 |
35 | public void Test()
36 | {
37 | //// Example
38 | //RaycastHitData rhd = new RaycastHitData(10);
39 | //if (RaycastHelper.Raycast
40 | // (rhd, Utils_Perf.vec3_zero, Utils_Perf.vec3_forward, 100f))
41 | //{
42 | // // We hit something!
43 | // RaycastHelper.SortByDistance(rhd);
44 | // Debug.Log("Closest hit = " + rhd.hitResults[0].collider.gameObject.name);
45 | //}
46 | float distance = 0;
47 |
48 | // BACKWARDS
49 | UnityEngine.Profiling.Profiler.BeginSample("Raycast (Helper) backwards");
50 | for (int i = 0; i < numIterations; i++)
51 | {
52 | if (!RaycastHelper.Raycast
53 | (rhd, Utils_Perf.vec3_forward * range, Utils_Perf.vec3_back, range))
54 | Debug.LogError("Bug!");
55 | }
56 | UnityEngine.Profiling.Profiler.EndSample();
57 |
58 | UnityEngine.Profiling.Profiler.BeginSample("Raycast (SortResults backwards)");
59 | RaycastHelper.SortByDistanceRev(rhd);
60 | UnityEngine.Profiling.Profiler.EndSample();
61 |
62 | distance = rhd.hitResults[0].distance;
63 | for (int i = 0, iLen = rhd.numHits; i < iLen; ++i)
64 | {
65 | if (distance < rhd.hitResults[i].distance)
66 | Debug.LogError("Bad sort");
67 |
68 | distance = rhd.hitResults[i].distance;
69 | }
70 |
71 | // FORWARDS
72 | UnityEngine.Profiling.Profiler.BeginSample("Raycast (Helper) forward");
73 | for (int i = 0; i < numIterations; i++)
74 | {
75 | if (!RaycastHelper.Raycast
76 | (rhd, Utils_Perf.vec3_zero, Utils_Perf.vec3_forward, range))
77 | Debug.LogError("Bug!");
78 | }
79 | UnityEngine.Profiling.Profiler.EndSample();
80 |
81 | UnityEngine.Profiling.Profiler.BeginSample("Raycast (SortResults forward)");
82 | RaycastHelper.SortByDistance(rhd);
83 | UnityEngine.Profiling.Profiler.EndSample();
84 |
85 | // Test sort
86 | distance = rhd.hitResults[0].distance;
87 | for ( int i = 0, iLen = rhd.numHits; i < iLen; ++i)
88 | {
89 | if (distance > rhd.hitResults[i].distance)
90 | Debug.LogError("Bad sort");
91 |
92 | distance = rhd.hitResults[i].distance;
93 | }
94 |
95 |
96 |
97 |
98 | // REGULAR
99 | UnityEngine.Profiling.Profiler.BeginSample("Raycast (Regular)");
100 | for (int i = 0; i < numIterations; i++)
101 | {
102 | RaycastHit[] hits = Physics.RaycastAll
103 | (Utils_Perf.vec3_zero, Utils_Perf.vec3_forward, range, layerMask);
104 |
105 | if (hits.Length == 0)
106 | Debug.LogError("Bug!");
107 | }
108 | UnityEngine.Profiling.Profiler.EndSample();
109 |
110 | UnityEngine.Profiling.Profiler.BeginSample("SphereCast (Helper)");
111 | for (int i = 0; i < numIterations; i++)
112 | {
113 | if (!RaycastHelper.SphereCast
114 | (rhd, Utils_Perf.vec3_zero, 1f, Utils_Perf.vec3_forward, range))
115 | Debug.LogError("Bug!");
116 | }
117 | UnityEngine.Profiling.Profiler.EndSample();
118 |
119 | // Collider data
120 | UnityEngine.Profiling.Profiler.BeginSample("OverlapSphere (Helper)");
121 | for (int i = 0; i < numIterations; i++)
122 | {
123 | if (!RaycastHelper.OverlapSphere
124 | (chd, Utils_Perf.vec3_zero, range))
125 | Debug.LogError("Bug!");
126 | }
127 | UnityEngine.Profiling.Profiler.EndSample();
128 | }
129 | }
130 |
131 | /*
132 | Revised BSD License
133 |
134 | Copyright(c) 2018, Garret Polk
135 | All rights reserved.
136 |
137 | Redistribution and use in source and binary forms, with or without
138 | modification, are permitted provided that the following conditions are met:
139 | * Redistributions of source code must retain the above copyright
140 | notice, this list of conditions and the following disclaimer.
141 | * Redistributions in binary form must reproduce the above copyright
142 | notice, this list of conditions and the following disclaimer in the
143 | documentation and/or other materials provided with the distribution.
144 | * Neither the name of the Garret Polk nor the
145 | names of its contributors may be used to endorse or promote products
146 | derived from this software without specific prior written permission.
147 |
148 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
149 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
150 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
151 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
152 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
153 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
154 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
155 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
156 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
157 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
158 | */
159 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_RayCast.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3e0fd4b96a0ae7a4ca81101058d01e8e
3 | timeCreated: 1524290201
4 | licenseType: Free
5 | MonoImporter:
6 | externalObjects: {}
7 | serializedVersion: 2
8 | defaultReferences: []
9 | executionOrder: 0
10 | icon: {instanceID: 0}
11 | userData:
12 | assetBundleName:
13 | assetBundleVariant:
14 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_SendMessage.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using System.Collections;
4 |
5 | public class Test_SendMessage : MonoBehaviour
6 | {
7 | int numReceived = 0;
8 |
9 | public void Init()
10 | {
11 |
12 | }
13 |
14 | public void SendEvent()
15 | {
16 | gameObject.SendMessage("ReceiveEvent", 1, SendMessageOptions.RequireReceiver);
17 | }
18 |
19 | public void ReceiveEvent (int value)
20 | {
21 | numReceived++;
22 | }
23 | }
24 |
25 | /*
26 | Revised BSD License
27 |
28 | Copyright(c) 2018, Garret Polk
29 | All rights reserved.
30 |
31 | Redistribution and use in source and binary forms, with or without
32 | modification, are permitted provided that the following conditions are met:
33 | * Redistributions of source code must retain the above copyright
34 | notice, this list of conditions and the following disclaimer.
35 | * Redistributions in binary form must reproduce the above copyright
36 | notice, this list of conditions and the following disclaimer in the
37 | documentation and/or other materials provided with the distribution.
38 | * Neither the name of the Garret Polk nor the
39 | names of its contributors may be used to endorse or promote products
40 | derived from this software without specific prior written permission.
41 |
42 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
43 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
44 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
46 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
47 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
51 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 | */
53 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_SendMessage.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: dbe33a00b6e00ef4c8c2a79ff680888b
3 | timeCreated: 1513117213
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_StringPerf.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using UnityEngine;
5 | using GP.Utils;
6 |
7 | ///
8 | /// Tests the speeds of various methods of String
9 | ///
10 | public class Test_StringPerf : MonoBehaviour, ITestController
11 | {
12 | string s1Test1 = "1Test1";
13 | string sTest = "Test";
14 | string sTest2Test = "Test2Test";
15 | string sT = "T";
16 | string st = "t";
17 | string s2TestTest = "2TestTest";
18 | int numIterations = 1000;
19 |
20 | public void Init()
21 | {
22 | }
23 |
24 | public void Test()
25 | {
26 | int matches = 0;
27 | string sTestTemp = "Test";
28 |
29 | UnityEngine.Profiling.Profiler.BeginSample("String (compare) : Equals");
30 | for (int iTest = 0; iTest < numIterations; iTest++)
31 | {
32 | // Checks to see if the contents of a string
33 | // matches exactly.
34 | if (sTest.Equals(sTestTemp))
35 | matches++;
36 | }
37 | UnityEngine.Profiling.Profiler.EndSample();
38 | if (matches != numIterations)
39 | Debug.LogError("Mismatch");
40 |
41 | matches = 0;
42 | UnityEngine.Profiling.Profiler.BeginSample("String (compare) : ==");
43 |
44 | for (int iTest = 0; iTest < numIterations; iTest++)
45 | {
46 | // Checks to see if the contents of a string
47 | // matches exactly.
48 | if (sTest == sTestTemp)
49 | matches++;
50 | }
51 | UnityEngine.Profiling.Profiler.EndSample();
52 | if (matches != numIterations)
53 | Debug.LogError("Mismatch");
54 |
55 | matches = 0;
56 | UnityEngine.Profiling.Profiler.BeginSample("String (compare) : CompareTo");
57 | for (int iTest = 0; iTest < numIterations; iTest++)
58 | {
59 | // Used primarily for sorting, esp. on
60 | // localized strings. C# can do the localized
61 | // sort for you! But...
62 | //
63 | // 0 == CompareTo() is 70x slower than Equals()
64 | if (0 == sTest.CompareTo(sTestTemp))
65 | matches++;
66 | }
67 | UnityEngine.Profiling.Profiler.EndSample();
68 | if (matches != numIterations)
69 | Debug.LogError("Mismatch");
70 |
71 | // CONTAINS
72 | matches = 0;
73 | UnityEngine.Profiling.Profiler.BeginSample("String (contains) : Contains");
74 | for (int iTest = 0; iTest < numIterations; iTest++)
75 | {
76 | // String.Contains() calls String.IndexOf()
77 | // which calls CultureInfo stuff, which is slow.
78 | if (s1Test1.Contains(sTest))
79 | matches++;
80 | }
81 | UnityEngine.Profiling.Profiler.EndSample();
82 | if (matches != numIterations)
83 | Debug.LogError("Mismatch");
84 |
85 | matches = 0;
86 | UnityEngine.Profiling.Profiler.BeginSample("String (contains) : byte-wise contains");
87 | for (int iTest = 0; iTest < numIterations; iTest++)
88 | {
89 | if (Utils_Perf.Contains(s1Test1, sTest))
90 | matches++;
91 | }
92 |
93 | //// For testing
94 | //// false
95 | //if (Utils_Perf.Contains(sTest2Test, s2TestTest))
96 | // matches++;
97 |
98 | UnityEngine.Profiling.Profiler.EndSample();
99 | if (matches != numIterations)
100 | Debug.LogError("Mismatch");
101 |
102 | // Ends With
103 | matches = 0;
104 | UnityEngine.Profiling.Profiler.BeginSample("String (EndsWith) : EndsWith");
105 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
106 | {
107 | if (sTest2Test.EndsWith(sTest))
108 | matches++;
109 | }
110 |
111 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
112 | {
113 | if (sTest2Test.EndsWith(st))
114 | matches++;
115 | }
116 |
117 | // False
118 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
119 | {
120 | if (sTest2Test.EndsWith(sT))
121 | matches++;
122 | }
123 | UnityEngine.Profiling.Profiler.EndSample();
124 | if (matches != numIterations * 2)
125 | Debug.LogError("Mismatch");
126 |
127 | matches = 0;
128 | UnityEngine.Profiling.Profiler.BeginSample("String (EndsWith) : byte-wise EndsWith");
129 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
130 | {
131 | if (Utils_Perf.EndsWith(sTest2Test, sTest))
132 | matches++;
133 | }
134 |
135 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
136 | {
137 | if (Utils_Perf.EndsWith(sTest2Test, st))
138 | matches++;
139 | }
140 |
141 | // False
142 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
143 | {
144 | if (Utils_Perf.EndsWith(sTest2Test, sT))
145 | matches++;
146 | }
147 | UnityEngine.Profiling.Profiler.EndSample();
148 | if (matches != numIterations * 2)
149 | Debug.LogError("Mismatch");
150 |
151 | // Starts with
152 | matches = 0;
153 | UnityEngine.Profiling.Profiler.BeginSample("String (StartsWith) : StartsWith");
154 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
155 | {
156 | if (sTest2Test.StartsWith(sTest))
157 | matches++;
158 | }
159 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
160 | {
161 | if (sTest2Test.StartsWith(sT))
162 | matches++;
163 | }
164 |
165 | // False
166 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
167 | {
168 | if (sTest2Test.StartsWith(st))
169 | matches++;
170 | }
171 | UnityEngine.Profiling.Profiler.EndSample();
172 | if (matches != numIterations * 2)
173 | Debug.LogError("Mismatch");
174 |
175 | matches = 0;
176 | UnityEngine.Profiling.Profiler.BeginSample("String (StartsWith) : byte-wise StartsWith");
177 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
178 | {
179 | if (Utils_Perf.StartsWith(sTest2Test, sTest))
180 | matches++;
181 | }
182 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
183 | {
184 | if (Utils_Perf.StartsWith(sTest2Test, sT))
185 | matches++;
186 | }
187 |
188 | // False
189 | for (int iLoop = 0; iLoop < numIterations; iLoop++)
190 | {
191 | if (Utils_Perf.StartsWith(sTest2Test, st))
192 | matches++;
193 | }
194 | UnityEngine.Profiling.Profiler.EndSample();
195 | if (matches != numIterations * 2)
196 | Debug.LogError("Mismatch");
197 | }
198 | }
199 |
200 | /*
201 | Revised BSD License
202 |
203 | Copyright(c) 2018, Garret Polk
204 | All rights reserved.
205 |
206 | Redistribution and use in source and binary forms, with or without
207 | modification, are permitted provided that the following conditions are met:
208 | * Redistributions of source code must retain the above copyright
209 | notice, this list of conditions and the following disclaimer.
210 | * Redistributions in binary form must reproduce the above copyright
211 | notice, this list of conditions and the following disclaimer in the
212 | documentation and/or other materials provided with the distribution.
213 | * Neither the name of the Garret Polk nor the
214 | names of its contributors may be used to endorse or promote products
215 | derived from this software without specific prior written permission.
216 |
217 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
218 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
219 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
220 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
221 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
222 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
223 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
224 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
225 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
226 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
227 | */
228 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_StringPerf.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8281cef8972b55142856bfd7341b78a0
3 | timeCreated: 1485465666
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Transform.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using UnityEngine;
5 |
6 | ///
7 | /// Some sample code was taken from the slides of Søren Trautner Madsen
8 | /// from the talk/video below. soren@playdead.com
9 | ///
10 | /// https://docs.google.com/presentation/d/1dew0TynVmtQf8OMLEz_YtRxK32a_0SAZU9-vgyMRPlA
11 | /// https://www.youtube.com/watch?v=mQ2KTRn4BMI&t
12 | ///
13 | /// Performance improvements using a GameObject transform
14 | ///
15 | public class Test_Transform : MonoBehaviour
16 | {
17 | // getter/setter versions
18 | public float gsSpeed { get; set; }
19 | public float gsSpeedfactor { get; set; }
20 | public float gsSomeOtherFactor { get; set; }
21 | public float gsDrag { get; set; }
22 | public float gsFriction { get; set; }
23 |
24 | // raw public variable versions
25 | public float speed;
26 | public float speedfactor;
27 | public float someOtherFactor;
28 | public float drag;
29 | public float friction;
30 |
31 | public Vector3 wantedVelocity;
32 |
33 | // Variable caching
34 | Transform _transform;
35 | Vector3 cachedLocalPosition;
36 | public static float globalDeltaTime;
37 |
38 | void Start()
39 | {
40 | _transform = transform;
41 | cachedLocalPosition = _transform.localPosition;
42 |
43 | // Make sure the character is actually moving.
44 | // -- Garret Polk
45 | speed = .01f;
46 | speedfactor = 1f;
47 | someOtherFactor = 5f;
48 | drag = 1f;
49 | friction = 1f;
50 | wantedVelocity = Vector3.one;
51 |
52 | gsSpeed = .01f;
53 | gsSpeedfactor = 1f;
54 | gsSomeOtherFactor = 5f;
55 | gsDrag = 1f;
56 | gsFriction = 1f;
57 |
58 | }
59 |
60 | ///
61 | /// This is typical Update() code to move a GameObject.
62 | /// We can make it faster with some changes.
63 | ///
64 | public void UpdateCharacter()
65 | {
66 | Vector3 lastPos = transform.position;
67 | transform.position = lastPos
68 | + wantedVelocity * speed * speedfactor
69 | * Mathf.Sin(someOtherFactor)
70 | * drag * friction * Time.deltaTime;
71 | }
72 |
73 | ///
74 | /// Move all floating point operations together,
75 | /// then apply the result ONCE to the Vector of wantedVelocity.
76 | ///
77 | public void UpdateCharacter_ReduceVectorOps()
78 | {
79 | Vector3 lastPos = transform.position;
80 | transform.position = lastPos
81 | + wantedVelocity * (speed * speedfactor
82 | * Mathf.Sin(someOtherFactor)
83 | * drag * friction * Time.deltaTime);
84 | }
85 |
86 | ///
87 | /// Cache the GameObject.transform. Yeah, I thought
88 | /// Unity takes care of this too, but look at the performance
89 | /// difference!
90 | ///
91 | public void UpdateCharacter_CachedTransforms()
92 | {
93 | Vector3 lastPos = _transform.position; //cached in “void Start()”
94 | _transform.position = lastPos
95 | + wantedVelocity * (speed * speedfactor
96 | * Mathf.Sin(someOtherFactor)
97 | * drag * friction * Time.deltaTime);
98 | }
99 |
100 | ///
101 | /// Use tranform.localPosition instead of the world position
102 | /// of transform.position.
103 | ///
104 | public void UpdateCharacter_LocalPosition()
105 | {
106 | Vector3 lastPos = _transform.localPosition;
107 | _transform.localPosition = lastPos
108 | + wantedVelocity * (speed * speedfactor
109 | * Mathf.Sin(someOtherFactor)
110 | * drag * friction * Time.deltaTime);
111 | }
112 |
113 | ///
114 | /// Cache the local position. Note : you will have
115 | /// to insure that other code doesn't directly modify
116 | /// the localPosition or it will get out of sync.
117 | ///
118 | public void UpdateCharacter_ReduceEngineCalls()
119 | {
120 | cachedLocalPosition += wantedVelocity * (speed * speedfactor
121 | * Mathf.Sin(someOtherFactor)
122 | * drag * friction * Time.deltaTime);
123 | _transform.localPosition = cachedLocalPosition;
124 | }
125 |
126 | ///
127 | /// Set the individual axis values ourselves.
128 | ///
129 | public void UpdateCharacter_NoVectorMath()
130 | {
131 | float factor = speed * speedfactor
132 | * Mathf.Sin(someOtherFactor)
133 | * drag * friction * Time.deltaTime;
134 |
135 | cachedLocalPosition.x += wantedVelocity.x * factor;
136 | cachedLocalPosition.y += wantedVelocity.y * factor;
137 | cachedLocalPosition.z += wantedVelocity.z * factor;
138 | _transform.localPosition = cachedLocalPosition;
139 | }
140 |
141 | ///
142 | /// This shows the impact of get/set instead of
143 | /// raw public variables.
144 | ///
145 | public void UpdateCharacter_CacheDeltaTimeGetSet()
146 | {
147 | float factor = gsSpeed * gsSpeedfactor
148 | * Mathf.Sin(gsSomeOtherFactor)
149 | * gsDrag * gsFriction * globalDeltaTime;
150 |
151 | cachedLocalPosition.x += wantedVelocity.x * factor;
152 | cachedLocalPosition.y += wantedVelocity.y * factor;
153 | cachedLocalPosition.z += wantedVelocity.z * factor;
154 | _transform.localPosition = cachedLocalPosition;
155 | }
156 |
157 | ///
158 | /// ** Fastest code, best example **
159 | ///
160 | /// Avoid calling Time.deltaTime more than once.
161 | /// We cache it and set it in the Controller code.
162 | ///
163 | public void UpdateCharacter_CacheDeltaTime()
164 | {
165 | float factor = speed * speedfactor
166 | * Mathf.Sin(someOtherFactor)
167 | * drag * friction * globalDeltaTime;
168 |
169 | cachedLocalPosition.x += wantedVelocity.x * factor;
170 | cachedLocalPosition.y += wantedVelocity.y * factor;
171 | cachedLocalPosition.z += wantedVelocity.z * factor;
172 | _transform.localPosition = cachedLocalPosition;
173 | }
174 | }
175 |
176 | /*
177 | Revised BSD License
178 |
179 | Copyright(c) 2018, Garret Polk
180 | All rights reserved.
181 |
182 | Redistribution and use in source and binary forms, with or without
183 | modification, are permitted provided that the following conditions are met:
184 | * Redistributions of source code must retain the above copyright
185 | notice, this list of conditions and the following disclaimer.
186 | * Redistributions in binary form must reproduce the above copyright
187 | notice, this list of conditions and the following disclaimer in the
188 | documentation and/or other materials provided with the distribution.
189 | * Neither the name of the Garret Polk nor the
190 | names of its contributors may be used to endorse or promote products
191 | derived from this software without specific prior written permission.
192 |
193 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
194 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
195 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
196 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
197 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
198 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
199 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
200 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
201 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
202 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
203 | */
204 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_Transform.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 68873196c6882a544ac2fa359d816010
3 | timeCreated: 1481251334
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_TransformController.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using UnityEngine;
5 |
6 | ///
7 | /// Some sample code was taken from the slides of Søren Trautner Madsen
8 | /// from the talk/video below. soren@playdead.com
9 | ///
10 | /// https://docs.google.com/presentation/d/1dew0TynVmtQf8OMLEz_YtRxK32a_0SAZU9-vgyMRPlA
11 | /// https://www.youtube.com/watch?v=mQ2KTRn4BMI&t
12 | ///
13 | /// Performance improvements using a GameObject transform
14 | ///
15 | public class Test_TransformController : MonoBehaviour, ITestController
16 | {
17 | public Test_Transform objTest;
18 | private int numIterations = 1000;
19 |
20 | public void Init()
21 | {
22 | if (objTest == null)
23 | Debug.LogError("No test object");
24 | }
25 |
26 | public void Test()
27 | {
28 | Test_Transform.globalDeltaTime = Time.deltaTime;
29 |
30 | // do a lot of iterations:
31 | UnityEngine.Profiling.Profiler.BeginSample("Transform");
32 | for (int a = 0; a < numIterations; a++)
33 | {
34 | objTest.UpdateCharacter();
35 | }
36 | UnityEngine.Profiling.Profiler.EndSample();
37 |
38 | UnityEngine.Profiling.Profiler.BeginSample("Transform : Reduce vector ops");
39 | for (int a = 0; a < numIterations; a++)
40 | {
41 | objTest.UpdateCharacter_ReduceVectorOps();
42 | }
43 | UnityEngine.Profiling.Profiler.EndSample();
44 |
45 | UnityEngine.Profiling.Profiler.BeginSample("Transform : Cached transforms");
46 | for (int a = 0; a < numIterations; a++)
47 | {
48 | objTest.UpdateCharacter_CachedTransforms();
49 | }
50 | UnityEngine.Profiling.Profiler.EndSample();
51 |
52 | UnityEngine.Profiling.Profiler.BeginSample("Transform : Local position");
53 | for (int a = 0; a < numIterations; a++)
54 | {
55 | objTest.UpdateCharacter_LocalPosition();
56 | }
57 | UnityEngine.Profiling.Profiler.EndSample();
58 |
59 | UnityEngine.Profiling.Profiler.BeginSample("Transform : Reduce engine calls");
60 | for (int a = 0; a < numIterations; a++)
61 | {
62 | objTest.UpdateCharacter_ReduceEngineCalls();
63 | }
64 | UnityEngine.Profiling.Profiler.EndSample();
65 |
66 | UnityEngine.Profiling.Profiler.BeginSample("Transform : No vector math");
67 | for (int a = 0; a < numIterations; a++)
68 | {
69 | objTest.UpdateCharacter_NoVectorMath();
70 | }
71 | UnityEngine.Profiling.Profiler.EndSample();
72 |
73 | UnityEngine.Profiling.Profiler.BeginSample("Transform : Cache delta time (get/set)");
74 | for (int a = 0; a < numIterations; a++)
75 | {
76 | objTest.UpdateCharacter_CacheDeltaTimeGetSet();
77 | }
78 | UnityEngine.Profiling.Profiler.EndSample();
79 |
80 | UnityEngine.Profiling.Profiler.BeginSample("Transform : Cache delta time");
81 | for (int a = 0; a < numIterations; a++)
82 | {
83 | objTest.UpdateCharacter_CacheDeltaTime();
84 | }
85 | UnityEngine.Profiling.Profiler.EndSample();
86 | }
87 | }
88 |
89 | /*
90 | Revised BSD License
91 |
92 | Copyright(c) 2018, Garret Polk
93 | All rights reserved.
94 |
95 | Redistribution and use in source and binary forms, with or without
96 | modification, are permitted provided that the following conditions are met:
97 | * Redistributions of source code must retain the above copyright
98 | notice, this list of conditions and the following disclaimer.
99 | * Redistributions in binary form must reproduce the above copyright
100 | notice, this list of conditions and the following disclaimer in the
101 | documentation and/or other materials provided with the distribution.
102 | * Neither the name of the Garret Polk nor the
103 | names of its contributors may be used to endorse or promote products
104 | derived from this software without specific prior written permission.
105 |
106 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
107 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
108 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
109 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
110 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
111 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
112 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
113 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
114 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
115 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
116 | */
117 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_TransformController.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c695a47a40dc7904785385c7878f0201
3 | timeCreated: 1481251298
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_UnityEvents.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using UnityEngine.Events;
4 | using System.Collections;
5 | using System;
6 |
7 | ///
8 | /// Testing Unity events
9 | /// See also : https://jacksondunstan.com/articles/3335
10 | ///
11 | public class Test_UnityEvents : MonoBehaviour
12 | {
13 | // An event that sends an int
14 | // These allocate!
15 | [Serializable]
16 | public class TestIntEvent : UnityEvent {}
17 | public TestIntEvent evtInt = new TestIntEvent();
18 |
19 | // An event with no parameters
20 | // This does not allocate
21 | public UnityEvent evt = new UnityEvent();
22 |
23 | // Just a fake value so the function isn't
24 | // optimized out by the compiler.
25 | int numReceived = 0;
26 |
27 | public void Init()
28 | {
29 | //evt.AddListener(ReceiveEvent);
30 | evtInt.AddListener(ReceiveEventInt);
31 | }
32 |
33 | public void SendEvent()
34 | {
35 | //evt.Invoke();
36 | evtInt.Invoke(1);
37 | }
38 |
39 | public void ReceiveEventInt(int value)
40 | {
41 | numReceived++;
42 | }
43 |
44 | public void ReceiveEvent()
45 | {
46 | numReceived++;
47 | }
48 | }
49 | /*
50 | Revised BSD License
51 |
52 | Copyright(c) 2018, Garret Polk
53 | All rights reserved.
54 |
55 | Redistribution and use in source and binary forms, with or without
56 | modification, are permitted provided that the following conditions are met:
57 | * Redistributions of source code must retain the above copyright
58 | notice, this list of conditions and the following disclaimer.
59 | * Redistributions in binary form must reproduce the above copyright
60 | notice, this list of conditions and the following disclaimer in the
61 | documentation and/or other materials provided with the distribution.
62 | * Neither the name of the Garret Polk nor the
63 | names of its contributors may be used to endorse or promote products
64 | derived from this software without specific prior written permission.
65 |
66 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
67 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
68 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
69 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
70 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
71 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
72 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
73 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
74 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
75 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
76 | */
77 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_UnityEvents.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1755b512b38a9a9449a7910dcc8b429f
3 | timeCreated: 1513113416
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_UnityMessage.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using UnityEngine;
3 | using UnityEngine.EventSystems;
4 | using System.Collections;
5 |
6 | public interface IMsgTest : IEventSystemHandler
7 | {
8 | void ReceiveEvent(int value);
9 | }
10 |
11 | public class Test_UnityMessage :
12 | MonoBehaviour,
13 | IMsgTest
14 | {
15 | int numReceived = 0;
16 |
17 | public void Init()
18 | {
19 |
20 | }
21 |
22 | public void SendEvent()
23 | {
24 | ExecuteEvents.Execute(gameObject, null, (x,y) => x.ReceiveEvent(1));
25 | }
26 |
27 | public void ReceiveEvent(int value)
28 | {
29 | numReceived++;
30 | }
31 | }
32 |
33 | /*
34 | Revised BSD License
35 |
36 | Copyright(c) 2018, Garret Polk
37 | All rights reserved.
38 |
39 | Redistribution and use in source and binary forms, with or without
40 | modification, are permitted provided that the following conditions are met:
41 | * Redistributions of source code must retain the above copyright
42 | notice, this list of conditions and the following disclaimer.
43 | * Redistributions in binary form must reproduce the above copyright
44 | notice, this list of conditions and the following disclaimer in the
45 | documentation and/or other materials provided with the distribution.
46 | * Neither the name of the Garret Polk nor the
47 | names of its contributors may be used to endorse or promote products
48 | derived from this software without specific prior written permission.
49 |
50 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
51 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
52 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
53 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
54 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
55 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
56 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
57 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 | */
61 |
--------------------------------------------------------------------------------
/Assets/Scripts/Test_UnityMessage.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4dc5ab319b9db0148a1d8293adc60100
3 | timeCreated: 1513116800
4 | licenseType: Free
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Assets/Scripts/Utils_Perf.cs:
--------------------------------------------------------------------------------
1 | // Revised BSD License text at bottom
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using UnityEngine;
5 |
6 | namespace GP.Utils
7 | {
8 | // Unite Europe 2016 - Optimizing Mobile Applications
9 | // https://www.youtube.com/watch?v=j4YAY36xjwE
10 | //
11 | // Unity US 2016 - Let's Talk (Content) Optimization
12 | // https://www.youtube.com/watch?v=n-oZa4Fb12U
13 |
14 | ///
15 | /// Performance utility code
16 | ///
17 | public class Utils_Perf
18 | {
19 | ///
20 | /// Static values with no accessor functions to slow them down.
21 | /// About 4x faster than Vector3.zero
22 | ///
23 | public static readonly Vector3 vec3_back = Vector3.back;
24 | public static readonly Vector3 vec3_down = Vector3.down;
25 | public static readonly Vector3 vec3_forward = Vector3.forward;
26 | public static readonly Vector3 vec3_left = Vector3.left;
27 | public static readonly Vector3 vec3_right = Vector3.right;
28 | public static readonly Vector3 vec3_up = Vector3.up;
29 | public static readonly Vector3 vec3_one = Vector3.one;
30 | public static readonly Vector3 vec3_zero = Vector3.zero;
31 |
32 | ///
33 | /// Static values with no accessor functions to slow them down.
34 | /// About 4x faster than Quaternion.identity
35 | ///
36 | public static readonly Quaternion quat_identity = Quaternion.identity;
37 |
38 | ///
39 | /// Does s1 start with s2?
40 | /// Strict byte for byte comparison, nothing fancy.
41 | /// About 100x as fast as String.StartsWith()
42 | ///
43 | /// Longer string
44 | /// Shorter string
45 | /// true, if s1 starts with s2
46 | public static bool StartsWith(string s1, string s2)
47 | {
48 | return StartsWith(s1, s2, 0);
49 | }
50 |
51 | ///
52 | /// Does s1 start with s2?
53 | /// Strict byte for byte comparison, nothing fancy.
54 | /// About 100x as fast as String.StartsWith()
55 | ///
56 | /// Longer string
57 | /// Shorter string
58 | /// Start checking at this index of s1
59 | /// true, if s1 starts with s2
60 | public static bool StartsWith(string s1, string s2, int startIndex)
61 | {
62 | if (string.IsNullOrEmpty(s1) || string.IsNullOrEmpty(s2))
63 | return false;
64 |
65 | // We need the index end
66 | int s1Len = s1.Length;
67 | int s2Len = s2.Length;
68 |
69 | // Too short?
70 | if (s1Len < s2Len)
71 | return false;
72 |
73 | for (int iChar = startIndex; iChar < s2Len; iChar++)
74 | {
75 | if (s1[iChar] != s2[iChar])
76 | return false;
77 | }
78 |
79 | return true;
80 | }
81 |
82 | ///
83 | /// Does s1 end with s2?
84 | /// Strict byte for byte comparison, nothing fancy.
85 | /// About 100x as fast as String.EndsWith()
86 | ///
87 | /// Longer string
88 | /// Shorter string
89 | /// true, if s1 ends with s2
90 | public static bool EndsWith(string s1, string s2)
91 | {
92 | if (string.IsNullOrEmpty(s1) || string.IsNullOrEmpty(s2))
93 | return false;
94 |
95 | int s1Len = s1.Length - 1;
96 | int s2Len = s2.Length - 1;
97 |
98 | // Too short?
99 | if (s1Len < s2Len)
100 | return false;
101 |
102 | for (int iChar = 0; iChar <= s2Len; iChar++)
103 | {
104 | if (s1[s1Len - iChar] != s2[s2Len - iChar])
105 | return false;
106 | }
107 |
108 | return true;
109 | }
110 |
111 | ///
112 | /// About 3x faster than String.Contains()
113 | ///
114 | /// Byte by byte comparison
115 | /// Doesn't use language features of C#
116 | ///
117 | /// With Equals(s1) vs. Equals(s1, StringComparison.Ordinal)
118 | /// regular String.Equals() is much faster. The Ordinal
119 | /// one calls into String.Compare() for some reason
120 | /// which is much slower. Bizarre.
121 | ///
122 | ///
123 | ///
124 | /// true, if s1 contains s2 in it anywhere.
125 | public static bool Contains(string s1, string s2)
126 | {
127 | if (string.IsNullOrEmpty(s1))
128 | return false;
129 |
130 | // s1 always contains an empty string
131 | // Matching String.Contains() behavior
132 | if (string.IsNullOrEmpty(s2))
133 | return true;
134 |
135 | // Example:
136 | // 0123456789
137 | // 789
138 | // We only need to check the first string up to
139 | // the last 3 characters.
140 |
141 | // Length we need to check the first string
142 | int s1Len = s1.Length - s2.Length + 1;
143 | int s2Len = s2.Length;
144 | int iChar2 = 0;
145 | bool match = false;
146 |
147 | for (int iChar1 = 0; iChar1 < s1Len; iChar1++)
148 | {
149 | // Found a possible match
150 | if (s1[iChar1] == s2[0])
151 | {
152 | match = true;
153 |
154 | // Loop until we find a mismatch.
155 | // If we don't, then it matches.
156 | for (iChar2 = 0; iChar2 < s2Len; iChar2++)
157 | {
158 | if (s1[iChar1 + iChar2] != s2[iChar2])
159 | {
160 | match = false;
161 | break;
162 | }
163 | }
164 |
165 | if (match)
166 | return true;
167 | }
168 | }
169 | return false;
170 | }
171 |
172 | // Usage :
173 | //
174 | // public enum TEST_KEY
175 | // {
176 | // thing1,
177 | // thing2,
178 | // thing3
179 | // }
180 | // Utils_Perf.EnumIntEqComp noboxCompare;
181 | // Dictionary dictEnumIntNoBox =
182 | // new Dictionary(noboxCompare);
183 | //
184 | // https://stackoverflow.com/questions/26280788/dictionary-enum-key-performance
185 | // todo; check if your TEnum is enum && typeCode == TypeCode.Int
186 |
187 | ///
188 | /// This code prevents the GC allocations when using Enum as
189 | /// a key in a Dictionary or other collection.
190 | ///
191 | /// Key type
192 | public struct EnumIntEqComp : IEqualityComparer
193 | where TEnum : struct
194 | {
195 | public static class BoxAvoidance
196 | {
197 | public static readonly System.Func _wrapper;
198 |
199 | public static int ToInt(TEnum enu)
200 | {
201 | return _wrapper(enu);
202 | }
203 |
204 | static BoxAvoidance()
205 | {
206 | var p = System.Linq.Expressions.Expression.Parameter(typeof(TEnum), null);
207 | var c = System.Linq.Expressions.Expression.ConvertChecked(p, typeof(int));
208 |
209 | _wrapper = System.Linq.Expressions.Expression.Lambda>(c, p).Compile();
210 | }
211 | }
212 |
213 | public bool Equals(TEnum firstEnum, TEnum secondEnum)
214 | {
215 | return BoxAvoidance.ToInt(firstEnum) ==
216 | BoxAvoidance.ToInt(secondEnum);
217 | }
218 |
219 | public int GetHashCode(TEnum firstEnum)
220 | {
221 | return BoxAvoidance.ToInt(firstEnum);
222 | }
223 | }
224 | }
225 | }
226 |
227 | /*
228 | Revised BSD License
229 |
230 | Copyright(c) 2018, Garret Polk
231 | All rights reserved.
232 |
233 | Redistribution and use in source and binary forms, with or without
234 | modification, are permitted provided that the following conditions are met:
235 | * Redistributions of source code must retain the above copyright
236 | notice, this list of conditions and the following disclaimer.
237 | * Redistributions in binary form must reproduce the above copyright
238 | notice, this list of conditions and the following disclaimer in the
239 | documentation and/or other materials provided with the distribution.
240 | * Neither the name of the Garret Polk nor the
241 | names of its contributors may be used to endorse or promote products
242 | derived from this software without specific prior written permission.
243 |
244 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
245 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
246 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
247 | DISCLAIMED. IN NO EVENT SHALL GARRET POLK BE LIABLE FOR ANY
248 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
249 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
250 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
251 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
253 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
254 | */
255 |
--------------------------------------------------------------------------------
/Assets/Scripts/Utils_Perf.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2bf08180d64c7a04489e9fd1b4bc2805
3 | timeCreated: 1484989320
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/Packages/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | }
4 | }
5 |
--------------------------------------------------------------------------------
/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!11 &1
4 | AudioManager:
5 | m_ObjectHideFlags: 0
6 | m_Volume: 1
7 | Rolloff Scale: 1
8 | Doppler Factor: 1
9 | Default Speaker Mode: 2
10 | m_SampleRate: 0
11 | m_DSPBufferSize: 0
12 | m_VirtualVoiceCount: 512
13 | m_RealVoiceCount: 32
14 | m_SpatializerPlugin:
15 | m_AmbisonicDecoderPlugin:
16 | m_DisableAudio: 0
17 | m_VirtualizeEffects: 1
18 |
--------------------------------------------------------------------------------
/ProjectSettings/ClusterInputManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!236 &1
4 | ClusterInputManager:
5 | m_ObjectHideFlags: 0
6 | m_Inputs: []
7 |
--------------------------------------------------------------------------------
/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!55 &1
4 | PhysicsManager:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 7
7 | m_Gravity: {x: 0, y: -9.81, z: 0}
8 | m_DefaultMaterial: {fileID: 0}
9 | m_BounceThreshold: 2
10 | m_SleepThreshold: 0.005
11 | m_DefaultContactOffset: 0.01
12 | m_DefaultSolverIterations: 6
13 | m_DefaultSolverVelocityIterations: 1
14 | m_QueriesHitBackfaces: 0
15 | m_QueriesHitTriggers: 1
16 | m_EnableAdaptiveForce: 0
17 | m_ClothInterCollisionDistance: 0
18 | m_ClothInterCollisionStiffness: 0
19 | m_ContactsGeneration: 1
20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
21 | m_AutoSimulation: 1
22 | m_AutoSyncTransforms: 1
23 | m_ClothInterCollisionSettingsToggle: 0
24 | m_ContactPairsMode: 0
25 | m_BroadphaseType: 0
26 | m_WorldBounds:
27 | m_Center: {x: 0, y: 0, z: 0}
28 | m_Extent: {x: 250, y: 250, z: 250}
29 | m_WorldSubdivisions: 8
30 |
--------------------------------------------------------------------------------
/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1045 &1
4 | EditorBuildSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | m_Scenes: []
8 |
--------------------------------------------------------------------------------
/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!159 &1
4 | EditorSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 7
7 | m_ExternalVersionControlSupport: Visible Meta Files
8 | m_SerializationMode: 2
9 | m_LineEndingsForNewScripts: 1
10 | m_DefaultBehaviorMode: 0
11 | m_SpritePackerMode: 2
12 | m_SpritePackerPaddingPower: 1
13 | m_EtcTextureCompressorBehavior: 0
14 | m_EtcTextureFastCompressor: 2
15 | m_EtcTextureNormalCompressor: 2
16 | m_EtcTextureBestCompressor: 5
17 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd
18 | m_ProjectGenerationRootNamespace:
19 | m_UserGeneratedProjectSuffix:
20 | m_CollabEditorSettings:
21 | inProgressEnabled: 1
22 |
--------------------------------------------------------------------------------
/ProjectSettings/GraphicsSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!30 &1
4 | GraphicsSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 12
7 | m_Deferred:
8 | m_Mode: 1
9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0}
10 | m_DeferredReflections:
11 | m_Mode: 1
12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0}
13 | m_ScreenSpaceShadows:
14 | m_Mode: 1
15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0}
16 | m_LegacyDeferred:
17 | m_Mode: 1
18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0}
19 | m_DepthNormals:
20 | m_Mode: 1
21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0}
22 | m_MotionVectors:
23 | m_Mode: 1
24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0}
25 | m_LightHalo:
26 | m_Mode: 1
27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0}
28 | m_LensFlare:
29 | m_Mode: 1
30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0}
31 | m_AlwaysIncludedShaders:
32 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0}
33 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0}
34 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0}
35 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0}
36 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
37 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
38 | - {fileID: 10782, guid: 0000000000000000f000000000000000, type: 0}
39 | - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
40 | - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
41 | m_PreloadedShaders: []
42 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
43 | type: 0}
44 | m_CustomRenderPipeline: {fileID: 0}
45 | m_TransparencySortMode: 0
46 | m_TransparencySortAxis: {x: 0, y: 0, z: 1}
47 | m_DefaultRenderingPath: 1
48 | m_DefaultMobileRenderingPath: 1
49 | m_TierSettings: []
50 | m_LightmapStripping: 0
51 | m_FogStripping: 0
52 | m_InstancingStripping: 0
53 | m_LightmapKeepPlain: 1
54 | m_LightmapKeepDirCombined: 1
55 | m_LightmapKeepDynamicPlain: 1
56 | m_LightmapKeepDynamicDirCombined: 1
57 | m_LightmapKeepShadowMask: 1
58 | m_LightmapKeepSubtractive: 1
59 | m_FogKeepLinear: 1
60 | m_FogKeepExp: 1
61 | m_FogKeepExp2: 1
62 | m_AlbedoSwatchInfos: []
63 | m_LightsUseLinearIntensity: 0
64 | m_LightsUseColorTemperature: 0
65 |
--------------------------------------------------------------------------------
/ProjectSettings/InputManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!13 &1
4 | InputManager:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | m_Axes:
8 | - serializedVersion: 3
9 | m_Name: Horizontal
10 | descriptiveName:
11 | descriptiveNegativeName:
12 | negativeButton: left
13 | positiveButton: right
14 | altNegativeButton: a
15 | altPositiveButton: d
16 | gravity: 3
17 | dead: 0.001
18 | sensitivity: 3
19 | snap: 1
20 | invert: 0
21 | type: 0
22 | axis: 0
23 | joyNum: 0
24 | - serializedVersion: 3
25 | m_Name: Vertical
26 | descriptiveName:
27 | descriptiveNegativeName:
28 | negativeButton: down
29 | positiveButton: up
30 | altNegativeButton: s
31 | altPositiveButton: w
32 | gravity: 3
33 | dead: 0.001
34 | sensitivity: 3
35 | snap: 1
36 | invert: 0
37 | type: 0
38 | axis: 0
39 | joyNum: 0
40 | - serializedVersion: 3
41 | m_Name: Fire1
42 | descriptiveName:
43 | descriptiveNegativeName:
44 | negativeButton:
45 | positiveButton: left ctrl
46 | altNegativeButton:
47 | altPositiveButton: mouse 0
48 | gravity: 1000
49 | dead: 0.001
50 | sensitivity: 1000
51 | snap: 0
52 | invert: 0
53 | type: 0
54 | axis: 0
55 | joyNum: 0
56 | - serializedVersion: 3
57 | m_Name: Fire2
58 | descriptiveName:
59 | descriptiveNegativeName:
60 | negativeButton:
61 | positiveButton: left alt
62 | altNegativeButton:
63 | altPositiveButton: mouse 1
64 | gravity: 1000
65 | dead: 0.001
66 | sensitivity: 1000
67 | snap: 0
68 | invert: 0
69 | type: 0
70 | axis: 0
71 | joyNum: 0
72 | - serializedVersion: 3
73 | m_Name: Fire3
74 | descriptiveName:
75 | descriptiveNegativeName:
76 | negativeButton:
77 | positiveButton: left shift
78 | altNegativeButton:
79 | altPositiveButton: mouse 2
80 | gravity: 1000
81 | dead: 0.001
82 | sensitivity: 1000
83 | snap: 0
84 | invert: 0
85 | type: 0
86 | axis: 0
87 | joyNum: 0
88 | - serializedVersion: 3
89 | m_Name: Jump
90 | descriptiveName:
91 | descriptiveNegativeName:
92 | negativeButton:
93 | positiveButton: space
94 | altNegativeButton:
95 | altPositiveButton:
96 | gravity: 1000
97 | dead: 0.001
98 | sensitivity: 1000
99 | snap: 0
100 | invert: 0
101 | type: 0
102 | axis: 0
103 | joyNum: 0
104 | - serializedVersion: 3
105 | m_Name: Mouse X
106 | descriptiveName:
107 | descriptiveNegativeName:
108 | negativeButton:
109 | positiveButton:
110 | altNegativeButton:
111 | altPositiveButton:
112 | gravity: 0
113 | dead: 0
114 | sensitivity: 0.1
115 | snap: 0
116 | invert: 0
117 | type: 1
118 | axis: 0
119 | joyNum: 0
120 | - serializedVersion: 3
121 | m_Name: Mouse Y
122 | descriptiveName:
123 | descriptiveNegativeName:
124 | negativeButton:
125 | positiveButton:
126 | altNegativeButton:
127 | altPositiveButton:
128 | gravity: 0
129 | dead: 0
130 | sensitivity: 0.1
131 | snap: 0
132 | invert: 0
133 | type: 1
134 | axis: 1
135 | joyNum: 0
136 | - serializedVersion: 3
137 | m_Name: Mouse ScrollWheel
138 | descriptiveName:
139 | descriptiveNegativeName:
140 | negativeButton:
141 | positiveButton:
142 | altNegativeButton:
143 | altPositiveButton:
144 | gravity: 0
145 | dead: 0
146 | sensitivity: 0.1
147 | snap: 0
148 | invert: 0
149 | type: 1
150 | axis: 2
151 | joyNum: 0
152 | - serializedVersion: 3
153 | m_Name: Horizontal
154 | descriptiveName:
155 | descriptiveNegativeName:
156 | negativeButton:
157 | positiveButton:
158 | altNegativeButton:
159 | altPositiveButton:
160 | gravity: 0
161 | dead: 0.19
162 | sensitivity: 1
163 | snap: 0
164 | invert: 0
165 | type: 2
166 | axis: 0
167 | joyNum: 0
168 | - serializedVersion: 3
169 | m_Name: Vertical
170 | descriptiveName:
171 | descriptiveNegativeName:
172 | negativeButton:
173 | positiveButton:
174 | altNegativeButton:
175 | altPositiveButton:
176 | gravity: 0
177 | dead: 0.19
178 | sensitivity: 1
179 | snap: 0
180 | invert: 1
181 | type: 2
182 | axis: 1
183 | joyNum: 0
184 | - serializedVersion: 3
185 | m_Name: Fire1
186 | descriptiveName:
187 | descriptiveNegativeName:
188 | negativeButton:
189 | positiveButton: joystick button 0
190 | altNegativeButton:
191 | altPositiveButton:
192 | gravity: 1000
193 | dead: 0.001
194 | sensitivity: 1000
195 | snap: 0
196 | invert: 0
197 | type: 0
198 | axis: 0
199 | joyNum: 0
200 | - serializedVersion: 3
201 | m_Name: Fire2
202 | descriptiveName:
203 | descriptiveNegativeName:
204 | negativeButton:
205 | positiveButton: joystick button 1
206 | altNegativeButton:
207 | altPositiveButton:
208 | gravity: 1000
209 | dead: 0.001
210 | sensitivity: 1000
211 | snap: 0
212 | invert: 0
213 | type: 0
214 | axis: 0
215 | joyNum: 0
216 | - serializedVersion: 3
217 | m_Name: Fire3
218 | descriptiveName:
219 | descriptiveNegativeName:
220 | negativeButton:
221 | positiveButton: joystick button 2
222 | altNegativeButton:
223 | altPositiveButton:
224 | gravity: 1000
225 | dead: 0.001
226 | sensitivity: 1000
227 | snap: 0
228 | invert: 0
229 | type: 0
230 | axis: 0
231 | joyNum: 0
232 | - serializedVersion: 3
233 | m_Name: Jump
234 | descriptiveName:
235 | descriptiveNegativeName:
236 | negativeButton:
237 | positiveButton: joystick button 3
238 | altNegativeButton:
239 | altPositiveButton:
240 | gravity: 1000
241 | dead: 0.001
242 | sensitivity: 1000
243 | snap: 0
244 | invert: 0
245 | type: 0
246 | axis: 0
247 | joyNum: 0
248 | - serializedVersion: 3
249 | m_Name: Submit
250 | descriptiveName:
251 | descriptiveNegativeName:
252 | negativeButton:
253 | positiveButton: return
254 | altNegativeButton:
255 | altPositiveButton: joystick button 0
256 | gravity: 1000
257 | dead: 0.001
258 | sensitivity: 1000
259 | snap: 0
260 | invert: 0
261 | type: 0
262 | axis: 0
263 | joyNum: 0
264 | - serializedVersion: 3
265 | m_Name: Submit
266 | descriptiveName:
267 | descriptiveNegativeName:
268 | negativeButton:
269 | positiveButton: enter
270 | altNegativeButton:
271 | altPositiveButton: space
272 | gravity: 1000
273 | dead: 0.001
274 | sensitivity: 1000
275 | snap: 0
276 | invert: 0
277 | type: 0
278 | axis: 0
279 | joyNum: 0
280 | - serializedVersion: 3
281 | m_Name: Cancel
282 | descriptiveName:
283 | descriptiveNegativeName:
284 | negativeButton:
285 | positiveButton: escape
286 | altNegativeButton:
287 | altPositiveButton: joystick button 1
288 | gravity: 1000
289 | dead: 0.001
290 | sensitivity: 1000
291 | snap: 0
292 | invert: 0
293 | type: 0
294 | axis: 0
295 | joyNum: 0
296 |
--------------------------------------------------------------------------------
/ProjectSettings/NavMeshAreas.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!126 &1
4 | NavMeshProjectSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | areas:
8 | - name: Walkable
9 | cost: 1
10 | - name: Not Walkable
11 | cost: 1
12 | - name: Jump
13 | cost: 2
14 | - name:
15 | cost: 1
16 | - name:
17 | cost: 1
18 | - name:
19 | cost: 1
20 | - name:
21 | cost: 1
22 | - name:
23 | cost: 1
24 | - name:
25 | cost: 1
26 | - name:
27 | cost: 1
28 | - name:
29 | cost: 1
30 | - name:
31 | cost: 1
32 | - name:
33 | cost: 1
34 | - name:
35 | cost: 1
36 | - name:
37 | cost: 1
38 | - name:
39 | cost: 1
40 | - name:
41 | cost: 1
42 | - name:
43 | cost: 1
44 | - name:
45 | cost: 1
46 | - name:
47 | cost: 1
48 | - name:
49 | cost: 1
50 | - name:
51 | cost: 1
52 | - name:
53 | cost: 1
54 | - name:
55 | cost: 1
56 | - name:
57 | cost: 1
58 | - name:
59 | cost: 1
60 | - name:
61 | cost: 1
62 | - name:
63 | cost: 1
64 | - name:
65 | cost: 1
66 | - name:
67 | cost: 1
68 | - name:
69 | cost: 1
70 | - name:
71 | cost: 1
72 | m_LastAgentTypeID: -887442657
73 | m_Settings:
74 | - serializedVersion: 2
75 | agentTypeID: 0
76 | agentRadius: 0.5
77 | agentHeight: 2
78 | agentSlope: 45
79 | agentClimb: 0.75
80 | ledgeDropHeight: 0
81 | maxJumpAcrossDistance: 0
82 | minRegionArea: 2
83 | manualCellSize: 0
84 | cellSize: 0.16666667
85 | manualTileSize: 0
86 | tileSize: 256
87 | accuratePlacement: 0
88 | debug:
89 | m_Flags: 0
90 | m_SettingNames:
91 | - Humanoid
92 |
--------------------------------------------------------------------------------
/ProjectSettings/NetworkManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!149 &1
4 | NetworkManager:
5 | m_ObjectHideFlags: 0
6 | m_DebugLevel: 0
7 | m_Sendrate: 15
8 | m_AssetToPrefab: {}
9 |
--------------------------------------------------------------------------------
/ProjectSettings/Physics2DSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!19 &1
4 | Physics2DSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 3
7 | m_Gravity: {x: 0, y: -9.81}
8 | m_DefaultMaterial: {fileID: 0}
9 | m_VelocityIterations: 8
10 | m_PositionIterations: 3
11 | m_VelocityThreshold: 1
12 | m_MaxLinearCorrection: 0.2
13 | m_MaxAngularCorrection: 8
14 | m_MaxTranslationSpeed: 100
15 | m_MaxRotationSpeed: 360
16 | m_BaumgarteScale: 0.2
17 | m_BaumgarteTimeOfImpactScale: 0.75
18 | m_TimeToSleep: 0.5
19 | m_LinearSleepTolerance: 0.01
20 | m_AngularSleepTolerance: 2
21 | m_DefaultContactOffset: 0.01
22 | m_AutoSimulation: 1
23 | m_QueriesHitTriggers: 1
24 | m_QueriesStartInColliders: 1
25 | m_ChangeStopsCallbacks: 0
26 | m_CallbacksOnDisable: 1
27 | m_AutoSyncTransforms: 1
28 | m_AlwaysShowColliders: 0
29 | m_ShowColliderSleep: 1
30 | m_ShowColliderContacts: 0
31 | m_ShowColliderAABB: 0
32 | m_ContactArrowScale: 0.2
33 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412}
34 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
35 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
36 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
37 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
38 |
--------------------------------------------------------------------------------
/ProjectSettings/ProjectVersion.txt:
--------------------------------------------------------------------------------
1 | m_EditorVersion: 2017.3.1f1
2 |
--------------------------------------------------------------------------------
/ProjectSettings/QualitySettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!47 &1
4 | QualitySettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 5
7 | m_CurrentQuality: 5
8 | m_QualitySettings:
9 | - serializedVersion: 2
10 | name: Fastest
11 | pixelLightCount: 0
12 | shadows: 0
13 | shadowResolution: 0
14 | shadowProjection: 1
15 | shadowCascades: 1
16 | shadowDistance: 15
17 | shadowNearPlaneOffset: 3
18 | shadowCascade2Split: 0.33333334
19 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
20 | shadowmaskMode: 0
21 | blendWeights: 1
22 | textureQuality: 1
23 | anisotropicTextures: 0
24 | antiAliasing: 0
25 | softParticles: 0
26 | softVegetation: 0
27 | realtimeReflectionProbes: 0
28 | billboardsFaceCameraPosition: 0
29 | vSyncCount: 0
30 | lodBias: 0.3
31 | maximumLODLevel: 0
32 | particleRaycastBudget: 4
33 | asyncUploadTimeSlice: 2
34 | asyncUploadBufferSize: 4
35 | resolutionScalingFixedDPIFactor: 1
36 | excludedTargetPlatforms: []
37 | - serializedVersion: 2
38 | name: Fast
39 | pixelLightCount: 0
40 | shadows: 0
41 | shadowResolution: 0
42 | shadowProjection: 1
43 | shadowCascades: 1
44 | shadowDistance: 20
45 | shadowNearPlaneOffset: 3
46 | shadowCascade2Split: 0.33333334
47 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
48 | shadowmaskMode: 0
49 | blendWeights: 2
50 | textureQuality: 0
51 | anisotropicTextures: 0
52 | antiAliasing: 0
53 | softParticles: 0
54 | softVegetation: 0
55 | realtimeReflectionProbes: 0
56 | billboardsFaceCameraPosition: 0
57 | vSyncCount: 0
58 | lodBias: 0.4
59 | maximumLODLevel: 0
60 | particleRaycastBudget: 16
61 | asyncUploadTimeSlice: 2
62 | asyncUploadBufferSize: 4
63 | resolutionScalingFixedDPIFactor: 1
64 | excludedTargetPlatforms: []
65 | - serializedVersion: 2
66 | name: Simple
67 | pixelLightCount: 1
68 | shadows: 1
69 | shadowResolution: 0
70 | shadowProjection: 1
71 | shadowCascades: 1
72 | shadowDistance: 20
73 | shadowNearPlaneOffset: 3
74 | shadowCascade2Split: 0.33333334
75 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
76 | shadowmaskMode: 0
77 | blendWeights: 2
78 | textureQuality: 0
79 | anisotropicTextures: 1
80 | antiAliasing: 0
81 | softParticles: 0
82 | softVegetation: 0
83 | realtimeReflectionProbes: 0
84 | billboardsFaceCameraPosition: 0
85 | vSyncCount: 1
86 | lodBias: 0.7
87 | maximumLODLevel: 0
88 | particleRaycastBudget: 64
89 | asyncUploadTimeSlice: 2
90 | asyncUploadBufferSize: 4
91 | resolutionScalingFixedDPIFactor: 1
92 | excludedTargetPlatforms: []
93 | - serializedVersion: 2
94 | name: Good
95 | pixelLightCount: 2
96 | shadows: 2
97 | shadowResolution: 1
98 | shadowProjection: 1
99 | shadowCascades: 2
100 | shadowDistance: 40
101 | shadowNearPlaneOffset: 3
102 | shadowCascade2Split: 0.33333334
103 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
104 | shadowmaskMode: 1
105 | blendWeights: 2
106 | textureQuality: 0
107 | anisotropicTextures: 1
108 | antiAliasing: 0
109 | softParticles: 0
110 | softVegetation: 1
111 | realtimeReflectionProbes: 1
112 | billboardsFaceCameraPosition: 1
113 | vSyncCount: 1
114 | lodBias: 1
115 | maximumLODLevel: 0
116 | particleRaycastBudget: 256
117 | asyncUploadTimeSlice: 2
118 | asyncUploadBufferSize: 4
119 | resolutionScalingFixedDPIFactor: 1
120 | excludedTargetPlatforms: []
121 | - serializedVersion: 2
122 | name: Beautiful
123 | pixelLightCount: 3
124 | shadows: 2
125 | shadowResolution: 2
126 | shadowProjection: 1
127 | shadowCascades: 2
128 | shadowDistance: 70
129 | shadowNearPlaneOffset: 3
130 | shadowCascade2Split: 0.33333334
131 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
132 | shadowmaskMode: 1
133 | blendWeights: 4
134 | textureQuality: 0
135 | anisotropicTextures: 2
136 | antiAliasing: 2
137 | softParticles: 1
138 | softVegetation: 1
139 | realtimeReflectionProbes: 1
140 | billboardsFaceCameraPosition: 1
141 | vSyncCount: 1
142 | lodBias: 1.5
143 | maximumLODLevel: 0
144 | particleRaycastBudget: 1024
145 | asyncUploadTimeSlice: 2
146 | asyncUploadBufferSize: 4
147 | resolutionScalingFixedDPIFactor: 1
148 | excludedTargetPlatforms: []
149 | - serializedVersion: 2
150 | name: Fantastic
151 | pixelLightCount: 4
152 | shadows: 2
153 | shadowResolution: 2
154 | shadowProjection: 1
155 | shadowCascades: 4
156 | shadowDistance: 150
157 | shadowNearPlaneOffset: 3
158 | shadowCascade2Split: 0.33333334
159 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
160 | shadowmaskMode: 1
161 | blendWeights: 4
162 | textureQuality: 0
163 | anisotropicTextures: 2
164 | antiAliasing: 2
165 | softParticles: 1
166 | softVegetation: 1
167 | realtimeReflectionProbes: 1
168 | billboardsFaceCameraPosition: 1
169 | vSyncCount: 1
170 | lodBias: 2
171 | maximumLODLevel: 0
172 | particleRaycastBudget: 4096
173 | asyncUploadTimeSlice: 2
174 | asyncUploadBufferSize: 4
175 | resolutionScalingFixedDPIFactor: 1
176 | excludedTargetPlatforms: []
177 | m_PerPlatformDefaultQuality:
178 | Android: 2
179 | Nintendo 3DS: 5
180 | PS4: 5
181 | PSM: 5
182 | PSP2: 2
183 | Samsung TV: 2
184 | Standalone: 5
185 | Tizen: 2
186 | Web: 5
187 | WebGL: 3
188 | WiiU: 5
189 | Windows Store Apps: 5
190 | XboxOne: 5
191 | iPhone: 2
192 | tvOS: 5
193 |
--------------------------------------------------------------------------------
/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!78 &1
4 | TagManager:
5 | serializedVersion: 2
6 | tags: []
7 | layers:
8 | - Default
9 | - TransparentFX
10 | - Ignore Raycast
11 | -
12 | - Water
13 | - UI
14 | -
15 | -
16 | - Targets
17 | -
18 | -
19 | -
20 | -
21 | -
22 | -
23 | -
24 | -
25 | -
26 | -
27 | -
28 | -
29 | -
30 | -
31 | -
32 | -
33 | -
34 | -
35 | -
36 | -
37 | -
38 | -
39 | -
40 | m_SortingLayers:
41 | - name: Default
42 | uniqueID: 0
43 | locked: 0
44 |
--------------------------------------------------------------------------------
/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!5 &1
4 | TimeManager:
5 | m_ObjectHideFlags: 0
6 | Fixed Timestep: 0.02
7 | Maximum Allowed Timestep: 0.33333334
8 | m_TimeScale: 1
9 | Maximum Particle Timestep: 0.03
10 |
--------------------------------------------------------------------------------
/ProjectSettings/UnityConnectSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!310 &1
4 | UnityConnectSettings:
5 | m_ObjectHideFlags: 0
6 | m_Enabled: 0
7 | m_TestMode: 0
8 | m_TestEventUrl:
9 | m_TestConfigUrl:
10 | m_TestInitMode: 0
11 | CrashReportingSettings:
12 | m_EventUrl: https://perf-events.cloud.unity3d.com/api/events/crashes
13 | m_NativeEventUrl: https://perf-events.cloud.unity3d.com/symbolicate
14 | m_Enabled: 0
15 | m_CaptureEditorExceptions: 1
16 | UnityPurchasingSettings:
17 | m_Enabled: 0
18 | m_TestMode: 0
19 | UnityAnalyticsSettings:
20 | m_Enabled: 0
21 | m_InitializeOnStartup: 1
22 | m_TestMode: 0
23 | m_TestEventUrl:
24 | m_TestConfigUrl:
25 | UnityAdsSettings:
26 | m_Enabled: 0
27 | m_InitializeOnStartup: 1
28 | m_TestMode: 0
29 | m_IosGameId:
30 | m_AndroidGameId:
31 | m_GameIds: {}
32 | m_GameId:
33 | PerformanceReportingSettings:
34 | m_Enabled: 0
35 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/friuns2/unity-script-performance/4b436c64870a1edc743e08ba7c2cd5278aab889d/README.md
--------------------------------------------------------------------------------
/UnityPackageManager/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | }
4 | }
5 |
--------------------------------------------------------------------------------