Skip to content

Instantly share code, notes, and snippets.

@typpo
Last active November 7, 2020 06:31
Show Gist options
  • Save typpo/77098de175e33398c10df7f25a687018 to your computer and use it in GitHub Desktop.
Save typpo/77098de175e33398c10df7f25a687018 to your computer and use it in GitHub Desktop.
QuickChart.io benchmark

QuickChart benchmark

The code below renders 100 bar graphs with 2 data series as 400x200 images. Average time per chart: 124 ms.

$ node sample.js
Running #0/100...
Running #99/100...
Total duration for 100 charts: 12361.083189964294 ms
Average time for each chart: 123.55390819549561 ms
const { performance } = require('perf_hooks');

const axios = require('axios');

const NUM_SAMPLES = 100;
const WIDTH = 400;
const HEIGHT = 200;

(async function() {
  const url = `https://quickchart.io/chart?w=${WIDTH}&h=${HEIGHT}&devicePixelRatio=1&bkg=white&c=%7B%0A%20%20type%3A%20%27bar%27%2C%0A%20%20data%3A%20%7B%0A%20%20%20%20labels%3A%20%5B%27Q1%27%2C%20%27Q2%27%2C%20%27Q3%27%2C%20%27Q4%27%5D%2C%0A%20%20%20%20datasets%3A%20%5B%7B%0A%20%20%20%20%20%20label%3A%20%27Users%27%2C%0A%20%20%20%20%20%20data%3A%20%5B50%2C%2060%2C%2070%2C%20180%5D%0A%20%20%20%20%7D%2C%20%7B%0A%20%20%20%20%20%20label%3A%20%27Revenue%27%2C%0A%20%20%20%20%20%20data%3A%20%5B100%2C%20200%2C%20300%2C%20400%5D%0A%20%20%20%20%7D%5D%0A%20%20%7D%0A%7D&cachebust=${Math.floor(Math.random() * 1000000)}`;

  const durations = [];
  const totalStart = performance.now();
  for (let i = 0; i < NUM_SAMPLES; i++) {
    console.log(`Running #${i}/${NUM_SAMPLES}...`);
    const startMs = performance.now();
    await axios.get(url);
    const duration = performance.now() - startMs;
    durations.push(duration);
  }

  const totalDuration = performance.now() - totalStart;
  const sum = durations.reduce((a, b) => a + b, 0);
  const avg = sum / durations.length;
  console.log(`Total duration for ${NUM_SAMPLES} samples: ${totalDuration} ms`);
  console.log(`Average time for each sample: ${avg} ms`);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment