How to use time-span - 7 common examples

To help you get started, we’ve selected a few time-span examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simonepri / pidtree / test / bench.js View on Github external
async function execute(pid, times) {
  const end = tspan();
  try {
    for (let i = 0; i < times; i++) {
      // eslint-disable-next-line no-await-in-loop
      await pidtree(pid);
    }

    const time = end();
    return Promise.resolve(time);
  } catch (error) {
    end();
    return Promise.reject(error);
  }
}
github thetutlage / japa / src / Test / index.ts View on Github external
public async run () {
    emitter.emit(IEvents.TESTSTARTED, this.toJSON())
    const start = timeSpan()

    /* istanbul ignore else */
    if (!this._todo && !this._skip) {
      /**
       * Run the actual test
       */
      try {
        await this._runTest()

        /**
         * Mark test as failed, when is regression but passed
         */
        if (this._regression) {
          throw new RegressionException('Expected regression test to fail')
        }
      } catch (error) {
github dylang / logging / src / formatters / format-color / dynamic-progress / dynamic-progress.ts View on Github external
}
        this.message = message;
        this.previousMessage = message;
        // Webpack progress % can go and down
        this.percentage = this.percentage > 0 ? Math.max(this.percentage, percentage) : percentage;
        if (this.interval) {
            this.render();
            return;
        }

        if (logConfig.isDebug) {
            return this.render();
        }

        this.prefix = getPackageAndFilename('PROGRESS');
        this.timer = timeSpan();

        this.interval = setInterval(() => this.render(), 50);
    }
github googleapis / nodejs-spanner / test / session-pool.ts View on Github external
it('should use the acquireTimeout if set', async () => {
      const end = timeSpan();
      const timeout = (sessionPool.options.acquireTimeout = 100);

      try {
        await sessionPool._getSession(types.ReadOnly, startTime);
        shouldNotBeCalled();
      } catch (e) {
        assert(isAround(timeout, end()));
        assert.strictEqual(
          e.message,
          'Timeout occurred while acquiring session.'
        );
      }
    });
github soyuka / pidusage / test / bench.js View on Github external
async function execute (childs, pidno, times, options = {}) {
  var pids = childs.map(child => child.pid).slice(0, pidno)

  const end = tspan()
  try {
    for (let i = 0; i < times; i++) {
      await m(pids, options)
    }
    const time = end()
    return Promise.resolve(time)
  } catch (err) {
    end()
    return Promise.reject(err)
  }
}
github thetutlage / japa / src / utils / index.ts View on Github external
public open () {
    if (!this._processStart) {
      this._processStart = timeSpan()
    }
  }
github dylang / logging / src / formatters / format-color / prefix / get-duration.ts View on Github external
export const getDuration = (level: Level, startTimeSpan: timeSpan.TimeEndFunction = lastCall) => {
    const ms = startTimeSpan();
    const { days, hours, minutes, seconds, milliseconds } = parseMS(ms);
    const daysHoursMinutesAsMinutes = hours * 60 + days * 24 * 60 + minutes;
    const duration =
        daysHoursMinutesAsMinutes > 0
            ? `${daysHoursMinutesAsMinutes} min`
            : `${seconds > 0 ? `${seconds}s` : ''}${
                  logConfig.isDebug
                      ? `${milliseconds < 10 ? ' ' : ''}${milliseconds < 100 ? ' ' : ''}${Math.round(milliseconds)}ms`
                      : ''
              }`;
    lastCall = timeSpan();
    const durationString = ms < (logConfig.isDebug ? 100 : 1000) ? '·' : duration;
    const annotation = level === 'DEBUG' ? 'DEBUG' : '';
    return chalk`{bgMagenta.white ${annotation}}{gray ${rightJustify(
        durationString,
        logConfig.indent - 1 - annotation.length
    )} }`;
};

time-span

Simplified high resolution timing

MIT
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis

Popular time-span functions