Skip to content

Instantly share code, notes, and snippets.

@mtharrison
Created August 18, 2015 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtharrison/99801991298abdafe242 to your computer and use it in GitHub Desktop.
Save mtharrison/99801991298abdafe242 to your computer and use it in GitHub Desktop.
var Benchmark = require('benchmark');
var Hapi = require('hapi');
var Wreck = require('wreck');
var server = new Hapi.Server();
server.connection({ port: 4000 });
server.register(require('h2o2'), function () {});
var asyncBench = function(name, bench, callback) {
var opts = {
defer: true,
fn: function(deffered) {
bench(deffered.resolve.bind(deffered))
}
};
new Benchmark(name, opts)
.on('complete', function(event) {
callback(null, event)
})
.run({
async: true
});
};
server.route({
path: '/',
method: 'GET',
handler: {
proxy: {
uri: 'http://google.com'
}
}
});
// server.route({
// path: '/',
// method: 'GET',
// handler: function (request, reply) {
// reply('ok');
// }
// });
server.start(function (err) {
if (err) {
throw err;
}
asyncBench('server.inject()', inject, function (err, event) {
console.log(event.target.toString());
asyncBench('Wreck.get()', wreck, function (err, event) {
console.log(event.target.toString());
server.stop(function() {});
});
});
});
var inject = function (callback) {
server.inject('/', function (res) {
callback(null);
});
};
var wreck = function (callback) {
Wreck.get('http://localhost:4000', function (err, res, payload) {
if (err) {
throw err;
}
callback();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment