让CPU画正弦曲线

CUP曲线 #include #include #include using namespace std; //得到循环0xFFFFFFFF次用的秒数 unsigned int test() { unsigned int c = 0xFFFFFFFF; time_t t1, t2; time(&t1); for(unsigned int i = 0; i < c; i++) ; time(&t2); return (unsigned int)(t2 -t1); } #define T 20000 //周期时间 20秒 #define C 100 //采样点时间间隔 #define PI 3.1415 //PI const unsigned int count = 0xFFFFFFFF / (test() *1000); //采样间隔可以执行的循环数目 const unsigned int N = T/C; //周期内采样点数目 unsigned int v[N] = { 0 }; //所有采样点连续执行循环数 unsigned int mt[N] = { 0 }; //所有采样点休眠毫秒数 int main() { //计算循环次数和休眠时间 for(int i = 0; i < N; i++) { double x = 2 * PI * i / N; double r = (sin(x) + 1) / 2; mt[i] = C - r * C; v[i] = r * C * count; } for(;;) { for(int i = 0; i < N; i++) { for(int j = 0; j < v[i]; j++) ; Sleep(mt[i]); } } }

你可能感兴趣的:(让CPU画正弦曲线)