Test Engineering:
Http://files.cnblogs.com/files/hont/RaycastTestProj.rar
Test method:
A random number of cubes within a radius, then a variety of projections are emitted at the center point for testing
Use the Unity5.3.4 version and test with Profiler and stopwatch to compare performance and GC differences
As the capsules and other projections are too slow, I use 1000 calls to test, Nonalloc cache array length of 20
Some projections are limited by distance.
usingUnityengine;usingSystem.Collections;usingSystem.Diagnostics; Public classboxcastalltest:monobehaviour{voidUpdate () {varStopWatch =NewStopwatch (); Stopwatch.start (); Profiler.beginsample ("boxcastalltest"); for(inti =0; I < +; i++) {Physics.boxcastall (transform.position, Vector3.one*2f, Vector3.forward); } profiler.endsample (); Stopwatch.stop (); UnityEngine.Debug.Log ("StopWatch:"+stopwatch.elapsedmilliseconds); }}
Test results:
Name |
Speed |
GC Alloc |
Raycast |
1ms |
0 |
Raycastall |
2ms |
273.4KB |
Raycastnonalloc |
1ms |
0 |
Boxcast |
18ms |
0 |
Boxcastall |
38ms |
3.2MB |
Boxcastnonalloc |
36ms |
0 |
Spherecast |
86ms |
0 |
Spherecastall |
192ms |
8.8MB |
Spherecastnonalloc |
183ms |
0 |
Capsulecast |
139ms |
- |
Capsulecastall |
449ms |
19.6MB |
Capsulenonalloc |
263ms |
0 |
The overhead of spherical projection and capsule projection is relatively large, and the overhead of various projections is much higher than that of direct emission rays.
Visible, if the first choice of Ray to judge, it will be a lot of game optimization help
Horizontal comparison of various physical projection performance in unity