Skip to content

Instantly share code, notes, and snippets.

@iurisilvio
Last active January 30, 2022 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iurisilvio/a916ce2de16336ec97aab8db5525f7f9 to your computer and use it in GitHub Desktop.
Save iurisilvio/a916ce2de16336ec97aab8db5525f7f9 to your computer and use it in GitHub Desktop.
vue-router optimization
/*eslint-disable no-undef*/
import timeit from 'timeit'
import { createMatcher } from '../../../src/create-matcher'
fdescribe('Bench', function () {
const data = []
for (let i = 0; i < 100; i++) {
const path = `/static/${i}`
const name = `static-${i}`
data.push({ path, name, component: { name }})
}
it('bench', function (done) {
_timeit(data, ['/static/1', '/static/50', '/static/100'], done)
})
})
function _timeit (data, paths, done) {
function factory (path) {
return function match (done) {
matcher.match(path)
done()
}
}
const matcher = createMatcher(data)
const iterations = 100000
timeit.howlong(iterations, paths.map(factory), function (err, results) {
if (err) {
console.log('DO NOTHING')
}
console.log('Baseline', results[0])
paths.forEach((path, index) => {
console.log(`Speed ${path}`, results[index + 1])
})
done()
})
}
Baseline {
  total_runtime: 171,
  total_step_runtime: 8,
  average_step_runtime: 0.00008
}
Speed /static/1 {
  total_runtime: 280,
  total_step_runtime: 104,
  average_step_runtime: 0.00104,
  total_off_baseline: 109,
  total_step_off_baseline: 96,
  average_step_off_baseline: 0.0009599999999999999
}
Speed /static/50 {
  total_runtime: 258,
  total_step_runtime: 90,
  average_step_runtime: 0.0009,
  total_off_baseline: 87,
  total_step_off_baseline: 82,
  average_step_off_baseline: 0.00082
}
Speed /static/100 {
  total_runtime: 278,
  total_step_runtime: 103,
  average_step_runtime: 0.00103,
  total_off_baseline: 107,
  total_step_off_baseline: 95,
  average_step_off_baseline: 0.0009500000000000001
}
Baseline {
  total_runtime: 193,
  total_step_runtime: 12,
  average_step_runtime: 0.00012
}
Speed /static/1 {
  total_runtime: 311,
  total_step_runtime: 142,
  average_step_runtime: 0.00142,
  total_off_baseline: 118,
  total_step_off_baseline: 130,
  average_step_off_baseline: 0.0013
}
Speed /static/50 {
  total_runtime: 935,
  total_step_runtime: 753,
  average_step_runtime: 0.00753,
  total_off_baseline: 742,
  total_step_off_baseline: 741,
  average_step_off_baseline: 0.00741
}
Speed /static/100 {
  total_runtime: 1573,
  total_step_runtime: 1413,
  average_step_runtime: 0.01413,
  total_off_baseline: 1380,
  total_step_off_baseline: 1401,
  average_step_off_baseline: 0.01401
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment