-
-
Save korayguclu/4ad6146f553a01253057ba03071259b6 to your computer and use it in GitHub Desktop.
Compare performance of Axios vs. SuperAgent when running under Node.js
This file contains hidden or 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 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