Test name | Executions per second |
---|---|
path part splitting and joining | 583397.5 Ops/sec |
looking up path separators | 1391124.4 Ops/sec |
const pathMap = new Map()
pathMap.set('test', 'site/app')
pathMap.set('vendor', 'site/vendor')
window.pathMap = pathMap
window.testId = 'test/lib/alpaca/js/alpaca'
const pathMap = window.pathMap
const parts = window.testId.split('/')
let modified
for (let { length } = parts; length > 0; --length) {
const parent = parts.slice(0, length).join('/')
const path = pathMap.get(parent)
if (path) {
parts.splice(0, length, path)
modified = true
break
}
}
const mapped = parts.join('/')
const pathMap = window.pathMap
let mapped = window.testId
for (let separator = mapped.length;;) {
const parent = mapped.substr(0, separator)
const path = pathMap.get(parent)
if (path) {
mapped = `${path}${mapped.substr(separator)}`
break
}
separator = mapped.lastIndexOf('/', separator - 1)
if (separator < 0) break
}