好吧,对于我的编程任务(是的,我们都可以转向我们认为适合帮助的任何源)我必须找出进程花费阻塞/休眠/运行的时间.
我的第一次尝试是创建一个bash脚本......看起来像这样:
for i in `ls /proc/ | egrep [0-9]+`
do
cat /proc/$i/status | grep State
done
Run Code Online (Sandbox Code Playgroud)
但后来所有问题都报告了睡眠状态.加上这种方法需要我疯狂地进行调查......所以运行测试可能会改变结果......(呃)
现在用syscalls编译新版本的linux或者跟踪进程状态的方法并不是不可能的.我唯一担心的是试图找出如何跟踪不断变化的过程状态,并确保我不会错过任何东西......
你如何运行一个长PHP脚本并继续通过HTTP向浏览器发送更新?
与输出缓冲有关但我不确切知道如何.
我很好奇大型结构的开销与使用运算符+和*数学的小结构.所以我做了两个结构,一个Small有1个双字段(8个字节),另一个Big有10个双字节(80个字节).在我的所有操作中,我只操纵一个叫做的字段x.
首先,我在两个结构中都定义了数学运算符
public static Small operator +(Small a, Small b)
{
return new Small(a.x + b.x);
}
public static Small operator *(double x, Small a)
{
return new Small(x * a.x);
}
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,它会占用堆栈中的大量内存来复制字段.我运行了5,000,000次迭代的数学运算并得到了我怀疑的(3倍减速).
public double TestSmall()
{
pt.Start(); // pt = performance timing object
Small r = new Small(rnd.NextDouble()); //rnd = Random number generator
for (int i = 0; i < N; i++)
{
a = 0.6 * a + …Run Code Online (Sandbox Code Playgroud) 我遇到了一个问题,UIAlertView我的应用程序中的所有内容都需要花费很长时间才能显示出来.显示屏立即变暗,但实际警报需要显示5秒钟.
我正在创建它们:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"Message"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
[alertView release];
Run Code Online (Sandbox Code Playgroud)
谁有过这个?
谢谢
-f
我想知道我们是否可以使用node.js来衡量完成http请求所需的时间.从文档(这里)稍微修改一个例子,可以很容易地写下以下代码.
var http = require('http');
var stamp1 = new Date();
var stamp2, stamp3, stamp4;
var options = {
hostname: 'www.google.com',
port: 80,
path: '/upload',
method: 'POST'
};
var req = http.request(options, function(res) {
stamp3 = new Date();
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
res.on('end', function () {
stamp4 = new Date();
console.log ("Stamp 3: " + stamp3);
console.log ("Stamp 4: " + stamp4);
});
});
req.on('error', …Run Code Online (Sandbox Code Playgroud)我感兴趣的是计算自由函数或成员函数(模板与否)的执行时间.调用TheFunc有问题的函数,它的调用是
TheFunc(/*parameters*/);
Run Code Online (Sandbox Code Playgroud)
要么
ReturnType ret = TheFunc(/*parameters*/);
Run Code Online (Sandbox Code Playgroud)
当然我可以按如下方式包装这些函数调用:
double duration = 0.0 ;
std::clock_t start = std::clock();
TheFunc(/*parameters*/);
duration = static_cast<double>(std::clock() - start) / static_cast<double>(CLOCKS_PER_SEC);
Run Code Online (Sandbox Code Playgroud)
要么
double duration = 0.0 ;
std::clock_t start = std::clock();
ReturnType ret = TheFunc(/*parameters*/);
duration = static_cast<double>(std::clock() - start) / static_cast<double>(CLOCKS_PER_SEC);
Run Code Online (Sandbox Code Playgroud)
但是我想做一些比这更优雅的事情,即(从现在起我将坚持使用void返回类型)如下:
Timer thetimer ;
double duration = 0.0;
thetimer(*TheFunc)(/*parameters*/, duration);
Run Code Online (Sandbox Code Playgroud)
其中Timer是我想设计的一些时序类,这将允许我编写前面的代码,这样在前面代码的最后一行的exectution之后,double duration将包含执行时间
TheFunc(/*parameters*/);
Run Code Online (Sandbox Code Playgroud)
但我不知道如何做到这一点,也不是我的目标语法/解决方案是最佳的...
假设:rAF now时间是在全部触发回调集时计算的.因此,在调用该帧的第一个回调之前发生的任何阻塞都不会影响rAF now并且它是准确的 - 至少对于第一次回调而言.
在触发rAF集之前进行的任何performance.now()测量应早于rAF now.
测试:记录before(发生任何事情之前的基线时间).设置下一个rAF.比较rAF now和实际performance.now()情况before,看看它们有多么不同.
预期成绩:
var before = performance.now(), frames = ["with blocking", "with no blocking"], calls = 0;
requestAnimationFrame(function frame(rAFnow) {
var actual = performance.now();
console.log("frame " + (calls + 1) + " " + frames[calls] + ":");
console.log("before frame -> rAF now: " + (rAFnow - before));
console.log("before frame -> rAF actual: " + (actual - before));
if (++calls < frames.length) …Run Code Online (Sandbox Code Playgroud)我正在对一个站点进行负载测试,并注意到我从Web服务器(在这种情况下,龙卷风Web服务器)和Chrome开发者工具收到的时间信息之间存在相当大的差异.Web服务器提供一个作为进程运行的服务(实际上,由主管管理的几个进程)在nginx后面.还有一个与此服务交互的Web界面.这个龙卷风Web服务器可以相当快地检索查询(平均30毫秒).但是,Chrome开发者工具显示的响应时间要慢得多(大约240毫秒).
每个查询都会检索一些信息,并需要查询其他资源(主要是图像).我认为这是造成这么大差异的主要原因,但我尝试使用curl并time_starttransfer测量172ms.
另一方面,对nginx使用此日志记录指令:
log_format timed_combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'$request_time $upstream_response_time $pipe';
Run Code Online (Sandbox Code Playgroud)
我能够检查它request_time并且upstream_response_time实际上非常小(45毫秒).
可能是造成这种响应时间差异的原因是什么?
UPDATE
这是Firebug的截图:
我不认为我可以用有限的信息找出延迟.
更新2
我能够通过curl获得更好的信息.不过我不确定它是否准确:
time_namelookup: 0.000
time_connect: 0.062
time_appconnect: 0.000
time_pretransfer: 0.062
time_redirect: 0.000
time_starttransfer: 0.172
----------
time_total: 0.240
Run Code Online (Sandbox Code Playgroud)
从我所看到的,time_starttransfer - time_pretransfer = content_generation所以0.172 - 0.062 = 0.110s.但是,查看日志,Web服务器报告0.044秒,并且request_time从nginx同意(0.045秒).此外,time_connect在curl输出中,我认为应该是延迟,并不是那么大(0.062s).
有趣的是,time_starttransfer - time_connect*2 = 0.048它类似于nginx或龙卷风报道的时间(0.048 vs 0.044).但这种计算不应该是正确的.有谁知道什么是正确的方法来证明chrome开发人员工具/ curl与web服务器/ nginx的响应时间之间的差异?
我想要一个程序,让用户有10秒钟的时间输入密码。如果计时器超过10秒,程序将显示一条消息。我当前的代码是这样的:
#include <iostream>
#include <ctime>
#include <string>
int main(){
std::string password;
int start_s=clock();
int stop_s=clock();
if(stop_s-start_s <= 0){
std::cout << "TIME RAN OUT!";
}
std::cout << "Enter your password! \n";
std::cout << "Password: ";
std::cin >> password;
std::cout << "\n \n";
if (password == "password123"){
std::cout << "Correct!";
} else {
std::cout << "Wrong!";
}
}
Run Code Online (Sandbox Code Playgroud)
这当然是行不通的...但是我不确定下一步该怎么做...有什么想法吗?
如果您需要更多详细信息,请在评论中提问。
编辑:
我刚刚意识到问题出在哪里……花了一个时间戳,然后迅速制作了另一个时间戳。当发现差异时,它低于0 ...
但是我仍然不知道下一步该怎么做...
我要实现的是检测屏幕上出现某些更改的准确时间(主要是使用Google Chrome浏览器)。例如,我使用显示项目$("xelement").show();或使用进行更改$("#xelement").text("sth new");,然后我想查看Performance.now()到底是什么,当更改以给定的屏幕重新绘制出现在用户的屏幕上时。因此,我完全可以接受任何解决方案-在下文中,我主要指的是requestAnimationFrame(rAF),因为这是应该帮助实现此功能的函数,只是似乎没有实现。见下文。
基本上,正如我所想象的,rAF应该在0-17毫秒内执行其中的所有操作(每当下一帧出现在我的标准60 Hz屏幕上)。此外,timestamp参数应提供此执行时间的值(并且该值基于与performance.now()相同的DOMHighResTimeStamp度量)。
现在,这是我为此进行的众多测试之一:https : //jsfiddle.net/gasparl/k5nx7zvh/31/
function item_display() {
var before = performance.now();
requestAnimationFrame(function(timest){
var r_start = performance.now();
var r_ts = timest;
console.log("before:", before);
console.log("RAF callback start:", r_start);
console.log("RAF stamp:", r_ts);
console.log("before vs. RAF callback start:", r_start - before);
console.log("before vs. RAF stamp:", r_ts - before);
console.log("")
});
}
setInterval(item_display, Math.floor(Math.random() * (1000 - 500 + 1)) + 500);
Run Code Online (Sandbox Code Playgroud)
我在Chrome中看到的是:rAF内的函数总是在大约0到3毫秒内执行(从紧接其前的performance.now()开始),最奇怪的是,rAF时间戳与我得到的完全不同rAF内的performance.now()通常比在rAF 之前调用的performance.now()早大约0-17毫秒(但有时在之后0-1毫秒)。
这是一个典型的例子:
before: 409265.00000001397
RAF callback start: 409266.30000001758
RAF stamp: 409260.832
before …Run Code Online (Sandbox Code Playgroud) timing ×10
javascript ×3
c++ ×2
animation ×1
c# ×1
cocoa-touch ×1
display ×1
http-request ×1
linux ×1
linux-kernel ×1
nginx ×1
node.js ×1
performance ×1
php ×1
scheduling ×1
scripting ×1
struct ×1
tornado ×1
uialertview ×1
updates ×1
winapi ×1
windows ×1