How to use performance-now - 10 common examples

To help you get started, we’ve selected a few performance-now 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 apollographql / graphql-tools / src / tracing.js View on Github external
newLoggerInstance() {
    const queryId = uuid.v4();
    const events = [];
    let idCounter = 0;
    const startTime = (new Date()).getTime();
    const startHrTime = now();

    const log = (type, data = null) => {
      const id = idCounter++;
      const timestamp = now();
      // const timestamp = (new Date()).getTime();
      // console.log(timestamp, type, id, data);
      events.push({ id, timestamp, type, data });
      return id;
    };

    const report = () => {
      return {
        TRACER_APP_KEY: this.TRACER_APP_KEY,
        tracerApiVersion: '0.0.1',
        queryId,
        startTime,
github coralproject / talk / src / core / server / services / migrate / indexing.ts View on Github external
return async (
    indexSpec: IndexSpecification,
    indexOptions: IndexOptions = {}
  ) => {
    try {
      // Try to create the index.
      const start = now();
      log.debug({ indexSpec, indexOptions }, "creating index");
      const indexName = await collection.createIndex(indexSpec, indexOptions);
      log.debug(
        { indexName, indexSpec, indexOptions, took: Math.round(now() - start) },
        "index was created"
      );

      // Match the interface from the `createIndex` function by returning the
      // index name.
      return indexName;
    } catch (err) {
      log.error({ err, indexSpec, indexOptions }, "could not create index");

      // Rethrow the error here.
      throw err;
    }
github coralproject / talk / src / core / server / queue / tasks / mailer / processor.ts View on Github external
if (isNil(smtp.secure) || isNil(smtp.host) || isNil(smtp.port)) {
      log.error("email enabled, but configuration is incomplete");
      return;
    }

    if (!fromEmail) {
      log.error(
        "email was enabled but the fromAddress configuration was missing"
      );
      return;
    }

    // Construct the fromAddress.
    const fromAddress = fromName ? `${fromName} <${fromEmail}>` : fromEmail;

    const startTemplateGenerationTime = now();

    // Get the message to send.
    let message: Message;
    try {
      message = await translateMessage(
        tenant,
        data.templateName,
        tenant.locale,
        fromAddress,
        data
      );
    } catch (e) {
      throw new InternalError(e, "could not translate the message");
    }

    // Compute the end time.
github convoyinc / graphql-client-benchmarks / src / execution.ts View on Github external
...eventCommon,
      subject: Subject.CLIENT_BENCHMARK_PHASE,
      phase: Phase.WARMUP,
      type: Type.END,
      duration: performanceNow() - warmupStart,
      failure: context.failure,
    });
  }

  // Brief pause to give the UI (and maybe GC) a chance to catch up.
  await new Promise(resolve => setTimeout(resolve, 50));

  // Iterations

  const stats = new Stats();
  const runStart = performanceNow();
  if (!context.canceled && !context.failure) {
    while (true) {
      if (context.canceled || context.failure) break;

      reporter({
        ...eventCommon,
        subject: Subject.CLIENT_BENCHMARK_PHASE,
        phase: Phase.ITERATION,
        type: Type.START,
      });

      const duration = await runSingleBenchmarkPass(
        context,
        BenchmarkClass,
        ClientClass,
        example,
github Webiks / force-horse / src / viewer / force-horse.viewer.js View on Github external
runSimulation() {
    const simulationStart = now();
    let ticksPerRender,
      simulationDuration, calculationStart, calculationDuration = 0,
      ticks = 0;

    this.force.velocityDecay(FHConfig.VELOCITY_DECAY_LIGHT);

    const render = () => {
      // Do not accelerate the simulation during dragging, so as not to slow the dragging.
      ticksPerRender = (this.isDragging ? 1 : this.numOfNodes / 7);
      calculationStart = now();
      for (let i = 0; i < ticksPerRender && this.force.alpha() > this.force.alphaMin(); i++) {
        this.force.tick();
        ticks++;
      }
      calculationDuration += (now() - calculationStart);
      this.updateGraphInDOM();
github coralproject / talk / src / core / server / queue / tasks / scraper.ts View on Github external
// Mark the start time.
  const startTime = now();

  log.debug("starting to scrape the story");

  try {
    await scrape(mongo, config, tenantID, storyID, storyURL);
  } catch (err) {
    log.error({ err }, "could not scrape the story");

    throw err;
  }

  // Compute the end time.
  const responseTime = Math.round(now() - startTime);

  log.debug({ responseTime }, "scraped the story");
};
github Webiks / force-horse / src / viewer / force-horse.viewer.js View on Github external
levelOfDetails() {
    debugLog('ForceHorseViewer:levelOfDetails');

    const view = this.svg.node().getBoundingClientRect(),
      nodesInView = [],
      startTime = now();

    let count = 0;

    // Find which nodes are contained in current view
    this.elements[FHConfig.NODES].each(function (d) { // Requires ES5 function for 'this' reference
      if (ForceHorseHelper.rectContained(this.getBoundingClientRect(), view)) {
        nodesInView[count++] = d;
      }
    });

    let numOfLabelsToShow = this.config.numOfLabelsToShow;
    // Experiment: show labels for 1/4 of the nodes in view
    numOfLabelsToShow = count < 2 * this.config.numOfLabelsToShow ? this.config.numOfLabelsToShow : Math.round(count / 4);
    // Sort the contained nodes, according to node weight
    // Set hide-on-current-level flag, for each node in view
    nodesInView.sort((node1, node2) => node1.edgesWeight - node2.edgesWeight)
github convoyinc / graphql-client-benchmarks / src / execution.ts View on Github external
failure: context.failure,
  });

  // Brief pause to give the UI (and maybe GC) a chance to catch up.
  await new Promise(resolve => setTimeout(resolve, 50));

  // Warmup

  if (!context.canceled && !context.failure) {
    reporter({
      ...eventCommon,
      subject: Subject.CLIENT_BENCHMARK_PHASE,
      phase: Phase.WARMUP,
      type: Type.START,
    });
    const warmupStart = performanceNow();
    for (let i = 0; i < config.warmups; i++) {
      if (context.canceled || context.failure) break;
      await runSingleBenchmarkPass(context, BenchmarkClass, ClientClass, example, Phase.WARMUP);
    }
    reporter({
      ...eventCommon,
      subject: Subject.CLIENT_BENCHMARK_PHASE,
      phase: Phase.WARMUP,
      type: Type.END,
      duration: performanceNow() - warmupStart,
      failure: context.failure,
    });
  }

  // Brief pause to give the UI (and maybe GC) a chance to catch up.
  await new Promise(resolve => setTimeout(resolve, 50));
github tbolis / react-back2top / src / main.jsx View on Github external
}
        var animation = animations.get(name);
        var shouldAnimate = this.shouldAnimate() && options.animation !== false;
        if (!animation || !shouldAnimate || !isNumber(endValue)) {
            let easing = options.easing || 'linear';
            let startValue = isNumber(options.startValue) && shouldAnimate ? options.startValue : endValue;
            animation = {duration, easing, endValue, isAnimating: false, startValue, value: startValue};
            animations.set(name, animation);
        }
        if (!duration) {
            Object.assign(animation, {endValue, value: endValue});
            animations.set(name, animation);
        }
        if (animation.value !== endValue && !animation.isAnimating) {
            if (!isAnimating(animations)) scheduleAnimation(this);
            var startTime = 'startTime' in options ? options.startTime : now();
            duration = duration || animation.duration;
            let easing = options.easing || animation.easing;
            let startValue = animation.value;
            Object.assign(animation, {isAnimating: true, endValue, startValue, startTime, duration, easing});
        }
        return animation.value;
    }
github baptistebriel / canvas-video / index.js View on Github external
draw() {
        
        if(!this.playing) return
        
        this.rAF = raf(this.draw.bind(this))
        
        this.fps && (this.perfs.now = performance(), this.perfs.delta = this.perfs.now - this.perfs.then)
        
        if (!this.fps || this.perfs.delta > this.interval) {
            
            this.context.drawImage(this.video, 0, 0, this.bounding.width, this.bounding.height)
            this.fps && (this.perfs.then = this.perfs.now - (this.perfs.delta % this.interval))
        }
    }

performance-now

Implements performance.now (based on process.hrtime).

MIT
Latest version published 8 years ago

Package Health Score

65 / 100
Full package analysis

Popular performance-now functions

Similar packages