Skip to content

Instantly share code, notes, and snippets.

@matteofigus
Last active January 23, 2018 13:23
Show Gist options
  • Save matteofigus/6651234 to your computer and use it in GitHub Desktop.
Save matteofigus/6651234 to your computer and use it in GitHub Desktop.
An example of request/response using api-benchmark with node.js https://github.com/matteofigus/api-benchmark
var apiBenchmark = require('api-benchmark');
var services = {
".NET": "http://localhost:57382/my-api/v1/",
"nodeJS": "http://localhost:3000/my-api/v1/"
};
var routes = {
"getUsers": "users/get",
"getUserInfo": "users/12345/get-info"
};
var options = { debug: true, minSamples: 100, maxTime: 5 };
apiBenchmark.compare(services, routes, options, function(err, results){
console.log(results);
/* displays:
.NET/getUsers x 58.37 ops/sec ±16.98% (173 runs sampled)
nodeJS/getUsers x 188 ops/sec ±0.99% (179 runs sampled)
======================================
Fastest is nodeJS/getUsers
.NET/getUserInfo x 49.16 ops/sec ±12.71% (153 runs sampled)
nodeJS/getUserInfo x 106 ops/sec ±1.19% (180 runs sampled)
======================================
Fastest is nodeJS/getUserInfo
======================================
Fastest Service is nodeJS
{ '.NET':
{ getUsers:
{ name: '.NET/getUsers',
href: 'http://localhost:57382/my-api/v1/users/get',
stats: [Object],
cycles: 3,
hz: 58.36824401380643 },
'getUserInfo':
{ name: '.NET/getUserInfo',
href: 'http://localhost:57382/my-api/v1/users/12345/get-info',
stats: [Object],
cycles: 3,
hz: 49.16409187790408 },
isSlowest: true },
nodeJS:
{ getUsers:
{ name: 'nodeJS/getUsers',
href: 'http://localhost:3000/my-api/v1/users/get',
stats: [Object],
cycles: 2,
hz: 187.5014849827169 },
'getUserInfo':
{ name: 'nodeJS/getUserInfo',
href: 'http://localhost:3000/my-api/v1/users/12345/get-info',
stats: [Object],
cycles: 3,
hz: 105.85228376312513 },
isFastest: true } }
*/
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment