Hi.
I am trying to “time” the startup time from starting an application, till it has finished rendered all the entities.
I have tried using UnityEngine.Time.realtimeSinceStartup, but I suspect that might not be right when initializing from either Entities or MonoBehaviour. At least when I use parallel processing.
When spawning using MonoBehaviour, I have put this code in LateUpdate:
{
if (!once)
{
Debug.Log("Time since startup: " + UnityEngine.Time.realtimeSinceStartup);
once = true;
}
}
It returns one result: Time since startup: 0.8476899)
But when trying the other option, and spawning from Entities, using the same code snip in OnStopRunning() , it returns two results (Make sense, since it is scheduled in parallel)
Time since startup: 0.9899601```
So, my question is basically, What is the best way to measure time it takes for an app/program ,when using either MonoBehaviour or Entity (System), to spawn a large number of entities?
Is there a finished rendering method somewhere I have not found yet?
I might just spawn everything and then make som movement and check time when one of the entities collide. That will probably give me the result, but I suspect there are an easier method...
I’m not sure what you mean by rendering here - do you mean when the entities (eg. a subscene) has finished loading? (Rendering typically refers to drawing entities on the screen, which happens every frame).
In general I think I’d measure these things separately:
App startup time until an empty scene loads
Time to load your specific scene
Measuring startup time seems like the more complicated part. If I were you, I’d try making a build that loads an empty scene and immidiately quits, and measure the time externally using some shell script.
Measuring scene load time is easier because you can do it directly in Unity. ECS complicates things because subscenes load asynchronously. I do scene loading in a coroutine and use a piece of code similar to this to wait for the subscenes to finish loading:
foreach (var scene in FindObjectsOfType<SubScene>())
{
var query = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(typeof(LocalToWorld), typeof(SceneSection));
query.SetSharedComponentFilter(new SceneSection { SceneGUID = scene.SceneGUID });
yield return new WaitWhile(() => query.IsEmpty);
}
(Note that this assumes that there’s objects with LocalToWorld in the subscene, so it could fail if your subscene is actually empty. I haven’t found any better API to do this, unfortunately)