コード例 #1
0
    public void Add(TMarker marker, float timeInSeconds)
    {
        MarkerStats stats = null;

        if (!_markerStats.TryGetValue(marker, out stats))
        {
            stats = new MarkerStats();
#if THREAD_SAFE_TIMER
            if (!_markerStats.TryAdd(marker, stats))
            {
                stats = _markerStats[marker]; // Item has been added by now
            }
#else
            _markerStats.Add(marker, stats);
#endif
        }

        var time = (long)(timeInSeconds * _frequency);
#if THREAD_SAFE_TIMER
        Interlocked.Increment(ref stats.Count);
        Interlocked.Exchange(ref stats.Min, Math.Min(stats.Min, time));
        Interlocked.Exchange(ref stats.Max, Math.Max(stats.Max, time));
        Interlocked.Add(ref stats.Total, time);
#else
        stats.Count++;
        stats.Min    = stats.Min < time ? stats.Min : time;
        stats.Max    = stats.Max > time ? stats.Max : time;
        stats.Total += time;
#endif
    }
コード例 #2
0
    public long Count(TMarker marker)
    {
        MarkerStats stats = null;

        if (_markerStats.TryGetValue(marker, out stats))
        {
            return(stats.Count);
        }

        throw new KeyNotFoundException(marker.ToString());
    }
コード例 #3
0
    public double MinSeconds(TMarker marker)
    {
        MarkerStats stats = null;

        if (_markerStats.TryGetValue(marker, out stats))
        {
            return(stats.Min / (double)_frequency);
        }

        throw new KeyNotFoundException(marker.ToString());
    }
コード例 #4
0
    public double AverageSeconds(TMarker marker)
    {
        MarkerStats stats = null;

        if (_markerStats.TryGetValue(marker, out stats))
        {
            return((stats.Total / (double)_frequency) / stats.Count);
        }

        throw new KeyNotFoundException(marker.ToString());
    }
コード例 #5
0
    public void Lap(TMarker marker, bool stop = false)
    {
        var time = Stop();

        if (!stop)
        {
            Start();
        }

        MarkerStats stats = null;

        if (!_markerStats.TryGetValue(marker, out stats))
        {
            stats = new MarkerStats();
#if THREAD_SAFE_TIMER
            if (!_markerStats.TryAdd(marker, stats))
            {
                stats = _markerStats[marker]; // Item has been added by now
            }
#else
            _markerStats.Add(marker, stats);
#endif
        }

#if THREAD_SAFE_TIMER
        Interlocked.Increment(ref stats.Count);
        Interlocked.Exchange(ref stats.Min, Math.Min(stats.Min, time));
        Interlocked.Exchange(ref stats.Max, Math.Max(stats.Max, time));
        Interlocked.Add(ref stats.Total, time);
#else
        stats.Count++;
        stats.Min    = stats.Min < time ? stats.Min : time;
        stats.Max    = stats.Max > time ? stats.Max : time;
        stats.Total += time;
#endif
    }