Node.js:获取响应时间 [英] Node.js: Get Response Time

查看:1182
本文介绍了Node.js:获取响应时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何知道网址的响应时间?

How can I know the response time of a URL?

我正在使用 http.get()发出HTTP GET请求。

I'm using http.get() to make an HTTP GET request.

推荐答案

没有内置函数或值来获取响应时间。

There's no builtin function or value to get the response time.

但你可以自己轻松获得价值。

But you can easily get the value yourself.

var http = require('http');
var start = new Date();
http.get({host: 'google.com', port: 80}, function(res) {
    console.log('Request took:', new Date() - start, 'ms');
});

编辑

由于V8还支持新的ES5 Date.now(),使用它代替 new Date()有点干净。

Since V8 also supports the new ES5 Date.now(), using that instead of new Date() would be a little bit cleaner.

这篇关于Node.js:获取响应时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆