考虑:
#include <time.h>
#include <unistd.h>
#include <iostream>
using namespace std;
const int times = 1000;
const int N = 100000;
void run() {
for (int j = 0; j < N; j++) {
}
}
int main() {
clock_t main_start = clock();
for (int i = 0; i < times; i++) {
clock_t start = clock();
run();
cout << "cost: " << (clock() - start) / 1000.0 << " ms." << endl;
//usleep(1000);
}
cout << "total cost: " << …Run Code Online (Sandbox Code Playgroud) 是否有Windows平台上类似Unix命令的,漂亮的?
我特意在命令行中查找可以使用的内容,而不是任务管理器中的"设置优先级"菜单.
我在谷歌上发现这种情况的尝试已被那些无法想出更好形容词的人所挫败.
如何在C#中暂停整个过程(就像我点击Suspend时的Process Explorer一样).
我正在使用Process.Start启动Process,并且在某个事件上,我想暂停该进程以便能够对其"快照"进行一些调查.
我们可以在C#应用程序中设置两个线程或两个任务以执行不同的处理器关联吗?
我已经读过SetThreadAffinityMask但没有找到应该如何使用的例子.
或者,TPL(任务并行库)有没有办法执行两个线程/高优先级的任务来使用100%的CPU?
我需要编写一个类,它将附加到某些Windows进程,监视和限制其CPU使用率.流程优先级的改变对我没有帮助,所以我真的需要编写一个与BES或ThreadMaster基本类似的程序.所以我需要创建一个类似这样的类(伪代码):
public void cpuLimiter(pid)
{
ProcessHandle handle = attachToProcess(pid);
while (cpuLimiting)
{
if (handle.cpuUsage > 30%)
{
handle.sleep(100miliseconds);
}
sleep(10miliseconds);
}
closeHandle(pid);
}
Run Code Online (Sandbox Code Playgroud)
我希望我说清楚我想要完成什么,只是我不知道如何.感谢每一位帮助.
c# ×3
.net ×2
benchmarking ×1
c++ ×1
cpu-time ×1
cpu-usage ×1
linux ×1
performance ×1
unix ×1
windows ×1