-
-
Save seanpascoe/37eec9ac18ed7a637a71d22379dbe4bf to your computer and use it in GitHub Desktop.
Compare performance of Axios vs. SuperAgent when running under Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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