GithubHelp home page GithubHelp logo

kick.js's Introduction

kick.js

sinatra style routing framework

var app = kick();

app.use(function(req, res, next) {
    req.hello = 'hello world';
    next();
})

app.get('/', function(req, res, next) {
    res.end(req.hello);
})

app.get('/user/:userid', function(req, res, next) {
    res.end(req.params.userid + req.hello);
})

benchmark

benchmark with siege.js, constant routing has similar RPS with helloworld, param routing (30 param routing defined) lose 5% RPS.

node hello world [code]

GET:/  without cookie
    done:100000
    200 OK: 100000
    rps: 7495
    response: 0ms(min)	17ms(max)	1ms(avg)

GET:/user/30/abcdefg  without cookie
    done:100000
    200 OK: 100000
    rps: 7577
    response: 0ms(min)	17ms(max)	1ms(avg)

kick example [code]

GET:/  without cookie
    done:100000
    200 OK: 100000
    rps: 7411
    response: 0ms(min)	18ms(max)	1ms(avg)

GET:/user/30/abcdefg  without cookie
    done:100000
    200 OK: 100000
    rps: 7079
    response: 0ms(min)	17ms(max)	1ms(avg)

app.configure(env, fn)

app.use(middleware, ...)

app.configure('development', function(){
    app.use(connect.logger('dev'))
    app.use(connect.static(__dirname + '/public'))
    app.use(connect.cookieParser('tobo!'))
    app.use(connect.session());
});

app.get(path, middleware, ...)

Constant routing, O(1)

app.get('/about', routes.about);

Param routing, O(N)

app.get('/user/:userid', function(req, res, next) {
    res.end(req.params.userid);
});

Above will match /user/123 and req.params.userid is 123

Regular expression routing, O(N)

app.get(/^\/user-(\d+)$/, function(req, res, next) {
    res.end(req.params[1])
});

Above will match /user-123 and req.params[1] is 123

N = count(params routing) + count(regular expression routing)

kick.js's People

Contributors

fengmk2 avatar guileen avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.