如何提高分析的准确性 [英] How to improve accuracy of profiling

查看:79
本文介绍了如何提高分析的准确性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想缩短某些代码的运行时间.

为了使我第一次运行所有相关代码,请使用如下代码:

before:= rdtsc;
myobject.run;
after:= rdtsc;

然后我放大并计时相关部分,就像这样:

procedure myobject.part;
begin
  StartTime:= rdtsc;
  ...
  EndTime:= rdtsc;
  inc(TotalTime, (EndTime- StartTime));
end;

我有一些代码可以将计时复制粘贴到Excel中,典型结果如下:


(89.8%和10.2%的总和是100%的巧合,与数据或问题无关)
(当数据显示1时,它表示0避免被零错误除法)

请注意run Arun B之间的区别.
我还没有更改任何内容,所以运行A和B应该给出相同的运行时间.
还要注意,我知道在两次运行中,过程part的调用次数完全相同(数据相同且算法是确定性的).

过程part的运行时间非常短(被多次调用).
如果在这种短暂的运行时间突发(少于700个CPU周期)中有某种方法可以阻止其他进程,那么我的计时将更加准确.

如何使这些时间更可靠?
是否有一种方法可以让CPU独占时间,仅在计时时运行我的任务?

请注意,我并不是在寻找明显的答案,例如:
-关闭其他正在运行的程序
-禁用virusscanner等...

我已经标记了问题 Delphi ,因为我现在正在使用Delphi(并且可能会有一些特定于Delphi的选项来实现此结果). 我也将其标记为与语言无关,因为可能会有一些更通用的方法.

更新
因为我使用的是CPU指令RDTSC,所以我不受CPU节流的影响.如果CPU速度变慢,则周期数保持不变.

Update2
我有2个答案,但没有一个答案...
问题是如何防止运行时间发生这些变化? 我是否必须运行20x的代码并始终比较20次运行中的最低运行时间?
还是我将程序优先级设置为realtime?
还是有其他技巧可以使用,以使我的代码示例不会被打断?

解决方案

要缩短某些代码的运行时间.

为了使我第一次运行所有相关代码,...

好的,关于这个问题,我的记录有些滞后,但是很多人认为,要缩短运行时间,首先需要对其进行准确的测量.

不是.

提高运行时间需要找出花费大量时间的时间(精确的时间段无关紧要),并以不同的方式进行工作,或者根本不做. 通常不会通过计时各个例程来揭示它的功能.

这是我使用的方法, 这是它的非常业余的视频 .

I want to improve the running time of some code.

In order to that I first time the running time of all relevant code, using code like this:

before:= rdtsc;
myobject.run;
after:= rdtsc;

Then I zoom in and time a relevant part, like so:

procedure myobject.part;
begin
  StartTime:= rdtsc;
  ...
  EndTime:= rdtsc;
  inc(TotalTime, (EndTime- StartTime));
end;

I have some code to copy paste the timings into Excel, a typical outcome would look like:


(the 89.8% and 10.2% adding up to 100% is a coincidence and has nothing to do with the data or the question)
(when the data shows 1 it means 0 to avoid divide by zero errors)

Note the difference between run A and run B.
I have not changed anything yet so run A and B should give the same running time.
Further note that I know that on both runs procedure part was invoked exactly the same number of times (the data is the same and the algorithm is deterministic).

The running time of procedure part is very short (it is just called many times).
If there was some way to block out other processes during these short bursts of runtime (less than 700 CPU cycles) my timings would be much more accurate.

How do I get these timings to be more reliable?
Is there a way to monopolize the CPU to only run my task when timing and nothing else?

Note that I'm not looking for obvious answers like:
- Close other running programs
- Disable the virusscanner etc...

I've tagged the question Delphi because I'm using Delphi right now (and there may be some Delphi specific option to achieve this result). I've also tagged it language-agnostic because there may be some more general way.

Update
Because I'm using the CPU instruction RDTSC I'm not affected by CPU throttling. If the CPU slows down, the number of cycles stays the same.

Update2
I have 2 answers, but neither answers the question...
The question is how do I prevent these changes in running time? Do I have to run the code 20x and always compare the lowest running time out of the 20 runs?
Or to I set my program priority to realtime?
Or is there some other trick to use so my code sample does not get interrupted?

解决方案

To want to improve the running time of some code.

In order to that I first time the running time of all relevant code, ...

OK, I'm a bit of a stuck record on this subject, but lots of people think that to improve running time requires first measuring it accurately.

Not So.

Improving running time requires finding out what's taking a large fraction of time (the exact fraction does not matter) and doing it differently or maybe not at all. What it's doing is often not revealed by timing individual routines.

Here's the method I use, and here's a very amateur video of it.

这篇关于如何提高分析的准确性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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