所以,我正在用线程做一些基准测试,我写了这些代码:
resp_threadless []和resp_threaded []是全局int数组,它们的大小是n;
int n = 100000;
void function() {
for (long j = 0; j < n; ++j) {
int count = 0;
double x = vetor[j];
while (x > 1.0) {
x = sqrt(x);
++count;
}
resp_threadless[j] = count;
}
}
DWORD WINAPI function_th( LPVOID lpParam ) {
for (long j = 0; j < n; ++j) {
int count = 0;
double x = vetor[j];
while (x > 1.0) {
x = sqrt(x);
++count;
}
resp_threadless[j] …Run Code Online (Sandbox Code Playgroud)