Compare commits

...

1 commit

Author SHA1 Message Date
c4f59fbb01 temp 2024-11-03 09:27:39 +00:00
5 changed files with 1278 additions and 13 deletions

View file

@ -1,9 +1,10 @@
import { summary, run, bench } from 'mitata'; import { summary, run, bench } from 'mitata';
import { createRouter, insertItem } from '@mapl/router' import { createRouter, insertItem } from '@mapl/router'
import { compileRouter } from './mapl_compiler.mjs' import { compileRouter } from './mapl_compiler.mjs'
import assert from 'assert'
import { compilePaths } from "./router_v2.mjs" import { compilePaths } from "./router_v2.mjs"
import { compilePaths as mainCompiler, compilePathsClosure } from "../router_v2.mjs" import { compilePaths as mainCompiler } from "../router_v2.mjs"
import { FlaskaRouter as FlaskaRouterBuffer } from "../flaska_buffer.mjs"
import { FlaskaRouter as FlaskaRouterFast } from "../flaska_fast.mjs"
import * as consts from './const.js' import * as consts from './const.js'
function printCurrentStatus(fn) { function printCurrentStatus(fn) {
@ -36,13 +37,21 @@ function printStatusHelperText() {
bench('noop', () => { }); bench('noop', () => { });
bench('noop2', () => { }); bench('noop2', () => { });
let paths = consts.allManyRoutes.map(x => ({ path: x })) let paths = consts.allRoutes.map(x => ({ path: x }))
let tests = paths.map(p => ([p.path.replace(/:[^/]+/g, '_'), p])) let tests = paths.map(p => ([p.path.replace(/:[^/]+/g, '_'), p]))
let testStrings = tests.map(x => x[0]) let testStrings = tests.map(x => x[0])
let testStringsMapl = testStrings.map(x => x.slice(1)) let testStringsMapl = testStrings.map(x => x.slice(1))
let func = [[testStrings, mainCompiler(paths)]]
let func = [[testStrings, ...mainCompiler(paths)]] let flaskaRouterBuffer = new FlaskaRouterBuffer()
func.push([testStrings, ...compilePathsClosure(paths)]) flaskaRouterBuffer.paths = paths.slice()
flaskaRouterBuffer.compile()
func.push([testStrings, flaskaRouterBuffer.match])
let flaskaRouterFast = new FlaskaRouterFast()
flaskaRouterFast.paths = paths.slice()
flaskaRouterFast.compile()
func.push([testStrings, flaskaRouterFast.match])
let maplPaths = paths.map(x => x.path.replace(/::[^\/]+/g, '**').replace(/:[^\/]+/g, '*')) let maplPaths = paths.map(x => x.path.replace(/::[^\/]+/g, '**').replace(/:[^\/]+/g, '*'))
const maplRouter = createRouter(); const maplRouter = createRouter();
@ -51,15 +60,15 @@ for (let route of maplPaths) {
} }
let maplMatcher = compileRouter(maplRouter) let maplMatcher = compileRouter(maplRouter)
func.push([testStringsMapl, maplMatcher, maplMatcher]) func.push([testStringsMapl, maplMatcher])
for (let [tests, _, fun] of func) { for (let [tests, fun] of func) {
console.log(`--- warming up ${fun.name || 'mapl'} ---`) console.log(`--- warming up ${fun.name || 'mapl'} ---`)
for (var i = 0; i < 10000; i++) { for (var i = 0; i < 100000; i++) {
tests.forEach(fun) tests.forEach(fun)
} }
} }
for (let [tests, _, fun] of func) { for (let [tests, fun] of func) {
console.log(`--- Sanity checking ${fun.name || 'mapl'} ---`) console.log(`--- Sanity checking ${fun.name || 'mapl'} ---`)
for (let a of tests) { for (let a of tests) {
// console.log(a, fun(a)) // console.log(a, fun(a))
@ -73,9 +82,9 @@ for (let [_, org] of func) {
printStatusHelperText() printStatusHelperText()
summary(() => { summary(() => {
func.forEach(function([tests, _, fun]) { func.forEach(function([tests, fun]) {
// console.log(tests, fun, tests.map(fun)) // console.log(tests, fun, tests.map(fun))
bench((fun.name || 'bound mapl').slice(6), function() { bench(fun.name || 'mapl', function() {
return tests.map(fun) return tests.map(fun)
}) })
}) })

View file

@ -611,7 +611,7 @@ export class FlaskaRouter {
} }
output += '\n' + indentString + ` },` output += '\n' + indentString + ` },`
} else { } else {
output += '\n' + indentString + ` params: {},` output += '\n' + indentString + ` params: {},`
} }
output += '\n' + indentString + `}` output += '\n' + indentString + `}`
return output return output

View file

@ -674,7 +674,8 @@ export class FlaskaRouter {
} }
__treeIntoCompiledCodeClosure(paths, tree, staticList) { __treeIntoCompiledCodeClosure(paths, tree, staticList) {
let output = 'return function RBufferStrSliceClosure(str) {' let output = "'use strict'"
output += '\nreturn function flaskaBufferStrClos(str) {'
if (staticList.size > 0) { if (staticList.size > 0) {
output += '\n let checkStatic = staticList.get(str)' output += '\n let checkStatic = staticList.get(str)'
output += '\n if(checkStatic) {' output += '\n if(checkStatic) {'

1235
flaska_fast.mjs Normal file

File diff suppressed because one or more lines are too long

20
test_fast.mjs Normal file
View file

@ -0,0 +1,20 @@
import { Flaska } from './flaska_fast.mjs'
const port = 51028
const flaska = new Flaska({}, )
flaska.get('/', function(ctx) {
ctx.body = { status: true }
})
flaska.get('/:item/asdf/herp/:derp/bla', function(ctx) {
ctx.body = { item: ctx.params.item }
})
flaska.get('/error', function(ctx) {
process.exit(1)
})
flaska.listen(port, function() {
console.log('listening on port', port)
})