Skip to content

Instantly share code, notes, and snippets.

@lukeed
Created January 12, 2018 09:15
Show Gist options
  • Save lukeed/60bdb0f5710ddcff4b4b6a80013f3035 to your computer and use it in GitHub Desktop.
Save lukeed/60bdb0f5710ddcff4b4b6a80013f3035 to your computer and use it in GitHub Desktop.
Polka vs Micro vs Native

Micro vs Polka vs Native

This is a quick benchmark test for Polka against Micro, as requested here.

While this does not include the recommended micro-route, I think that actually helps Micro's cause in this scenario.

Considerations

  • Both the Micro & Native apps are not checking for METHOD matches
  • Both the Micro & Native apps are using a hardcoded substring() to get the "parameter" value
  • Micro is using the same "routing" as the Native app
  • Polka is auto-parsing the parameter(s)
  • Polka is using the METHOD to match
  • Polka ships with a full router & middleware support out of the box

Results

Running all benchmarkks on Node v8.9.0. Results copied from the 2nd run (1 warm up).

The numbers may be slightly different for your machine, but the ratios should be the same~!

👉 Include obligatory note about benchmarks like these not reflecting real-world apps.

Index Route

$ wrk -t8 -c100 -d10s http://localhost:3000
Native
    Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency     2.25ms  159.04us   7.23ms   92.74%
        Req/Sec     5.36k   183.08     5.57k    92.25%
      426815 requests in 10.01s, 42.33MB read
    Requests/sec:  42658.47
    Transfer/sec:      4.23MB

Polka
    Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency     2.26ms  282.75us   7.79ms   94.07%
        Req/Sec     5.34k   807.26    21.49k    96.51%
      426284 requests in 10.10s, 42.28MB read
    Requests/sec:  42207.02
    Transfer/sec:      4.19MB

Micro
    Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency     2.68ms  274.34us   7.28ms   86.71%
        Req/Sec     4.50k   432.66    11.31k    98.63%
      359922 requests in 10.10s, 35.70MB read
    Requests/sec:  35635.15
    Transfer/sec:      3.53MB

User Route

$ wrk -t8 -c100 -d10s http://localhost:3000/user/123
Native
    Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency     2.31ms  214.32us   7.19ms   92.59%
        Req/Sec     5.21k   542.24    13.82k    98.63%
      416473 requests in 10.10s, 45.28MB read
    Requests/sec:  41232.98
    Transfer/sec:      4.48MB

Polka
    Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency     2.49ms  187.35us   7.02ms   86.56%
        Req/Sec     4.83k   151.13     5.64k    89.47%
      387957 requests in 10.10s, 42.18MB read
    Requests/sec:  38400.93
    Transfer/sec:      4.17MB

Micro
    Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency     2.77ms  271.69us  10.90ms   86.67%
        Req/Sec     4.35k   203.21     5.69k    91.44%
      349269 requests in 10.10s, 37.97MB read
    Requests/sec:  34566.77
    Transfer/sec:      3.76MB
const micro = require('micro');
micro((req, res) => {
if (req.url === '/') {
return 'Hello';
}
if (req.url.indexOf('/user/') === 0) {
// cheating, but ok
return `Hello user ${req.url.substring(6)}`;
}
}).listen(3000);
const http = require('http');
http.createServer((req, res) => {
if (req.url === '/') {
return res.end('Hello');
}
if (req.url.indexOf('/user/') === 0) {
// cheating, but ok
return res.end(`Hello user ${req.url.substring(6)}`);
}
}).listen(3000);
const polka = require('polka');
polka()
.get('/', (req, res) => {
res.end('Hello');
})
.get('/user/:id', (req, res) => {
res.end(`Hello user ${req.params.id}`);
})
.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment