Skip to content
Snippets Groups Projects
Select Git revision
  • efd707eb65ed74b3e376e0178bd43270dccb7432
  • master default protected
  • gh-pages
  • dependabot/npm_and_yarn/nock-14.0.6
  • dependabot/npm_and_yarn/react-19.1.0
  • dependabot/npm_and_yarn/react-dom-19.1.0
  • server-2025-02-01-6100669a
  • server-2024-11-01-87cba042
  • server-2024-10-01-6875b7c8
  • dependabot/npm_and_yarn/path-to-regexp-8.2.0
  • server-2024-09-01-3d52575c
  • daily-tests-gha2
  • daily-tests-gha
  • server-2023-12-01-92d8fb8e
  • server-2023-11-01-a80c93fd
  • server-2023-10-01-31096085
  • coc-v2
  • server-2023-09-01-8edc3810
  • server-2023-08-01-75858a03
  • server-2023-07-01-02183d8d
  • test-9317
  • server-2025-07-01
  • 5.0.2
  • 5.0.1
  • 5.0.0
  • server-2025-06-01
  • server-2025-05-01
  • server-2025-04-03
  • server-2025-03-02
  • server-2025-03-01
  • server-2025-02-02
  • server-2025-01-01
  • server-2024-12-01
  • server-2024-11-02
  • 4.1.0
  • server-2024-09-25
  • server-2024-09-02
  • server-2024-08-01
  • server-2024-07-01
  • 4.0.0
  • server-2024-06-01
41 results

capture-timings.js

Blame
  • capture-timings.js 1.56 KiB
    import readline from 'readline'
    import minimist from 'minimist'
    
    async function captureTimings(warmupIterations) {
      const rl = readline.createInterface({
        input: process.stdin,
      })
    
      const times = {}
      let timingsCount = 0
      let labelsCount = 0
      const timing = /^(.+): ([0-9.]+)ms$/i
    
      for await (const line of rl) {
        const match = timing.exec(line)
        if (match) {
          labelsCount = Object.keys(times).length
          if (timingsCount > warmupIterations * labelsCount) {
            const label = match[1]
            const time = parseFloat(match[2])
            times[label] = time + (times[label] || 0)
          }
          ++timingsCount
        }
      }
      return { times, iterations: timingsCount / labelsCount }
    }
    
    function logResults({ times, iterations, warmupIterations }) {
      if (isNaN(iterations)) {
        console.log(
          'No timings captured. Have you included console.time statements in the badge creation code path?'
        )
      } else {
        const timedIterations = iterations - warmupIterations
        for (const [label, time] of Object.entries(times)) {
          const averageTime = time / timedIterations
          console.log(
            `Average '${label}' time over ${timedIterations} iterations: ${averageTime}ms`
          )
        }
      }
    }
    
    async function main() {
      const args = minimist(process.argv)
      const warmupIterations = parseInt(args['warmup-iterations']) || 100
      const { times, iterations } = await captureTimings(warmupIterations)
      logResults({ times, iterations, warmupIterations })
    }
    
    ;(async () => {
      try {
        await main()
      } catch (e) {
        console.error(e)
        process.exit(1)
      }
    })()