[backend]更新脚本和库以支持性能测试用例
This commit is contained in:
43
testdata/performance/h-7-01.sy
vendored
Normal file
43
testdata/performance/h-7-01.sy
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
float i_buf[10000000];
|
||||
float o_buf[10000000];
|
||||
|
||||
float newtons_sqrt_recursive(float n, float x, float prec) {
|
||||
float r = (x + n / x) * 0.5;
|
||||
float d;
|
||||
if (x < r) {
|
||||
d = r - x;
|
||||
} else {
|
||||
d = x - r;
|
||||
}
|
||||
if (d <= prec) {
|
||||
return r;
|
||||
} else {
|
||||
return newtons_sqrt_recursive(n, r, prec);
|
||||
}
|
||||
}
|
||||
|
||||
float newtons_sqrt(float n) {
|
||||
const float prec = 0.0000000001;
|
||||
if (n <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
float x = (n + 1) * 0.5;
|
||||
return newtons_sqrt_recursive(n, x, prec);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n = getfarray(i_buf);
|
||||
starttime();
|
||||
|
||||
int i = 0;
|
||||
while (i < n) {
|
||||
o_buf[i] = newtons_sqrt(i_buf[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
stoptime();
|
||||
putfarray(n, o_buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user