相关疑难解决方法(0)

如何获取Windows上每个线程的CPU使用率(win32)

寻找Win32 API函数,C++或Delphi示例代码,它告诉我线程的CPU使用率(百分比和/或总CPU时间)(而不是进程的总和).我有线程ID.

我知道Sysinternals Process Explorer可以显示这些信息,但我在程序中需要这些信息.

c++ delphi winapi multithreading cpu-usage

19
推荐指数
4
解决办法
3万
查看次数

测量c ++中popcount函数的时间

我感兴趣的是如何把它放在循环中,以便获得cpu执行每个不同操作的实时时间

#include<iostream>
#include<cstdlib>
#include<time.h>

using namespace std;
typedef unsigned __int64 uint64;
const uint64 m1=0x5555555555555555;
const uint64 m2=0x3333333333333333;
const uint64 m4=0x0f0f0f0f0f0f0f0f;
const uint64 m8=0x00ff00ff00ff00ff;
const uint64 m16=0x0000ffff0000ffff;
const uint64 m32=0x00000000ffffffff;
const uint64 hff=0xffffffffffffffff;
const uint64 h01=0x0101010101010101;

uint64 popcount_1(uint64 x)
{
    x=(x&m1)+((x>>1)&m1);
    x=(x&m2)+((x>>2)&m2);
    x=(x&m4)+((x>>4)&m4);
    x=(x&m8)+((x>>8)&m8);
    x=(x&m16)+((x>>16)&m16);
    x=(x&m32)+((x>>32)&m32);
    return (uint64)x;
}

//This uses fewer arithmetic operations than any other known
//implementation on machines with slow multiplication.
//It uses 17 arithmetic operations.
int popcount_2(uint64 x)
{
    x-=(x>>1)&m1;//put count of each 2 bits into those …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm bit cpu-speed

0
推荐指数
1
解决办法
1588
查看次数

标签 统计

c++ ×2

algorithm ×1

bit ×1

cpu-speed ×1

cpu-usage ×1

delphi ×1

multithreading ×1

winapi ×1