1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ffrt_inner.h"
17 #include "common.h"
18 
main()19 int main()
20 {
21     int64_t ffrt_time = 0;
22     uint32_t count = 10000;
23     uint32_t max_min = 2000; // us
24     uint32_t min = 0;
25     uint32_t max = max_min;
26     completely_paralle(count, max_min, ffrt_time); // pre hot ffrt
27     while ((max - min) > 1) {
28         // use binay search to get the min granularity of tasks that can obtain benefits
29         uint32_t median = (max + min) / 2;
30         completely_paralle(count, median, ffrt_time);
31         float speedup = (1.0f * count * median) / ffrt_time;
32         printf("duration:%u speedup:%.2f\n", median, speedup);
33         if (speedup > 1) {
34             max = median;
35         } else {
36             min = median;
37         }
38     }
39     return 0;
40 }
41 
42