Skip to content
Snippets Groups Projects
Select Git revision
  • b0cc608045c1142bd68bff7fea8c3663d56d89df
  • main default protected
  • feat/gnupg
  • next
  • fix/36615b-branch-reuse-no-cache
  • renovate/main-redis-5.x
  • chore/punycode
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • fix/32307-global-extends-repositories
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • gh-readonly-queue/next/pr-35009-9d5e583b7d7251148ab0d11ee8dd38149618d162
  • 41.43.5
  • 41.43.4
  • 41.43.3
  • 41.43.2
  • 41.43.1
  • 41.43.0
  • 41.42.12
  • 41.42.11
  • 41.42.10
  • 41.42.9
  • 41.42.8
  • 41.42.7
  • 41.42.6
  • 41.42.5
  • 41.42.4
  • 41.42.3
  • 41.42.2
  • 41.42.1
  • 41.42.0
  • 41.41.0
41 results

static-files.spec.ts

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)
      }
    })()