Skip to content

Instantly share code, notes, and snippets.

@Om4ar
Forked from natesilva/axios-vs-superagent.js
Created June 2, 2019 09:49
Show Gist options
  • Save Om4ar/ae3a9ac70daec81d5baaecdf7a02d0fb to your computer and use it in GitHub Desktop.
Save Om4ar/ae3a9ac70daec81d5baaecdf7a02d0fb 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