# all files / TypeScript.NET/source/System/Diagnostics/ Stopwatch.js

95.38% Statements 62/65
72.73% Branches 16/22
100% Functions 17/17
96.83% Lines 61/63

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116

    1×
    1×
    1×

    1×
    1×
    17×

    1×
    1×
    6×

    1×
    1×

    1×

    4×

    1×
    5×
    5×
    5×

    1×
    1×
    1×
    1×

    1×
    7×
    7×
    6×
    6×

    1×
    6×
    6×
    5×
    5×

    1×
    7×
    7×
    7×
    7×

    1×
    2×
    2×
    1×
    1×
    1×
    1×
    1×
    1×

    1×

    1×

    8×

    1×

    2×

    1×

    2×
    2×
    2×
    1×
    2×

    1×

    1×

    1×

    1×
    1×

     /*!
     * @author electricessence / https://github.com/electricessence/
     * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
     */
    (function (factory) {
        Eif (typeof module === 'object' && typeof module.exports === 'object') {
            var v = factory(require, exports); Iif (v !== undefined) module.exports = v;
        }
        else if (typeof define === 'function' && define.amd) {
            define(["require", "exports", "../Time/TimeSpan"], factory);
        }
    })(function (require, exports) {
        "use strict";
        var TimeSpan_1 = require("../Time/TimeSpan");
        function getTimestampMilliseconds() {
            return (new Date()).getTime();
        }
        var Stopwatch = (function () {
            function Stopwatch() {
                this.reset();
            }
            Stopwatch.getTimestampMilliseconds = function () {
                return getTimestampMilliseconds();
            };
            Object.defineProperty(Stopwatch.prototype, "isRunning", {
                get: function () {
                    return this._isRunning;
                },
                enumerable: true,
                configurable: true
            });
            Stopwatch.startNew = function () {
                var s = new Stopwatch();
                s.start();
                return s;
            };
            Stopwatch.measure = function (closure) {
                var start = getTimestampMilliseconds();
                closure();
                return new TimeSpan_1.TimeSpan(getTimestampMilliseconds() - start);
            };
            Stopwatch.prototype.start = function () {
                var _ = this;
                if (!_._isRunning) {
                    _._startTimeStamp = getTimestampMilliseconds();
                    _._isRunning = true;
                }
            };
            Stopwatch.prototype.stop = function () {
                var _ = this;
                if (_._isRunning) {
                    _._elapsed += _.currentLapMilliseconds;
                    _._isRunning = false;
                }
            };
            Stopwatch.prototype.reset = function () {
                var _ = this;
                _._elapsed = 0;
                _._isRunning = false;
                _._startTimeStamp = NaN;
            };
            Stopwatch.prototype.lap = function () {
                var _ = this;
                if (_._isRunning) {
                    var t = getTimestampMilliseconds();
                    var s = _._startTimeStamp;
                    var e = t - s;
                    _._startTimeStamp = t;
                    _._elapsed += e;
                    return new TimeSpan_1.TimeSpan(e);
                }
                else
                    return TimeSpan_1.TimeSpan.zero;
            };
            Object.defineProperty(Stopwatch.prototype, "currentLapMilliseconds", {
                get: function () {
                    return this._isRunning
                        ? (getTimestampMilliseconds() - this._startTimeStamp)
                        : 0;
                },
                enumerable: true,
                configurable: true
            });
            Object.defineProperty(Stopwatch.prototype, "currentLap", {
                get: function () {
                    return this._isRunning
                        ? new TimeSpan_1.TimeSpan(this.currentLapMilliseconds)
                        : TimeSpan_1.TimeSpan.zero;
                },
                enumerable: true,
                configurable: true
            });
            Object.defineProperty(Stopwatch.prototype, "elapsedMilliseconds", {
                get: function () {
                    var _ = this;
                    var timeElapsed = _._elapsed;
                    if (_._isRunning)
                        timeElapsed += _.currentLapMilliseconds;
                    return timeElapsed;
                },
                enumerable: true,
                configurable: true
            });
            Object.defineProperty(Stopwatch.prototype, "elapsed", {
                get: function () {
                    return new TimeSpan_1.TimeSpan(this.elapsedMilliseconds);
                },
                enumerable: true,
                configurable: true
            });
            return Stopwatch;
        }());
        Object.defineProperty(exports, "__esModule", { value: true });
        exports.default = Stopwatch;
    });
    //# sourceMappingURL=Stopwatch.js.map