2020-03-11 12:34:34 +00:00
|
|
|
import assert from 'assert'
|
|
|
|
import Benchmark from 'benchmarkjs-pretty'
|
|
|
|
import { koaRouter1, koaRouter2 } from './router_koa.js'
|
2021-07-05 17:54:00 +00:00
|
|
|
import { flaskaRouter1, flaskaRouter2, flaskaClassRouter1, flaskaClassRouter2 } from './router_flaska.js'
|
2020-03-11 12:34:34 +00:00
|
|
|
import { expressRouter1, expressRouter2 } from './router_express.js'
|
|
|
|
import * as consts from './const.js'
|
|
|
|
|
|
|
|
let assertOk = true
|
|
|
|
let testData = null
|
|
|
|
|
|
|
|
consts.overrideDummy(function() { testData = assertOk })
|
|
|
|
|
|
|
|
function TestSmallStaticRoute() {
|
|
|
|
return new Benchmark.default('Small router static route benchmark: /api/staff (16 routes registered)')
|
|
|
|
.add('expressjs', function() {
|
|
|
|
testData = null
|
|
|
|
expressRouter1.handle({
|
|
|
|
url: '/api/staff',
|
|
|
|
method: 'GET',
|
|
|
|
}, {}, function() { })
|
|
|
|
assert.ok(testData)
|
|
|
|
})
|
|
|
|
.add('koa-router', function() {
|
|
|
|
testData = koaRouter1.match('/api/staff', 'GET')
|
|
|
|
assert.ok(testData.route)
|
|
|
|
})
|
|
|
|
.add('bottle-router', function() {
|
2020-05-20 13:14:25 +00:00
|
|
|
testData = flaskaRouter1.match('/api/staff')
|
2020-03-11 12:34:34 +00:00
|
|
|
assert.ok(testData.handler)
|
|
|
|
})
|
2021-07-05 17:54:00 +00:00
|
|
|
.add('bottle-router-alt', function() {
|
|
|
|
testData = flaskaClassRouter1.match('/api/staff')
|
|
|
|
assert.ok(testData.handler)
|
|
|
|
})
|
2020-03-11 12:34:34 +00:00
|
|
|
.run()
|
|
|
|
.then(function() {}, function(e) {
|
|
|
|
console.error('error:', e)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestSmallParamRoute() {
|
|
|
|
return new Benchmark.default('Small router param route benchmark: /api/staff/:id (16 routes registered)')
|
|
|
|
.add('expressjs', function() {
|
|
|
|
testData = null
|
|
|
|
expressRouter1.handle({
|
|
|
|
url: '/api/staff/justatest',
|
|
|
|
method: 'GET',
|
|
|
|
}, {}, function() { })
|
|
|
|
assert.ok(testData)
|
|
|
|
})
|
|
|
|
.add('koa-router', function() {
|
|
|
|
testData = koaRouter1.match('/api/staff/justatest', 'GET')
|
|
|
|
assert.ok(testData.route)
|
|
|
|
})
|
|
|
|
.add('bottle-router', function() {
|
2020-05-20 13:14:25 +00:00
|
|
|
testData = flaskaRouter1.match('/api/staff/justatest')
|
2020-03-11 12:34:34 +00:00
|
|
|
assert.ok(testData.handler)
|
|
|
|
})
|
2021-07-05 17:54:00 +00:00
|
|
|
.add('bottle-router-alt', function() {
|
|
|
|
testData = flaskaClassRouter1.match('/api/staff/justatest')
|
|
|
|
assert.ok(testData.handler)
|
|
|
|
})
|
2020-03-11 12:34:34 +00:00
|
|
|
.run()
|
|
|
|
.then(function() {}, function(e) {
|
|
|
|
console.error('error:', e)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestLargeStaticRoute() {
|
|
|
|
return new Benchmark.default('Large router static route benchmark: /api/staff (58 routes registered)')
|
|
|
|
.add('expressjs', function() {
|
|
|
|
testData = null
|
|
|
|
expressRouter2.handle({
|
|
|
|
url: '/api/staff',
|
|
|
|
method: 'GET',
|
|
|
|
}, {}, function() { })
|
|
|
|
assert.ok(testData)
|
|
|
|
})
|
|
|
|
.add('koa-router', function() {
|
|
|
|
testData = koaRouter2.match('/api/staff', 'GET')
|
|
|
|
assert.ok(testData.route)
|
|
|
|
})
|
|
|
|
.add('bottle-router', function() {
|
2020-05-20 13:14:25 +00:00
|
|
|
testData = flaskaRouter2.match('/api/staff')
|
2020-03-11 12:34:34 +00:00
|
|
|
assert.ok(testData.handler)
|
|
|
|
})
|
2021-07-05 17:54:00 +00:00
|
|
|
.add('bottle-router-alt', function() {
|
|
|
|
testData = flaskaClassRouter2.match('/api/staff')
|
|
|
|
assert.ok(testData.handler)
|
|
|
|
})
|
2020-03-11 12:34:34 +00:00
|
|
|
.run()
|
|
|
|
.then(function() {}, function(e) {
|
|
|
|
console.error('error:', e)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestLargeParamRoute() {
|
|
|
|
return new Benchmark.default('Large router param route benchmark: /api/staff/:id (58 routes registered)')
|
|
|
|
.add('expressjs', function() {
|
|
|
|
testData = null
|
|
|
|
expressRouter2.handle({
|
|
|
|
url: '/api/staff/justatest',
|
|
|
|
method: 'GET',
|
|
|
|
}, {}, function() { })
|
|
|
|
assert.ok(testData)
|
|
|
|
})
|
|
|
|
.add('koa-router', function() {
|
|
|
|
testData = koaRouter2.match('/api/staff/justatest', 'GET')
|
|
|
|
assert.ok(testData.route)
|
|
|
|
})
|
|
|
|
.add('bottle-router', function() {
|
2020-05-20 13:14:25 +00:00
|
|
|
testData = flaskaRouter2.match('/api/staff/justatest')
|
2020-03-11 12:34:34 +00:00
|
|
|
assert.ok(testData.handler)
|
|
|
|
})
|
2021-07-05 17:54:00 +00:00
|
|
|
.add('bottle-router-alt', function() {
|
|
|
|
testData = flaskaClassRouter2.match('/api/staff/justatest')
|
|
|
|
assert.ok(testData.handler)
|
|
|
|
})
|
|
|
|
.run()
|
|
|
|
.then(function() {}, function(e) {
|
|
|
|
console.error('error:', e)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestLargeParamLargeUrlRoute() {
|
|
|
|
return new Benchmark.default('Large router param route long route benchmark: /api/products/:id/sub_products/:productId (58 routes registered)')
|
|
|
|
.add('expressjs', function() {
|
|
|
|
testData = null
|
|
|
|
expressRouter2.handle({
|
|
|
|
url: '/api/products/justatest/sub_products/foobar',
|
|
|
|
method: 'GET',
|
|
|
|
}, {}, function() { })
|
|
|
|
assert.ok(testData)
|
|
|
|
})
|
|
|
|
.add('koa-router', function() {
|
|
|
|
testData = koaRouter2.match('/api/products/justatest/sub_products/foobar', 'GET')
|
|
|
|
assert.ok(testData.route)
|
|
|
|
})
|
|
|
|
.add('bottle-router', function() {
|
|
|
|
testData = flaskaRouter2.match('/api/products/justatest/sub_products/foobar')
|
|
|
|
assert.ok(testData.handler)
|
|
|
|
})
|
|
|
|
.add('bottle-router-alt', function() {
|
|
|
|
testData = flaskaClassRouter2.match('/api/products/justatest/sub_products/foobar')
|
|
|
|
assert.ok(testData.handler)
|
|
|
|
})
|
2020-03-11 12:34:34 +00:00
|
|
|
.run()
|
|
|
|
.then(function() {}, function(e) {
|
|
|
|
console.error('error:', e)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
TestSmallStaticRoute()
|
|
|
|
.then(function() {
|
|
|
|
return TestSmallParamRoute()
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
return TestLargeStaticRoute()
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
return TestLargeParamRoute()
|
|
|
|
})
|
2021-07-05 17:54:00 +00:00
|
|
|
.then(function() {
|
|
|
|
return TestLargeParamLargeUrlRoute()
|
|
|
|
})
|
2020-03-11 12:34:34 +00:00
|
|
|
.then(function() {
|
|
|
|
process.exit(0)
|
|
|
|
})
|