Skip to content

Instantly share code, notes, and snippets.

@natesilva
Created August 31, 2017 15:39
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save natesilva/24597d954f392b21467b83403756f121 to your computer and use it in GitHub Desktop.
Save natesilva/24597d954f392b21467b83403756f121 to your computer and use it in GitHub Desktop.
Compare performance of Axios vs. SuperAgent when running under Node.js
const Benchmark = require('benchmark');
const axios = require('axios');
const superagent = require('superagent');
var suite = new Benchmark.Suite;
const targetUrl = 'http://httpbin.org/ip';
suite
.add('axios', {
defer: true,
fn: function(deferred) {
axios.get(targetUrl).then(function() { deferred.resolve(); });
}
})
.add('superagent - promise', {
defer: true,
fn: function(deferred) {
superagent.get(targetUrl).then(function() { deferred.resolve(); });
}
})
.add('superagent - end method', {
defer: true,
fn: function(deferred) {
superagent.get(targetUrl).end(function() { deferred.resolve(); });
}
})
.on('cycle', function(event) { console.log(String(event.target)) })
.on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ async: true })
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment