#
#
#2018-08-19 08:33:29
Node.js
#, 2018-08-19 08:33:29

Measuring the execution time of a piece of code, in node.js?

I have been sitting on a sharp for a long time and tightly (from his birth). I’m looking at js (what really, what is that) - like an old ram to a new gate))
what I ask for help, as in a node (yes, I’m trying to start not from browsers, but from my territory - the system)) .. on a clean js to make an analogue of measuring the execution time of a code fragment

internal static situation startEmptyFlop()
        {
#if DEBUG
            var sw = new Stopwatch();
            sw.Start();
#endif
            /// bla-bla-bla
#if DEBUG
            sw.Stop();
            var ts = sw.Elapsed;
            $"\t{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds:000}".log();
#endif
            return s;
        }

I will be grateful for an example (I thought that it is easier to transfer the accumulated experience to a new technology, and study it that way, and not try head-on, from 0 ... when you don’t want a lot of things already "from 0"))
thanks!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Hellsite, 2018-08-19
@mindtester

function startEmptyFlop() {
    console.time('Watcher');

    // bla-bla-bla

    console.timeEnd('Watcher');
}

> startEmptyFlop()
Watcher: 0.007ms

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question