Skip to content

Instantly share code, notes, and snippets.

@ctbui
Forked from natesilva/axios-vs-superagent.js
Last active December 23, 2020 16:23
Show Gist options
  • Save ctbui/f1f6e5603a512aa79611003fe858a2e2 to your computer and use it in GitHub Desktop.
Save ctbui/f1f6e5603a512aa79611003fe858a2e2 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 got = require('got');
const superagent = require('superagent');
const suite = new Benchmark.Suite();
const targetUrl = 'http://httpbin.org/ip';
suite
.add('axios', {
defer: true,
fn(deferred) {
axios.get(targetUrl).then(() => {
deferred.resolve();
});
},
})
.add('got', {
defer: true,
fn(deferred) {
got.get(targetUrl).then(() => {
deferred.resolve();
});
},
})
.add('superagent - promise', {
defer: true,
fn(deferred) {
superagent.get(targetUrl).then(() => {
deferred.resolve();
});
},
})
.add('superagent - end method', {
defer: true,
fn(deferred) {
superagent.get(targetUrl).end(() => {
deferred.resolve();
});
},
})
.on('cycle', event => {
console.log(String(event.target));
console.log(`mean ${event.target.stats.mean}`);
console.log(`count ${event.target.stats.sample.length}`);
})
.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