[backend]更新脚本和库以支持性能测试用例
This commit is contained in:
96
testdata/performance/sort_search.sy
vendored
Normal file
96
testdata/performance/sort_search.sy
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
const int global_int = 303;
|
||||
const float global_float = 3.14;
|
||||
const int space = 32;
|
||||
const int maxN=10000;
|
||||
int sorted_array[maxN];
|
||||
|
||||
void bubble_sort(int arr[], int n) {
|
||||
int i;
|
||||
i = 0;
|
||||
int j;
|
||||
while(i < n-1){
|
||||
j=0;
|
||||
while( j < n-1){
|
||||
if (arr[j] > arr[j + 1]) {
|
||||
int temp = arr[j];
|
||||
arr[j] = arr[j + 1];
|
||||
arr[j + 1] = temp;
|
||||
}
|
||||
j=j+1;
|
||||
}
|
||||
i=i+1;
|
||||
}
|
||||
}
|
||||
|
||||
int binary_search(int arr[], int n, int target) {
|
||||
int low = 0;
|
||||
int high = n - 1;
|
||||
|
||||
while (low <= high) {
|
||||
int mid = (low + high) / 2;
|
||||
if (arr[mid] == target) {
|
||||
return mid;
|
||||
} else if (arr[mid] < target) {
|
||||
low = mid + 1;
|
||||
} else {
|
||||
high = mid - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return -1; // Target not found
|
||||
}
|
||||
|
||||
void perform_operations() {
|
||||
|
||||
int a = 10;
|
||||
int b = 5;
|
||||
|
||||
// Arithmetic operations
|
||||
int sum = a + b;
|
||||
int diff = a - b;
|
||||
int prod = a * b;
|
||||
int quot = a / b;
|
||||
int mod = a % b;
|
||||
|
||||
|
||||
putint(sum);putch(space);
|
||||
putint(diff);putch(space);
|
||||
putint(prod);putch(space);
|
||||
putint(quot);putch(space);
|
||||
putint(mod);putch(space);
|
||||
}
|
||||
|
||||
void array_init_and_process() {
|
||||
|
||||
// Initialize the array with some values
|
||||
int i=0;
|
||||
while(i<maxN){
|
||||
sorted_array[i] = i*303%maxN;
|
||||
i=i+1;
|
||||
}
|
||||
|
||||
// Perform bubble sort
|
||||
bubble_sort(sorted_array, maxN);
|
||||
|
||||
|
||||
// Search for a value
|
||||
int target = global_int;
|
||||
|
||||
int index = binary_search(sorted_array, maxN, target);
|
||||
|
||||
|
||||
putint(target);putch(space);
|
||||
putint(index);putch(space);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Perform array initialization and processing
|
||||
starttime();
|
||||
array_init_and_process();
|
||||
|
||||
perform_operations();
|
||||
stoptime();
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user