• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <benchmark/benchmark.h>
17 #include <deque>
18 
19 #include <meta/api/object.h>
20 #include <meta/base/namespace.h>
21 
22 #include "property_utils.h"
23 
24 META_BEGIN_NAMESPACE()
25 namespace benchmarks {
26 
MetadataGetPropertyByName(benchmark::State & state)27 void MetadataGetPropertyByName(benchmark::State& state)
28 {
29     auto& objr = GetObjectRegistry();
30     auto m = objr.Create<IMetadata>(ClassId::Object);
31     for (int i = 0; i != 100; ++i) {
32         auto name = "Thisispropertyname_" + std::to_string(i);
33         m->AddProperty(ConstructProperty<float>(name.c_str()));
34     }
35     for (auto _ : state) {
36         auto p = m->GetProperty("Thisispropertyname_50");
37         if (!p) {
38             state.SkipWithError("Could not find property");
39             break;
40         }
41     }
42 }
43 
ConstructEmptyMetadata(benchmark::State & state)44 void ConstructEmptyMetadata(benchmark::State& state)
45 {
46     auto& objr = GetObjectRegistry();
47     for (auto _ : state) {
48         state.PauseTiming();
49         BASE_NS::vector<IMetadata::Ptr> datas;
50         datas.reserve(100);
51         state.ResumeTiming();
52         datas.push_back(objr.Create<IMetadata>(ClassId::Object));
53     }
54 }
55 
56 BENCHMARK(MetadataGetPropertyByName);
57 BENCHMARK(ConstructEmptyMetadata);
58 
59 } // namespace benchmarks
60 META_END_NAMESPACE()
61