Using Time.time to test the performance of scripts

I'd like to do some heavy optimizations of the scripts we run in our game (the critical ones). One thing I did to test performance was to get the timestamp at the beginning and end of an Update() function, and print it every 100 times. Here's the code:

  void Update()
        debugTimeStart = Time.time;

//here's the stuff going on

  debugTimeTaken += Time.time - debugTimeStart;

        if (debugTimeCount == 100)
            Debug.Log("Time: " + debugTimeTaken);
            debugTimeCount = 0;
            debugTimeTaken = 0;

The problem is that I always get 0 as the result.. Is there something more precise than Time.time?

Thanks a lot!

Yes, Time.time and the other Time properties (.deltaTime, .fixedDeltaTime) have a value which is only updated between frames.

There are a few other methods of timing which should give you what you need, such as:

Time.realtimeSinceStartup also works great, I use that for all my profiling.

Try System.Diagnostics.Stopwatch