1 /*
2 * Copyright (c) 2025 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 <chrono>
17 #include <climits>
18 #include <cstring>
19 #include <ctime>
20 #include <fstream>
21 #include <gtest/gtest.h>
22 #include <iostream>
23
24 #define private public
25
26 #include "hap_parser.h"
27 #include "hap_parser_v1.h"
28 #include "hap_parser_v2.h"
29 #include "hap_resource.h"
30 #include "hap_resource_v1.h"
31 #include "hap_resource_v2.h"
32 #include "resource_manager.h"
33 #include "resource_manager_impl.h"
34 #include "test_common.h"
35 #include "utils/errors.h"
36
37 using namespace OHOS::Global::Resource;
38 using namespace testing::ext;
39 using namespace std;
40 namespace {
41 static const char *PERFOR_FEIL_V2_PATH = "all/assets/entry/resourcesV2.index";
42 class ResourceManagerNewModulePerformanceTest : public testing::Test {
43 public:
44 static void SetUpTestCase(void);
45
46 static void TearDownTestCase(void);
47
48 void SetUp();
49
50 void TearDown();
51
ResourceManagerNewModulePerformanceTest()52 ResourceManagerNewModulePerformanceTest() : rm(nullptr)
53 {}
54
~ResourceManagerNewModulePerformanceTest()55 ~ResourceManagerNewModulePerformanceTest()
56 {}
57
58 public:
59 ResourceManager *rm;
60
61 int GetResId(std::string name, ResType resType) const;
62 };
63
GetResId(std::string name,ResType resType) const64 int ResourceManagerNewModulePerformanceTest::GetResId(std::string name, ResType resType) const
65 {
66 auto idValues = ((ResourceManagerImpl *)rm)->hapManager_->GetResourceListByName(name.c_str(), resType);
67 if (idValues.size() == 0) {
68 return -1;
69 }
70
71 for (auto &idValue : idValues) {
72 if (idValue->GetLimitPathsConst().size() > 0 && !idValue->GetLimitPathsConst()[0]->IsSystemResource()) {
73 return idValue->GetLimitPathsConst()[0]->GetIdItem()->id_;
74 }
75 }
76 return OBJ_NOT_FOUND;
77 }
78
SetUpTestCase(void)79 void ResourceManagerNewModulePerformanceTest::SetUpTestCase(void)
80 {
81 // step 1: input testsuit setup step
82 }
83
TearDownTestCase(void)84 void ResourceManagerNewModulePerformanceTest::TearDownTestCase(void)
85 {
86 // step 2: input testsuit teardown step
87 }
88
SetUp(void)89 void ResourceManagerNewModulePerformanceTest::SetUp(void)
90 {
91 // PerformanceTest need higher log level
92 g_logLevel = LOG_INFO;
93 this->rm = CreateResourceManager();
94 if (rm == nullptr) {
95 return;
96 }
97 auto rc = CreateResConfig();
98 if (rc == nullptr) {
99 return;
100 }
101 rc->SetLocaleInfo("zh", nullptr, nullptr);
102 rm->UpdateResConfig(*rc);
103 delete rc;
104 bool ret = rm->AddResource(FormatFullPath(g_newResFilePath).c_str());
105 if (!ret) {
106 RESMGR_HILOGE(RESMGR_TAG, "AddResource failed. test would fail.");
107 }
108 }
109
TearDown(void)110 void ResourceManagerNewModulePerformanceTest::TearDown(void)
111 {
112 if (this->rm != nullptr) {
113 delete this->rm;
114 this->rm = nullptr;
115 }
116 }
117
TestLoadFromNewIndex(const char * filePath)118 int TestLoadFromNewIndex(const char *filePath)
119 {
120 std::string pstr = FormatFullPath(filePath);
121 auto start = std::chrono::high_resolution_clock::now();
122 for (int k = 0; k < 1000; ++k) {
123 HapParserV2 hapParser;
124 if (!hapParser.Init(pstr.c_str())) {
125 RESMGR_HILOGE(RESMGR_TAG, "ParseResHex failed!");
126 return -1;
127 }
128
129 std::shared_ptr<HapResource> pResource = hapParser.GetHapResource(pstr.c_str(), false, false);
130 if (pResource == nullptr) {
131 RESMGR_HILOGE(RESMGR_TAG, "new HapResource failed when LoadFromIndex");
132 return -1;
133 }
134 }
135 auto end = std::chrono::high_resolution_clock::now();
136 auto readFilecost = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
137 RESMGR_HILOGD(RESMGR_TAG, "read index file cost 002: %lld us", readFilecost);
138 return OK;
139 }
140
141 /*
142 * @tc.name: ResourceManagerPerformanceFuncTest002
143 * @tc.desc: Test UpdateResConfig
144 * @tc.type: FUNC
145 */
146 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest002, TestSize.Level1)
147 {
148 long long total = 0;
149 double average = 0;
150 auto tmpRm = CreateResourceManager();
151 if (tmpRm == nullptr) {
152 ASSERT_TRUE(false);
153 }
154 ResConfig *rc = CreateResConfig();
155 if (rc == nullptr) {
156 ASSERT_TRUE(false);
157 delete tmpRm;
158 }
159 rc->SetLocaleInfo("en", nullptr, "US");
160 rc->SetDeviceType(DeviceType::DEVICE_CAR);
161 for (int k = 0; k < 1000; ++k) {
162 auto t1 = std::chrono::high_resolution_clock::now();
163 tmpRm->UpdateResConfig(*rc);
164 auto t2 = std::chrono::high_resolution_clock::now();
165 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
166 }
167 delete tmpRm;
168 delete rc;
169 average = total / 1000.0;
170 g_logLevel = LOG_DEBUG;
171 RESMGR_HILOGD(RESMGR_TAG, "avg cost 002: %f us", average);
172 EXPECT_LT(average, 2000);
173 };
174
175 /*
176 * @tc.name: ResourceManagerPerformanceFuncTest003
177 * @tc.desc: Test GetResConfig
178 * @tc.type: FUNC
179 */
180 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest003, TestSize.Level1)
181 {
182 if (rm == nullptr) {
183 ASSERT_TRUE(false);
184 }
185 unsigned long long total = 0;
186 double average = 0;
187 ResConfig *rc = CreateResConfig();
188 if (rc == nullptr) {
189 ASSERT_TRUE(false);
190 }
191 rc->SetLocaleInfo("en", nullptr, "US");
192 rc->SetDeviceType(DeviceType::DEVICE_CAR);
193 ResConfigImpl rci;
194 for (int k = 0; k < 1000; ++k) {
195 auto t1 = std::chrono::high_resolution_clock::now();
196 rm->GetResConfig(rci);
197 auto t2 = std::chrono::high_resolution_clock::now();
198 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
199 }
200 delete rc;
201 average = total / 1000.0;
202 g_logLevel = LOG_DEBUG;
203 RESMGR_HILOGD(RESMGR_TAG, "avg cost 003: %f us", average);
204 EXPECT_LT(average, 100);
205 };
206
207 /*
208 * @tc.name: ResourceManagerPerformanceFuncTest004
209 * @tc.desc: Test GetStringByID
210 * @tc.type: FUNC
211 */
212 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest004, TestSize.Level1)
213 {
214 if (rm == nullptr) {
215 ASSERT_TRUE(false);
216 }
217 unsigned long long total = 0;
218 double average = 0;
219 string name[] = {"app_name", "title"};
220 vector<uint32_t> ids;
221 int count = 2;
222 for (int i = 0; i < count; ++i) {
223 int id = GetResId(name[i], ResType::STRING);
224 ASSERT_TRUE(id > 0);
225 ids.push_back(static_cast<uint32_t>(id));
226 }
227
228 std::string outValue;
229 for (int k = 0; k < 1000; ++k) {
230 for (int i = 0; i < count; ++i) {
231 auto t1 = std::chrono::high_resolution_clock::now();
232 rm->GetStringById(ids[i], outValue);
233 auto t2 = std::chrono::high_resolution_clock::now();
234 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
235 }
236 }
237 average = total / (1000.0 * count);
238 g_logLevel = LOG_DEBUG;
239 RESMGR_HILOGD(RESMGR_TAG, "avg cost 004: %f us", average);
240 EXPECT_LT(average, 100);
241 };
242
243 /*
244 * @tc.name: ResourceManagerPerformanceFuncTest005
245 * @tc.desc: Test GetStringByName
246 * @tc.type: FUNC
247 */
248 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest005, TestSize.Level1)
249 {
250 if (rm == nullptr) {
251 ASSERT_TRUE(false);
252 }
253 unsigned long long total = 0;
254 double average = 0;
255 string name[] = {"app_name", "title"};
256 int count = 2;
257 std::string outValue;
258 for (int k = 0; k < 1000; ++k) {
259 for (int i = 0; i < count; ++i) {
260 auto t1 = std::chrono::high_resolution_clock::now();
261 rm->GetStringByName(name[i].c_str(), outValue);
262 auto t2 = std::chrono::high_resolution_clock::now();
263 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
264 }
265 }
266 average = total / (1000.0 * count);
267 g_logLevel = LOG_DEBUG;
268 RESMGR_HILOGD(RESMGR_TAG, "avg cost 005: %f us", average);
269 EXPECT_LT(average, 100);
270 };
271
272 /*
273 * @tc.name: ResourceManagerPerformanceFuncTest006
274 * @tc.desc: Test GetStringByName
275 * @tc.type: FUNC
276 */
277 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest006, TestSize.Level1)
278 {
279 if (rm == nullptr) {
280 ASSERT_TRUE(false);
281 }
282 unsigned long long total = 0;
283 double average = 0;
284 string name[] = {"string_ref", "string_ref2"};
285 int count = 2;
286 std::string outValue;
287 for (int k = 0; k < 1000; ++k) {
288 for (int i = 0; i < count; ++i) {
289 auto t1 = std::chrono::high_resolution_clock::now();
290 rm->GetStringByName(name[i].c_str(), outValue);
291 auto t2 = std::chrono::high_resolution_clock::now();
292 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
293 }
294 }
295 average = total / (1000.0 * count);
296 g_logLevel = LOG_DEBUG;
297 RESMGR_HILOGD(RESMGR_TAG, "avg cost 006: %f us", average);
298 EXPECT_LT(average, 100);
299 };
300
301 /*
302 * @tc.name: ResourceManagerPerformanceFuncTest007
303 * @tc.desc: Test GetStringFormatById
304 * @tc.type: FUNC
305 */
306 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest007, TestSize.Level1)
307 {
308 if (rm == nullptr) {
309 ASSERT_TRUE(false);
310 }
311 unsigned long long total = 0;
312 double average = 0;
313 string name[] = {"app_name", "title"};
314 vector<uint32_t> ids;
315 int count = 2;
316 for (int i = 0; i < count; ++i) {
317 int id = GetResId(name[i], ResType::STRING);
318 ASSERT_TRUE(id > 0);
319 ids.push_back(static_cast<uint32_t>(id));
320 }
321
322 std::string outValue;
323 for (int k = 0; k < 1000; ++k) {
324 for (int i = 0; i < count; ++i) {
325 auto t1 = std::chrono::high_resolution_clock::now();
326 rm->GetStringFormatById(outValue, ids[i], 12);
327 auto t2 = std::chrono::high_resolution_clock::now();
328 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
329 }
330 }
331 average = total / (1000.0 * count);
332 g_logLevel = LOG_DEBUG;
333 RESMGR_HILOGD(RESMGR_TAG, "avg cost 007: %f us", average);
334 EXPECT_LT(average, 100);
335 };
336
337 /*
338 * @tc.name: ResourceManagerPerformanceFuncTest008
339 * @tc.desc: Test GetStringFormatByName
340 * @tc.type: FUNC
341 */
342 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest008, TestSize.Level1)
343 {
344 if (rm == nullptr) {
345 ASSERT_TRUE(false);
346 }
347 unsigned long long total = 0;
348 double average = 0;
349 string name[] = {"app_name", "title"};
350 int count = 2;
351 std::string outValue;
352 for (int k = 0; k < 1000; ++k) {
353 for (int i = 0; i < count; ++i) {
354 auto t1 = std::chrono::high_resolution_clock::now();
355 rm->GetStringFormatByName(outValue, name[i].c_str(), 123);
356 auto t2 = std::chrono::high_resolution_clock::now();
357 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
358 }
359 }
360 average = total / (1000.0 * count);
361 g_logLevel = LOG_DEBUG;
362 RESMGR_HILOGD(RESMGR_TAG, "avg cost 008: %f us", average);
363 EXPECT_LT(average, 100);
364 };
365
366 /*
367 * @tc.name: ResourceManagerPerformanceFuncTest009
368 * @tc.desc: Test GetStringArrayById
369 * @tc.type: FUNC
370 */
371 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest009, TestSize.Level1)
372 {
373 if (rm == nullptr) {
374 ASSERT_TRUE(false);
375 }
376 unsigned long long total = 0;
377 double average = 0;
378 int id = GetResId("size", ResType::STRINGARRAY);
379 ASSERT_TRUE(id > 0);
380
381 std::vector<std::string> outValue;
382 for (int k = 0; k < 1000; ++k) {
383 auto t1 = std::chrono::high_resolution_clock::now();
384 rm->GetStringArrayById(id, outValue);
385 auto t2 = std::chrono::high_resolution_clock::now();
386 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
387 }
388 average = total / 1000.0;
389 g_logLevel = LOG_DEBUG;
390 RESMGR_HILOGD(RESMGR_TAG, "avg cost 009: %f us", average);
391 EXPECT_LT(average, 100);
392 };
393
394 /*
395 * @tc.name: ResourceManagerPerformanceFuncTest010
396 * @tc.desc: Test GetStringArrayByName
397 * @tc.type: FUNC
398 */
399 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest010, TestSize.Level1)
400 {
401 if (rm == nullptr) {
402 ASSERT_TRUE(false);
403 }
404 unsigned long long total = 0;
405 double average = 0;
406 std::vector<std::string> outValue;
407 for (int k = 0; k < 1000; ++k) {
408 auto t1 = std::chrono::high_resolution_clock::now();
409 rm->GetStringArrayByName("size", outValue);
410 auto t2 = std::chrono::high_resolution_clock::now();
411 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
412 }
413 average = total / 1000.0;
414 g_logLevel = LOG_DEBUG;
415 RESMGR_HILOGD(RESMGR_TAG, "avg cost 010: %f us", average);
416 EXPECT_LT(average, 100);
417 };
418
419 /*
420 * @tc.name: ResourceManagerPerformanceFuncTest011
421 * @tc.desc: Test GetPatternById
422 * @tc.type: FUNC
423 */
424 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest011, TestSize.Level1)
425 {
426 if (rm == nullptr) {
427 ASSERT_TRUE(false);
428 }
429 unsigned long long total = 0;
430 double average = 0;
431 string name[] = {"base", "child"};
432 vector<uint32_t> ids;
433 int count = 2;
434 for (int i = 0; i < count; ++i) {
435 int id = GetResId(name[i], ResType::PATTERN);
436 ASSERT_TRUE(id > 0);
437 ids.push_back(static_cast<uint32_t>(id));
438 }
439 std::map<std::string, std::string> outValue;
440 for (int k = 0; k < 1000; ++k) {
441 for (int i = 0; i < count; ++i) {
442 auto t1 = std::chrono::high_resolution_clock::now();
443 rm->GetPatternById(ids[i], outValue);
444 auto t2 = std::chrono::high_resolution_clock::now();
445 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
446 }
447 }
448 average = total / (1000.0 * count);
449 g_logLevel = LOG_DEBUG;
450 RESMGR_HILOGD(RESMGR_TAG, "avg cost 011: %f us", average);
451 EXPECT_LT(average, 100);
452 };
453
454 /*
455 * @tc.name: ResourceManagerPerformanceFuncTest012
456 * @tc.desc: Test GetPatternByName
457 * @tc.type: FUNC
458 */
459 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest012, TestSize.Level1)
460 {
461 if (rm == nullptr) {
462 ASSERT_TRUE(false);
463 }
464 unsigned long long total = 0;
465 double average = 0;
466 string name[] = {"base", "child"};
467 int count = 2;
468 std::map<std::string, std::string> outValue;
469 for (int k = 0; k < 1000; ++k) {
470 for (int i = 0; i < count; ++i) {
471 auto t1 = std::chrono::high_resolution_clock::now();
472 rm->GetPatternByName(name[i].c_str(), outValue);
473 auto t2 = std::chrono::high_resolution_clock::now();
474 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
475 }
476 }
477 average = total / (1000.0 * count);
478 g_logLevel = LOG_DEBUG;
479 RESMGR_HILOGD(RESMGR_TAG, "avg cost 012: %f us", average);
480 EXPECT_LT(average, 100);
481 };
482
483 /*
484 * @tc.name: ResourceManagerPerformanceFuncTest013
485 * @tc.desc: Test GetPluralStringById
486 * @tc.type: FUNC
487 */
488 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest013, TestSize.Level1)
489 {
490 if (rm == nullptr) {
491 ASSERT_TRUE(false);
492 }
493 unsigned long long total = 0;
494 double average = 0;
495 int quantity[] = {1, 100};
496 int count = 2;
497 int id = GetResId("eat_apple", ResType::PLURALS);
498 ASSERT_TRUE(id > 0);
499
500 string outValue;
501 for (int k = 0; k < 1000; ++k) {
502 for (int i = 0; i < count; ++i) {
503 auto t1 = std::chrono::high_resolution_clock::now();
504 rm->GetPluralStringById(id, quantity[i], outValue);
505 auto t2 = std::chrono::high_resolution_clock::now();
506 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
507 }
508 }
509 average = total / (1000.0 * count);
510 g_logLevel = LOG_DEBUG;
511 RESMGR_HILOGD(RESMGR_TAG, "avg cost 013: %f us", average);
512 EXPECT_LT(average, 100);
513 };
514
515 /*
516 * @tc.name: ResourceManagerPerformanceFuncTest014
517 * @tc.desc: Test GetPluralStringByName
518 * @tc.type: FUNC
519 */
520 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest014, TestSize.Level1)
521 {
522 if (rm == nullptr) {
523 ASSERT_TRUE(false);
524 }
525 unsigned long long total = 0;
526 double average = 0;
527 int quantity[] = {1, 100};
528 int count = 2;
529 string outValue;
530 for (int k = 0; k < 1000; ++k) {
531 for (int i = 0; i < count; ++i) {
532 auto t1 = std::chrono::high_resolution_clock::now();
533 rm->GetPluralStringByName("eat_apple", quantity[i], outValue);
534 auto t2 = std::chrono::high_resolution_clock::now();
535 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
536 }
537 }
538 average = total / (1000.0 * count);
539 g_logLevel = LOG_DEBUG;
540 RESMGR_HILOGD(RESMGR_TAG, "avg cost 014: %f us", average);
541 EXPECT_LT(average, 100);
542 };
543
544 /*
545 * @tc.name: ResourceManagerPerformanceFuncTest015
546 * @tc.desc: Test GetPluralStringByIdFormat
547 * @tc.type: FUNC
548 */
549 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest015, TestSize.Level1)
550 {
551 if (rm == nullptr) {
552 ASSERT_TRUE(false);
553 }
554 unsigned long long total = 0;
555 double average = 0;
556 int quantity[] = {1, 100};
557 int count = 2;
558 int id = GetResId("eat_apple", ResType::PLURALS);
559 ASSERT_TRUE(id > 0);
560
561 string outValue;
562 for (int k = 0; k < 1000; ++k) {
563 for (int i = 0; i < count; ++i) {
564 auto t1 = std::chrono::high_resolution_clock::now();
565 rm->GetPluralStringByIdFormat(outValue, id, quantity[i], quantity[i]);
566 auto t2 = std::chrono::high_resolution_clock::now();
567 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
568 }
569 }
570 average = total / (1000.0 * count);
571 g_logLevel = LOG_DEBUG;
572 RESMGR_HILOGD(RESMGR_TAG, "avg cost 015: %f us", average);
573 EXPECT_LT(average, 100);
574 };
575
576 /*
577 * @tc.name: ResourceManagerPerformanceFuncTest016
578 * @tc.desc: Test GetPluralStringByNameFormat
579 * @tc.type: FUNC
580 */
581 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest016, TestSize.Level1)
582 {
583 if (rm == nullptr) {
584 ASSERT_TRUE(false);
585 }
586 unsigned long long total = 0;
587 double average = 0;
588 int quantity[] = {1, 100};
589 int count = 2;
590 string outValue;
591 for (int k = 0; k < 1000; ++k) {
592 for (int i = 0; i < count; ++i) {
593 auto t1 = std::chrono::high_resolution_clock::now();
594 rm->GetPluralStringByNameFormat(outValue, "eat_apple", quantity[i], quantity[i]);
595 auto t2 = std::chrono::high_resolution_clock::now();
596 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
597 }
598 }
599 average = total / (1000.0 * count);
600 g_logLevel = LOG_DEBUG;
601 RESMGR_HILOGD(RESMGR_TAG, "avg cost 016: %f us", average);
602 EXPECT_LT(average, 100);
603 };
604
605 /*
606 * @tc.name: ResourceManagerPerformanceFuncTest017
607 * @tc.desc: Test GetThemeById
608 * @tc.type: FUNC
609 */
610 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest017, TestSize.Level1)
611 {
612 if (rm == nullptr) {
613 ASSERT_TRUE(false);
614 }
615 unsigned long long total = 0;
616 double average = 0;
617 int id = GetResId("app_theme", ResType::THEME);
618 ASSERT_TRUE(id > 0);
619
620 std::map<std::string, std::string> outValue;
621 for (int k = 0; k < 1000; ++k) {
622 auto t1 = std::chrono::high_resolution_clock::now();
623 rm->GetThemeById(id, outValue);
624 auto t2 = std::chrono::high_resolution_clock::now();
625 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
626 }
627 average = total / 1000.0;
628 g_logLevel = LOG_DEBUG;
629 RESMGR_HILOGD(RESMGR_TAG, "avg cost 017: %f us", average);
630 EXPECT_LT(average, 100);
631 };
632
633 /*
634 * @tc.name: ResourceManagerPerformanceFuncTest018
635 * @tc.desc: Test GetThemeByName
636 * @tc.type: FUNC
637 */
638 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest018, TestSize.Level1)
639 {
640 if (rm == nullptr) {
641 ASSERT_TRUE(false);
642 }
643 unsigned long long total = 0;
644 double average = 0;
645 std::map<std::string, std::string> outValue;
646 for (int k = 0; k < 1000; ++k) {
647 auto t1 = std::chrono::high_resolution_clock::now();
648 rm->GetThemeByName("app_theme", outValue);
649 auto t2 = std::chrono::high_resolution_clock::now();
650 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
651 }
652 average = total / 1000.0;
653 g_logLevel = LOG_DEBUG;
654 RESMGR_HILOGD(RESMGR_TAG, "avg cost 018: %f us", average);
655 EXPECT_LT(average, 100);
656 };
657
658 /*
659 * @tc.name: ResourceManagerPerformanceFuncTest019
660 * @tc.desc: Test GetBooleanById
661 * @tc.type: FUNC
662 */
663 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest019, TestSize.Level1)
664 {
665 if (rm == nullptr) {
666 ASSERT_TRUE(false);
667 }
668 unsigned long long total = 0;
669 double average = 0;
670 int id = GetResId("boolean_1", ResType::BOOLEAN);
671 ASSERT_TRUE(id > 0);
672
673 bool outValue = true;
674 for (int k = 0; k < 1000; ++k) {
675 auto t1 = std::chrono::high_resolution_clock::now();
676 rm->GetBooleanById(id, outValue);
677 auto t2 = std::chrono::high_resolution_clock::now();
678 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
679 }
680 average = total / 1000.0;
681 g_logLevel = LOG_DEBUG;
682 RESMGR_HILOGD(RESMGR_TAG, "avg cost 019: %f us", average);
683 EXPECT_LT(average, 100);
684 };
685
686 /*
687 * @tc.name: ResourceManagerPerformanceFuncTest020
688 * @tc.desc: Test GetBooleanByName
689 * @tc.type: FUNC
690 */
691 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest020, TestSize.Level1)
692 {
693 if (rm == nullptr) {
694 ASSERT_TRUE(false);
695 }
696 unsigned long long total = 0;
697 double average = 0;
698 bool outValue = true;
699 for (int k = 0; k < 1000; ++k) {
700 auto t1 = std::chrono::high_resolution_clock::now();
701 rm->GetBooleanByName("boolean_1", outValue);
702 auto t2 = std::chrono::high_resolution_clock::now();
703 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
704 }
705 average = total / 1000.0;
706 g_logLevel = LOG_DEBUG;
707 RESMGR_HILOGD(RESMGR_TAG, "avg cost 020: %f us", average);
708 EXPECT_LT(average, 100);
709 };
710
711 /*
712 * @tc.name: ResourceManagerPerformanceFuncTest021
713 * @tc.desc: Test GetIntegerById
714 * @tc.type: FUNC
715 */
716 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest021, TestSize.Level1)
717 {
718 if (rm == nullptr) {
719 ASSERT_TRUE(false);
720 }
721 unsigned long long total = 0;
722 double average = 0;
723 int id = GetResId("integer_1", ResType::INTEGER);
724 ASSERT_TRUE(id > 0);
725
726 int outValue = 0;
727 for (int k = 0; k < 1000; ++k) {
728 auto t1 = std::chrono::high_resolution_clock::now();
729 rm->GetIntegerById(id, outValue);
730 auto t2 = std::chrono::high_resolution_clock::now();
731 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
732 }
733 average = total / 1000.0;
734 g_logLevel = LOG_DEBUG;
735 RESMGR_HILOGD(RESMGR_TAG, "avg cost 021: %f us", average);
736 EXPECT_LT(average, 100);
737 };
738
739 /*
740 * @tc.name: ResourceManagerPerformanceFuncTest022
741 * @tc.desc: Test GetIntegerByName
742 * @tc.type: FUNC
743 */
744 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest022, TestSize.Level1)
745 {
746 if (rm == nullptr) {
747 ASSERT_TRUE(false);
748 }
749 unsigned long long total = 0;
750 double average = 0;
751 int outValue = 0;
752 for (int k = 0; k < 1000; ++k) {
753 auto t1 = std::chrono::high_resolution_clock::now();
754 rm->GetIntegerByName("integer_ref", outValue);
755 auto t2 = std::chrono::high_resolution_clock::now();
756 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
757 }
758 average = total / 1000.0;
759 g_logLevel = LOG_DEBUG;
760 RESMGR_HILOGD(RESMGR_TAG, "avg cost 022: %f us", average);
761 EXPECT_LT(average, 100);
762 };
763
764 /*
765 * @tc.name: ResourceManagerPerformanceFuncTest023
766 * @tc.desc: Test GetFloatById
767 * @tc.type: FUNC
768 */
769 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest023, TestSize.Level1)
770 {
771 if (rm == nullptr) {
772 ASSERT_TRUE(false);
773 }
774 unsigned long long total = 0;
775 double average = 0;
776 int id = GetResId("width_appBar_backButton_touchTarget", ResType::FLOAT);
777 ASSERT_TRUE(id > 0);
778
779 float outValue = 0.0;
780 for (int k = 0; k < 1000; ++k) {
781 auto t1 = std::chrono::high_resolution_clock::now();
782 rm->GetFloatById(id, outValue);
783 auto t2 = std::chrono::high_resolution_clock::now();
784 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
785 }
786 average = total / 1000.0;
787 g_logLevel = LOG_DEBUG;
788 RESMGR_HILOGD(RESMGR_TAG, "avg cost 023: %f us", average);
789 EXPECT_LT(average, 220);
790 };
791
792 /*
793 * @tc.name: ResourceManagerPerformanceFuncTest024
794 * @tc.desc: Test GetFloatByName
795 * @tc.type: FUNC
796 */
797 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest024, TestSize.Level1)
798 {
799 if (rm == nullptr) {
800 ASSERT_TRUE(false);
801 }
802 unsigned long long total = 0;
803 double average = 0;
804 float outValue = 0;
805 for (int k = 0; k < 1000; ++k) {
806 auto t1 = std::chrono::high_resolution_clock::now();
807 rm->GetFloatByName("width_appBar_backButton_touchTarget", outValue);
808 auto t2 = std::chrono::high_resolution_clock::now();
809 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
810 }
811 average = total / 1000.0;
812 g_logLevel = LOG_DEBUG;
813 RESMGR_HILOGD(RESMGR_TAG, "avg cost 024: %f us", average);
814 EXPECT_LT(average, 160);
815 };
816
817 /*
818 * @tc.name: ResourceManagerPerformanceFuncTest025
819 * @tc.desc: Test GetIntArrayById
820 * @tc.type: FUNC
821 */
822 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest025, TestSize.Level1)
823 {
824 if (rm == nullptr) {
825 ASSERT_TRUE(false);
826 }
827 unsigned long long total = 0;
828 double average = 0;
829 int id = GetResId("intarray_1", ResType::INTARRAY);
830 ASSERT_TRUE(id > 0);
831
832 std::vector<int> outValue;
833 for (int k = 0; k < 1000; ++k) {
834 auto t1 = std::chrono::high_resolution_clock::now();
835 rm->GetIntArrayById(id, outValue);
836 auto t2 = std::chrono::high_resolution_clock::now();
837 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
838 }
839 average = total / 1000.0;
840 g_logLevel = LOG_DEBUG;
841 RESMGR_HILOGD(RESMGR_TAG, "avg cost 025: %f us", average);
842 EXPECT_LT(average, 100);
843 };
844
845 /*
846 * @tc.name: ResourceManagerPerformanceFuncTest026
847 * @tc.desc: Test GetIntArrayByName
848 * @tc.type: FUNC
849 */
850 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest026, TestSize.Level1)
851 {
852 if (rm == nullptr) {
853 ASSERT_TRUE(false);
854 }
855 unsigned long long total = 0;
856 double average = 0;
857 std::vector<int> outValue;
858 for (int k = 0; k < 1000; ++k) {
859 auto t1 = std::chrono::high_resolution_clock::now();
860 rm->GetIntArrayByName("intarray_1", outValue);
861 auto t2 = std::chrono::high_resolution_clock::now();
862 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
863 }
864 average = total / 1000.0;
865 g_logLevel = LOG_DEBUG;
866 RESMGR_HILOGD(RESMGR_TAG, "avg cost 026: %f us", average);
867 EXPECT_LT(average, 100);
868 };
869
870 /*
871 * @tc.name: ResourceManagerPerformanceFuncTest027
872 * @tc.desc: Test GetColorById
873 * @tc.type: FUNC
874 */
875 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest027, TestSize.Level1)
876 {
877 if (rm == nullptr) {
878 ASSERT_TRUE(false);
879 }
880 unsigned long long total = 0;
881 double average = 0;
882 int id = GetResId("divider_color", ResType::COLOR);
883 ASSERT_TRUE(id > 0);
884
885 uint32_t outValue;
886 for (int k = 0; k < 1000; ++k) {
887 auto t1 = std::chrono::high_resolution_clock::now();
888 rm->GetColorById(id, outValue);
889 auto t2 = std::chrono::high_resolution_clock::now();
890 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
891 }
892 average = total / 1000.0;
893 g_logLevel = LOG_DEBUG;
894 RESMGR_HILOGD(RESMGR_TAG, "avg cost 027: %f us", average);
895 EXPECT_LT(average, 100);
896 };
897
898 /*
899 * @tc.name: ResourceManagerPerformanceFuncTest028
900 * @tc.desc: Test GetColorByName
901 * @tc.type: FUNC
902 */
903 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest028, TestSize.Level1)
904 {
905 if (rm == nullptr) {
906 ASSERT_TRUE(false);
907 }
908 unsigned long long total = 0;
909 double average = 0;
910 uint32_t outValue;
911 for (int k = 0; k < 1000; ++k) {
912 auto t1 = std::chrono::high_resolution_clock::now();
913 rm->GetColorByName("divider_color", outValue);
914 auto t2 = std::chrono::high_resolution_clock::now();
915 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
916 }
917 average = total / 1000.0;
918 g_logLevel = LOG_DEBUG;
919 RESMGR_HILOGD(RESMGR_TAG, "avg cost 028: %f us", average);
920 EXPECT_LT(average, 100);
921 };
922
923 /*
924 * @tc.name: ResourceManagerPerformanceFuncTest029
925 * @tc.desc: Test GetProfileById
926 * @tc.type: FUNC
927 */
928 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest029, TestSize.Level1)
929 {
930 if (rm == nullptr) {
931 ASSERT_TRUE(false);
932 }
933 unsigned long long total = 0;
934 double average = 0;
935 int id = GetResId("test_profile", ResType::PROF);
936 ASSERT_TRUE(id > 0);
937
938 string outValue;
939 for (int k = 0; k < 1000; ++k) {
940 auto t1 = std::chrono::high_resolution_clock::now();
941 rm->GetProfileById(id, outValue);
942 auto t2 = std::chrono::high_resolution_clock::now();
943 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
944 }
945 average = total / 1000.0;
946 g_logLevel = LOG_DEBUG;
947 RESMGR_HILOGD(RESMGR_TAG, "avg cost 029: %f us", average);
948 EXPECT_LT(average, 100);
949 };
950
951 /*
952 * @tc.name: ResourceManagerPerformanceFuncTest030
953 * @tc.desc: Test GetProfileByName
954 * @tc.type: FUNC
955 */
956 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest030, TestSize.Level1)
957 {
958 if (rm == nullptr) {
959 ASSERT_TRUE(false);
960 }
961 unsigned long long total = 0;
962 double average = 0;
963 string outValue;
964 for (int k = 0; k < 1000; ++k) {
965 auto t1 = std::chrono::high_resolution_clock::now();
966 rm->GetProfileByName("test_common", outValue);
967 auto t2 = std::chrono::high_resolution_clock::now();
968 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
969 }
970 average = total / 1000.0;
971 g_logLevel = LOG_DEBUG;
972 RESMGR_HILOGD(RESMGR_TAG, "avg cost 030: %f us", average);
973 EXPECT_LT(average, 100);
974 };
975
976 /*
977 * @tc.name: ResourceManagerPerformanceFuncTest031
978 * @tc.desc: Test GetMediaById
979 * @tc.type: FUNC
980 */
981 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest031, TestSize.Level1)
982 {
983 if (rm == nullptr) {
984 ASSERT_TRUE(false);
985 }
986 unsigned long long total = 0;
987 double average = 0;
988 int id = GetResId("icon", ResType::MEDIA);
989 ASSERT_TRUE(id > 0);
990
991 string outValue;
992 for (int k = 0; k < 1000; ++k) {
993 auto t1 = std::chrono::high_resolution_clock::now();
994 rm->GetMediaById(id, outValue);
995 auto t2 = std::chrono::high_resolution_clock::now();
996 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
997 }
998 average = total / 1000.0;
999 g_logLevel = LOG_DEBUG;
1000 RESMGR_HILOGD(RESMGR_TAG, "avg cost 031: %f us", average);
1001 EXPECT_LT(average, 100);
1002 };
1003
1004 /*
1005 * @tc.name: ResourceManagerPerformanceFuncTest032
1006 * @tc.desc: Test GetMediaByName
1007 * @tc.type: FUNC
1008 */
1009 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest032, TestSize.Level1)
1010 {
1011 if (rm == nullptr) {
1012 ASSERT_TRUE(false);
1013 }
1014 unsigned long long total = 0;
1015 double average = 0;
1016 string outValue;
1017 for (int k = 0; k < 1000; ++k) {
1018 auto t1 = std::chrono::high_resolution_clock::now();
1019 rm->GetMediaByName("icon", outValue);
1020 auto t2 = std::chrono::high_resolution_clock::now();
1021 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1022 }
1023 average = total / 1000.0;
1024 g_logLevel = LOG_DEBUG;
1025 RESMGR_HILOGD(RESMGR_TAG, "avg cost 032: %f us", average);
1026 EXPECT_LT(average, 100);
1027 };
1028
1029 /*
1030 * @tc.name: ResourceManagerPerformanceFuncTest033
1031 * @tc.desc: Test GetResConfigById
1032 * @tc.type: FUNC
1033 */
1034 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest033, TestSize.Level1)
1035 {
1036 if (rm == nullptr) {
1037 ASSERT_TRUE(false);
1038 }
1039 unsigned long long total = 0;
1040 double average = 0;
1041 int id = GetResId("app_name", ResType::STRING);
1042 ASSERT_TRUE(id > 0);
1043 ResConfigImpl rci;
1044 for (int k = 0; k < 1000; ++k) {
1045 auto t1 = std::chrono::high_resolution_clock::now();
1046 rm->GetResConfigById(id, rci);
1047 auto t2 = std::chrono::high_resolution_clock::now();
1048 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1049 }
1050 average = total / 1000.0;
1051 g_logLevel = LOG_DEBUG;
1052 RESMGR_HILOGD(RESMGR_TAG, "avg cost 033: %f us", average);
1053 EXPECT_LT(average, 100);
1054 };
1055
1056 /*
1057 * @tc.name: ResourceManagerPerformanceFuncTest034
1058 * @tc.desc: Test GetResConfigByName
1059 * @tc.type: FUNC
1060 */
1061 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest034, TestSize.Level1)
1062 {
1063 if (rm == nullptr) {
1064 ASSERT_TRUE(false);
1065 }
1066 unsigned long long total = 0;
1067 double average = 0;
1068 ResConfigImpl rci;
1069 for (int k = 0; k < 1000; ++k) {
1070 auto t1 = std::chrono::high_resolution_clock::now();
1071 rm->GetResConfigByName("app_name", ResType::STRING, rci);
1072 auto t2 = std::chrono::high_resolution_clock::now();
1073 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1074 }
1075 average = total / 1000.0;
1076 g_logLevel = LOG_DEBUG;
1077 RESMGR_HILOGD(RESMGR_TAG, "avg cost 034: %f us", average);
1078 EXPECT_LT(average, 100);
1079 };
1080
1081 /*
1082 * @tc.name: ResourceManagerPerformanceFuncTest037
1083 * @tc.desc: Test GetMediaDataById
1084 * @tc.type: FUNC
1085 */
1086 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest037, TestSize.Level1)
1087 {
1088 if (rm == nullptr) {
1089 ASSERT_TRUE(false);
1090 }
1091 unsigned long long total = 0;
1092 double average = 0;
1093 int id = GetResId("icon", ResType::MEDIA);
1094 ASSERT_TRUE(id > 0);
1095 size_t len;
1096 std::unique_ptr<uint8_t[]> outValue;
1097 for (int k = 0; k < 1000; ++k) {
1098 auto t1 = std::chrono::high_resolution_clock::now();
1099 rm->GetMediaDataById(id, len, outValue);
1100 auto t2 = std::chrono::high_resolution_clock::now();
1101 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1102 }
1103 average = total / 1000.0;
1104 g_logLevel = LOG_DEBUG;
1105 RESMGR_HILOGD(RESMGR_TAG, "avg cost 037: %f us", average);
1106 EXPECT_LT(average, 100);
1107 };
1108
1109 /*
1110 * @tc.name: ResourceManagerPerformanceFuncTest038
1111 * @tc.desc: Test GetMediaDataByName
1112 * @tc.type: FUNC
1113 */
1114 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest038, TestSize.Level1)
1115 {
1116 if (rm == nullptr) {
1117 ASSERT_TRUE(false);
1118 }
1119 unsigned long long total = 0;
1120 double average = 0;
1121 size_t len;
1122 std::unique_ptr<uint8_t[]> outValue;
1123 for (int k = 0; k < 1000; ++k) {
1124 auto t1 = std::chrono::high_resolution_clock::now();
1125 rm->GetMediaDataByName("icon", len, outValue);
1126 auto t2 = std::chrono::high_resolution_clock::now();
1127 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1128 }
1129 average = total / 1000.0;
1130 g_logLevel = LOG_DEBUG;
1131 RESMGR_HILOGD(RESMGR_TAG, "avg cost 038: %f us", average);
1132 EXPECT_LT(average, 100);
1133 };
1134
1135 /*
1136 * @tc.name: ResourceManagerPerformanceFuncTest039
1137 * @tc.desc: Test GetMediaBase64DataById
1138 * @tc.type: FUNC
1139 */
1140 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest039, TestSize.Level1)
1141 {
1142 if (rm == nullptr) {
1143 ASSERT_TRUE(false);
1144 }
1145 unsigned long long total = 0;
1146 double average = 0;
1147 int id = GetResId("icon", ResType::MEDIA);
1148 ASSERT_TRUE(id > 0);
1149 std::string outValue;
1150 for (int k = 0; k < 1000; ++k) {
1151 auto t1 = std::chrono::high_resolution_clock::now();
1152 rm->GetMediaBase64DataById(id, outValue);
1153 auto t2 = std::chrono::high_resolution_clock::now();
1154 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1155 }
1156 average = total / 1000.0;
1157 g_logLevel = LOG_DEBUG;
1158 RESMGR_HILOGD(RESMGR_TAG, "avg cost 039: %f us", average);
1159 EXPECT_LT(average, 100);
1160 };
1161
1162 /*
1163 * @tc.name: ResourceManagerPerformanceFuncTest040
1164 * @tc.desc: Test GetMediaBase64DataByName
1165 * @tc.type: FUNC
1166 */
1167 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest040, TestSize.Level1)
1168 {
1169 if (rm == nullptr) {
1170 ASSERT_TRUE(false);
1171 }
1172 unsigned long long total = 0;
1173 double average = 0;
1174 std::string outValue;
1175 for (int k = 0; k < 1000; ++k) {
1176 auto t1 = std::chrono::high_resolution_clock::now();
1177 rm->GetMediaBase64DataByName("icon", outValue);
1178 auto t2 = std::chrono::high_resolution_clock::now();
1179 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1180 }
1181 average = total / 1000.0;
1182 g_logLevel = LOG_DEBUG;
1183 RESMGR_HILOGD(RESMGR_TAG, "avg cost 040: %f us", average);
1184 EXPECT_LT(average, 100);
1185 };
1186
1187 /*
1188 * @tc.name: ResourceManagerPerformanceFuncTest041
1189 * @tc.desc: Test GetProfileDataById
1190 * @tc.type: FUNC
1191 */
1192 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest041, TestSize.Level1)
1193 {
1194 if (rm == nullptr) {
1195 ASSERT_TRUE(false);
1196 }
1197 unsigned long long total = 0;
1198 double average = 0;
1199 int id = GetResId("test_profile", ResType::PROF);
1200 EXPECT_TRUE(id > 0);
1201 size_t len;
1202 std::unique_ptr<uint8_t[]> outValue;
1203 for (int k = 0; k < 1000; ++k) {
1204 auto t1 = std::chrono::high_resolution_clock::now();
1205 rm->GetProfileDataById(id, len, outValue);
1206 auto t2 = std::chrono::high_resolution_clock::now();
1207 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1208 }
1209 average = total / 1000.0;
1210 g_logLevel = LOG_DEBUG;
1211 RESMGR_HILOGD(RESMGR_TAG, "avg cost 041: %f us", average);
1212 EXPECT_LT(average, 260);
1213 };
1214
1215 /*
1216 * @tc.name: ResourceManagerPerformanceFuncTest042
1217 * @tc.desc: Test GetProfileDataByName
1218 * @tc.type: FUNC
1219 */
1220 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest042, TestSize.Level1)
1221 {
1222 if (rm == nullptr) {
1223 ASSERT_TRUE(false);
1224 }
1225 unsigned long long total = 0;
1226 double average = 0;
1227 size_t len;
1228 std::unique_ptr<uint8_t[]> outValue;
1229 for (int k = 0; k < 1000; ++k) {
1230 auto t1 = std::chrono::high_resolution_clock::now();
1231 rm->GetProfileDataByName("test_profile", len, outValue);
1232 auto t2 = std::chrono::high_resolution_clock::now();
1233 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1234 }
1235 average = total / 1000.0;
1236 g_logLevel = LOG_DEBUG;
1237 RESMGR_HILOGD(RESMGR_TAG, "avg cost 042: %f us", average);
1238 EXPECT_LT(average, 260);
1239 };
1240
1241 /*
1242 * @tc.name: ResourceManagerPerformanceFuncTest045
1243 * @tc.desc: Test IsLoadHap
1244 * @tc.type: FUNC
1245 */
1246 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest045, TestSize.Level1)
1247 {
1248 if (rm == nullptr) {
1249 ASSERT_TRUE(false);
1250 }
1251 bool ret = rm->AddResource(FormatFullPath(g_newModuleHapPath).c_str());
1252 EXPECT_TRUE(ret);
1253 unsigned long long total = 0;
1254 double average = 0;
1255 std::string hapPath(FormatFullPath(g_newModuleHapPath));
1256 for (int k = 0; k < 1000; ++k) {
1257 auto t1 = std::chrono::high_resolution_clock::now();
1258 rm->IsLoadHap(hapPath);
1259 auto t2 = std::chrono::high_resolution_clock::now();
1260 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1261 }
1262 average = total / 1000.0;
1263 g_logLevel = LOG_DEBUG;
1264 RESMGR_HILOGD(RESMGR_TAG, "avg cost 045: %f us", average);
1265 EXPECT_LT(average, 100);
1266 };
1267
1268 /*
1269 * @tc.name: ResourceManagerPerformanceFuncTest047
1270 * @tc.desc: Test GetDrawableInfoById
1271 * @tc.type: FUNC
1272 */
1273 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest047, TestSize.Level1)
1274 {
1275 if (rm == nullptr) {
1276 ASSERT_TRUE(false);
1277 }
1278 unsigned long long total = 0;
1279 double average = 0;
1280 int id = GetResId("icon", ResType::MEDIA);
1281 ASSERT_TRUE(id > 0);
1282 std::string type;
1283 size_t len;
1284 std::unique_ptr<uint8_t[]> outValue;
1285 for (int k = 0; k < 1000; ++k) {
1286 auto t1 = std::chrono::high_resolution_clock::now();
1287 rm->GetDrawableInfoById(id, type, len, outValue);
1288 auto t2 = std::chrono::high_resolution_clock::now();
1289 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1290 }
1291 average = total / 1000.0;
1292 g_logLevel = LOG_DEBUG;
1293 RESMGR_HILOGD(RESMGR_TAG, "avg cost 047: %f us", average);
1294 EXPECT_LT(average, 100);
1295 };
1296
1297 /*
1298 * @tc.name: ResourceManagerPerformanceFuncTest048
1299 * @tc.desc: Test GetDrawableInfoByName
1300 * @tc.type: FUNC
1301 */
1302 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest048, TestSize.Level1)
1303 {
1304 if (rm == nullptr) {
1305 ASSERT_TRUE(false);
1306 }
1307 unsigned long long total = 0;
1308 double average = 0;
1309 std::string type;
1310 size_t len;
1311 std::unique_ptr<uint8_t[]> outValue;
1312 for (int k = 0; k < 1000; ++k) {
1313 auto t1 = std::chrono::high_resolution_clock::now();
1314 rm->GetDrawableInfoByName(std::string("icon").c_str(), type, len, outValue);
1315 auto t2 = std::chrono::high_resolution_clock::now();
1316 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1317 }
1318 average = total / 1000.0;
1319 g_logLevel = LOG_DEBUG;
1320 RESMGR_HILOGD(RESMGR_TAG, "avg cost 048: %f us", average);
1321 EXPECT_LT(average, 100);
1322 };
1323
1324 /*
1325 * @tc.name: ResourceManagerPerformanceFuncTest049
1326 * @tc.desc: Test GetResourceLimitKeys
1327 * @tc.type: FUNC
1328 */
1329 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest049, TestSize.Level1)
1330 {
1331 if (rm == nullptr) {
1332 ASSERT_TRUE(false);
1333 }
1334 unsigned long long total = 0;
1335 double average = 0;
1336 for (int k = 0; k < 1000; ++k) {
1337 auto t1 = std::chrono::high_resolution_clock::now();
1338 rm->GetResourceLimitKeys();
1339 auto t2 = std::chrono::high_resolution_clock::now();
1340 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1341 }
1342 average = total / 1000.0;
1343 g_logLevel = LOG_DEBUG;
1344 RESMGR_HILOGD(RESMGR_TAG, "avg cost 049: %f us", average);
1345 EXPECT_LT(average, 100);
1346 };
1347
1348 /*
1349 * @tc.name: ResourceManagerPerformanceFuncTest052
1350 * @tc.desc: Test GetLocales
1351 * @tc.type: FUNC
1352 */
1353 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest052, TestSize.Level1)
1354 {
1355 if (rm == nullptr) {
1356 ASSERT_TRUE(false);
1357 }
1358 unsigned long long total = 0;
1359 double average = 0;
1360 std::vector<std::string> outValue;
1361 for (int k = 0; k < 1000; ++k) {
1362 auto t1 = std::chrono::high_resolution_clock::now();
1363 rm->GetLocales(outValue);
1364 auto t2 = std::chrono::high_resolution_clock::now();
1365 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1366 }
1367 average = total / 1000.0;
1368 g_logLevel = LOG_DEBUG;
1369 RESMGR_HILOGD(RESMGR_TAG, "avg cost 052: %f us", average);
1370 EXPECT_LT(average, 100);
1371 };
1372
1373 /*
1374 * @tc.name: ResourceManagerPerformanceFuncTest053
1375 * @tc.desc: Test GetSymbolById
1376 * @tc.type: FUNC
1377 */
1378 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest053, TestSize.Level1)
1379 {
1380 if (rm == nullptr) {
1381 ASSERT_TRUE(false);
1382 }
1383 int id = GetResId("test_symbol", ResType::SYMBOL);
1384 ASSERT_TRUE(id > 0);
1385 unsigned long long total = 0;
1386 double average = 0;
1387 uint32_t outValue;
1388 for (int k = 0; k < 1000; ++k) {
1389 auto t1 = std::chrono::high_resolution_clock::now();
1390 rm->GetSymbolById(id, outValue);
1391 auto t2 = std::chrono::high_resolution_clock::now();
1392 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1393 }
1394 average = total / 1000.0;
1395 g_logLevel = LOG_DEBUG;
1396 RESMGR_HILOGD(RESMGR_TAG, "avg cost 053: %f us", average);
1397 EXPECT_LT(average, 100);
1398 };
1399
1400 /*
1401 * @tc.name: ResourceManagerPerformanceFuncTest054
1402 * @tc.desc: Test GetSymbolByName
1403 * @tc.type: FUNC
1404 */
1405 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest054, TestSize.Level1)
1406 {
1407 if (rm == nullptr) {
1408 ASSERT_TRUE(false);
1409 }
1410 unsigned long long total = 0;
1411 double average = 0;
1412 uint32_t outValue;
1413 for (int k = 0; k < 1000; ++k) {
1414 auto t1 = std::chrono::high_resolution_clock::now();
1415 rm->GetSymbolByName(std::string("test_symbol").c_str(), outValue);
1416 auto t2 = std::chrono::high_resolution_clock::now();
1417 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1418 }
1419 average = total / 1000.0;
1420 g_logLevel = LOG_DEBUG;
1421 RESMGR_HILOGD(RESMGR_TAG, "avg cost 054: %f us", average);
1422 EXPECT_LT(average, 100);
1423 };
1424
1425 /*
1426 * @tc.name: ResourceManagerPerformanceFuncTest056
1427 * @tc.desc: Test GetStringFormatById
1428 * @tc.type: FUNC
1429 */
1430 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest056, TestSize.Level1)
1431 {
1432 if (rm == nullptr) {
1433 ASSERT_TRUE(false);
1434 }
1435 int id = GetResId("test_string2", ResType::STRING);
1436 ASSERT_TRUE(id > 0);
1437
1438 unsigned long long total = 0;
1439 double average = 0;
1440 std::string outValue;
1441 for (int k = 0; k < 1000; ++k) {
1442 auto t1 = std::chrono::high_resolution_clock::now();
1443 rm->GetStringFormatById(outValue, id, 1.00001, "你好");
1444 auto t2 = std::chrono::high_resolution_clock::now();
1445 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1446 }
1447 average = total / 1000.0;
1448 g_logLevel = LOG_DEBUG;
1449 RESMGR_HILOGD(RESMGR_TAG, "avg cost 056: %f us", average);
1450 EXPECT_LT(average, 100);
1451 };
1452
1453 /*
1454 * @tc.name: ResourceManagerPerformanceFuncTest057
1455 * @tc.desc: Test GetStringFormatByName
1456 * @tc.type: FUNC
1457 */
1458 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest057, TestSize.Level1)
1459 {
1460 if (rm == nullptr) {
1461 ASSERT_TRUE(false);
1462 }
1463 unsigned long long total = 0;
1464 double average = 0;
1465 std::string outValue;
1466 for (int k = 0; k < 1000; ++k) {
1467 auto t1 = std::chrono::high_resolution_clock::now();
1468 rm->GetStringFormatByName(outValue, std::string("test_string2").c_str(), 1.0001, "你好");
1469 auto t2 = std::chrono::high_resolution_clock::now();
1470 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1471 }
1472 average = total / 1000.0;
1473 g_logLevel = LOG_DEBUG;
1474 RESMGR_HILOGD(RESMGR_TAG, "avg cost 057: %f us", average);
1475 EXPECT_LT(average, 100);
1476 };
1477
1478 /*
1479 * @tc.name: ResourceManagerPerformanceFuncTest059
1480 * @tc.desc: Test GetFormatPluralStringByName
1481 * @tc.type: FUNC
1482 */
1483 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest059, TestSize.Level1)
1484 {
1485 if (rm == nullptr) {
1486 ASSERT_TRUE(false);
1487 }
1488 unsigned long long total = 0;
1489 double average = 0;
1490 double quantity = 1;
1491 std::string outValue;
1492 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> params;
1493 params.push_back(std::make_tuple(ResourceManager::NapiValueType::NAPI_NUMBER, std::to_string(quantity)));
1494 for (int k = 0; k < 1000; ++k) {
1495 auto t1 = std::chrono::high_resolution_clock::now();
1496 rm->GetFormatPluralStringByName(outValue, std::string("eat_apple").c_str(), quantity, params);
1497 auto t2 = std::chrono::high_resolution_clock::now();
1498 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1499 }
1500 average = total / 1000.0;
1501 g_logLevel = LOG_DEBUG;
1502 RESMGR_HILOGD(RESMGR_TAG, "avg cost 059: %f us", average);
1503 EXPECT_LT(average, 200);
1504 };
1505
1506 /*
1507 * @tc.name: ResourceManagerPerformanceFuncTest063
1508 * @tc.desc: Test GetPatternDataById
1509 * @tc.type: FUNC
1510 */
1511 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest063, TestSize.Level1)
1512 {
1513 if (rm == nullptr) {
1514 ASSERT_TRUE(false);
1515 }
1516 bool ret = rm->AddResource(FormatFullPath(g_newModuleHapPath).c_str());
1517 EXPECT_TRUE(ret);
1518 int id = GetResId("ohos_test_button_pattern", ResType::PATTERN);
1519 ASSERT_TRUE(id > 0);
1520 unsigned long long total = 0;
1521 double average = 0;
1522 std::map<std::string, ResourceManager::ResData> outValue;
1523 for (int k = 0; k < 1000; ++k) {
1524 auto t1 = std::chrono::high_resolution_clock::now();
1525 rm->GetPatternDataById(id, outValue);
1526 auto t2 = std::chrono::high_resolution_clock::now();
1527 total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1528 }
1529 average = total / 1000.0;
1530 g_logLevel = LOG_DEBUG;
1531 RESMGR_HILOGD(RESMGR_TAG, "avg cost 063: %f us", average);
1532 EXPECT_LT(average, 100);
1533 };
1534
1535 /*
1536 * @tc.name: ResourceManagerPerformanceFuncTest064
1537 * @tc.desc: Test AddResource
1538 * @tc.type: FUNC
1539 */
1540 HWTEST_F(ResourceManagerNewModulePerformanceTest, ResourceManagerPerformanceFuncTest064, TestSize.Level1)
1541 {
1542 int ret = TestLoadFromNewIndex(PERFOR_FEIL_V2_PATH);
1543 EXPECT_EQ(OK, ret);
1544 };
1545 }
1546