问题描述
如果我使用 Axios 和 Superagent 一个接一个地调用同一个 api 我在两种情况下都首先在控制台日志中得到 Superagent 的响应,即如果我先调用一个而不是另一个,反之亦然.这是否意味着一个比另一个更快,还是完全不同?
If I use Axios and Superagent to make a call to the same api one after another I get Superagent's response first in the console logs in both cases i.e if I call one first than the other and vice versa. Does that mean one is faster than the other or is something else entirely?
getUser() {
axios.get('/api/getuser')
.then((res) => {
console.log(err,res)
})
.catch((err,res) => {
console.log(err,res)
})
request
.get('api/getuser')
.end((err, res) => {
console.log(err,res)
});
}
推荐答案
差异不太可能与客户端的原始速度有关.两者都使用 Node 的 HTTP 库或浏览器的内置 XMLHttpRequest
.您所观察到的很可能是与事件处理相关的时间略有不同.
The difference is unlikely to be related to the raw speed of the client. Both use Node’s HTTP library or the browser’s built-in XMLHttpRequest
. Most likely what you’ve observed are slight differences in timing related to event handling.
我会根据其他因素做出决定,例如您更喜欢哪种 API,以及库大小(对于浏览器端应用程序).
I’d base my decision on other factors, like which API you like better, and library size (for a browser-side application).
这是 Axios 和 SuperAgent 的浏览器端测试用例:https://jsperf.com/axios-vs-superagent/ 和这里的服务器端测试:https://gist.github.com/natesilva/24597d954f392b21467b83403756f121
Here’s a browser-side test case for Axios and SuperAgent: https://jsperf.com/axios-vs-superagent/ and here’s a server-side test: https://gist.github.com/natesilva/24597d954f392b21467b83403756f121
对我来说,在这些测试中,Axios 在浏览器中速度更快,SuperAgent 在 Node.js 下速度更快.
For me, on these tests, Axios is faster in the browser and SuperAgent is faster under Node.js.
这篇关于Axios 与 Superagent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!