• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "resource_manager_performance_test.h"
17 
18 #include <chrono>
19 #include <climits>
20 #include <cstring>
21 #include <ctime>
22 #include <fstream>
23 #include <gtest/gtest.h>
24 #include <iostream>
25 
26 #define private public
27 
28 #include "hap_parser.h"
29 #include "hap_resource.h"
30 #include "resource_manager.h"
31 #include "resource_manager_impl.h"
32 #include "test_common.h"
33 #include "utils/errors.h"
34 
35 using namespace OHOS::Global::Resource;
36 using namespace testing::ext;
37 using namespace std;
38 namespace {
39 class ResourceManagerPerformanceTest : public testing::Test {
40 public:
41     static void SetUpTestCase(void);
42 
43     static void TearDownTestCase(void);
44 
45     void SetUp();
46 
47     void TearDown();
48 
ResourceManagerPerformanceTest()49     ResourceManagerPerformanceTest() : rm(nullptr)
50     {}
51 
~ResourceManagerPerformanceTest()52     ~ResourceManagerPerformanceTest()
53     {}
54 
55 public:
56     ResourceManager *rm;
57 
58     int GetResId(std::string name, ResType resType) const;
59 };
60 
GetResId(std::string name,ResType resType) const61 int ResourceManagerPerformanceTest::GetResId(std::string name, ResType resType) const
62 {
63     auto idv = ((ResourceManagerImpl *)rm)->hapManager_->GetResourceListByName(name.c_str(), resType);
64     if (idv == nullptr) {
65         return -1;
66     }
67 
68     if (idv->GetLimitPathsConst().size() > 0) {
69         return idv->GetLimitPathsConst()[0]->GetIdItem()->id_;
70     }
71     return OBJ_NOT_FOUND;
72 }
73 
SetUpTestCase(void)74 void ResourceManagerPerformanceTest::SetUpTestCase(void)
75 {
76     // step 1: input testsuit setup step
77 }
78 
TearDownTestCase(void)79 void ResourceManagerPerformanceTest::TearDownTestCase(void)
80 {
81     // step 2: input testsuit teardown step
82 }
83 
SetUp(void)84 void ResourceManagerPerformanceTest::SetUp(void)
85 {
86     // PerformanceTest need higher log level
87     g_logLevel = LOG_INFO;
88     this->rm = CreateResourceManager();
89     if (rm == nullptr) {
90         return;
91     }
92     auto rc = CreateResConfig();
93     if (rc == nullptr) {
94         return;
95     }
96     rc->SetLocaleInfo("zh", nullptr, nullptr);
97     rm->UpdateResConfig(*rc);
98     delete rc;
99     bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str());
100     if (!ret) {
101         HILOG_ERROR("AddResource failed. test would fail.");
102     }
103 }
104 
TearDown(void)105 void ResourceManagerPerformanceTest::TearDown(void)
106 {
107     if (this->rm != nullptr) {
108         delete this->rm;
109         this->rm = nullptr;
110     }
111 }
112 
113 // test HapResource::LoadFromIndex(), spilt to two parts: 1. read from file, 2. parse buf to HapResource
TestLoadFromIndex(const char * filePath)114 int TestLoadFromIndex(const char *filePath)
115 {
116     unsigned long long total = 0;
117     double average = 0;
118     std::string pstr = FormatFullPath(filePath);
119 
120     auto start = std::chrono::high_resolution_clock::now();
121     std::ifstream inFile(pstr.c_str(), std::ios::binary | std::ios::in);
122     if (!inFile.good()) {
123         return -1;
124     }
125     inFile.seekg(0, std::ios::end);
126     size_t bufLen = inFile.tellg();
127     if (bufLen <= 0) {
128         HILOG_ERROR("file size is zero");
129         inFile.close();
130         return -1;
131     }
132     void *buf = malloc(bufLen);
133     if (buf == nullptr) {
134         HILOG_ERROR("Error allocating memory");
135         inFile.close();
136         return -1;
137     }
138     inFile.seekg(0, std::ios::beg);
139     inFile.read((char *)buf, bufLen);
140     inFile.close();
141 
142     auto end = std::chrono::high_resolution_clock::now();
143     auto readFilecost = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
144 
145     g_logLevel = LOG_DEBUG;
146     HILOG_DEBUG("read index file cost 001: %lld us", readFilecost);
147     g_logLevel = LOG_INFO;
148 
149     for (int k = 0; k < 1000; ++k) {
150         auto t1 = std::chrono::high_resolution_clock::now();
151         ResDesc *resDesc = new(std::nothrow) ResDesc();
152         if (resDesc == nullptr) {
153             HILOG_ERROR("new ResDesc failed when LoadFromIndex");
154             free(buf);
155             return -1;
156         }
157         int32_t out = HapParser::ParseResHex((char *)buf, bufLen, *resDesc, nullptr);
158         if (out != OK) {
159             delete (resDesc);
160             free(buf);
161             HILOG_ERROR("ParseResHex failed! retcode:%d", out);
162             return -1;
163         } else {
164             HILOG_DEBUG("ParseResHex success:\n%s", resDesc->ToString().c_str());
165         }
166 
167         HapResource *pResource = new(std::nothrow) HapResource(pstr, 0, nullptr, resDesc);
168         if (pResource == nullptr) {
169             HILOG_ERROR("new HapResource failed when LoadFromIndex");
170             delete (resDesc);
171             free(buf);
172             return -1;
173         }
174         if (!pResource->Init()) {
175             delete (pResource);
176             free(buf);
177             return -1;
178         }
179         auto t2 = std::chrono::high_resolution_clock::now();
180         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
181         delete pResource;
182     }
183     free(buf);
184     average = total / 1000.0;
185     g_logLevel = LOG_DEBUG;
186     HILOG_DEBUG("parse index avg cost 001: %f us", average);
187     EXPECT_LT(average, 4000);
188     return OK;
189 }
190 
191 /*
192  * @tc.name: ResourceManagerPerformanceFuncTest001
193  * @tc.desc: Test AddResource
194  * @tc.type: FUNC
195  */
196 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest001, TestSize.Level1)
197 {
198     int ret = TestLoadFromIndex(g_resFilePath);
199     EXPECT_EQ(OK, ret);
200 };
201 
202 /*
203  * @tc.name: ResourceManagerPerformanceFuncTest002
204  * @tc.desc: Test UpdateResConfig
205  * @tc.type: FUNC
206  */
207 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest002, TestSize.Level1)
208 {
209     unsigned long long total = 0;
210     double average = 0;
211     auto tmpRm = CreateResourceManager();
212     if (tmpRm == nullptr) {
213         ASSERT_TRUE(false);
214     }
215     ResConfig *rc = CreateResConfig();
216     if (rc == nullptr) {
217         delete tmpRm;
218         ASSERT_TRUE(false);
219     }
220     rc->SetLocaleInfo("en", nullptr, "US");
221     rc->SetDeviceType(DeviceType::DEVICE_CAR);
222     for (int k = 0; k < 1000; ++k) {
223         auto t1 = std::chrono::high_resolution_clock::now();
224         tmpRm->UpdateResConfig(*rc);
225         auto t2 = std::chrono::high_resolution_clock::now();
226         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
227     }
228     delete tmpRm;
229     delete rc;
230     average = total / 1000.0;
231     g_logLevel = LOG_DEBUG;
232     HILOG_DEBUG("avg cost 002: %f us", average);
233     EXPECT_LT(average, 100);
234 };
235 
236 /*
237  * @tc.name: ResourceManagerPerformanceFuncTest003
238  * @tc.desc: Test GetResConfig
239  * @tc.type: FUNC
240  */
241 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest003, TestSize.Level1)
242 {
243     if (rm == nullptr) {
244         ASSERT_TRUE(false);
245     }
246     unsigned long long total = 0;
247     double average = 0;
248     ResConfig *rc = CreateResConfig();
249     if (rc == nullptr) {
250         ASSERT_TRUE(false);
251     }
252     rc->SetLocaleInfo("en", nullptr, "US");
253     rc->SetDeviceType(DeviceType::DEVICE_CAR);
254     ResConfigImpl rci;
255     for (int k = 0; k < 1000; ++k) {
256         auto t1 = std::chrono::high_resolution_clock::now();
257         rm->GetResConfig(rci);
258         auto t2 = std::chrono::high_resolution_clock::now();
259         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
260     }
261     delete rc;
262     average = total / 1000.0;
263     g_logLevel = LOG_DEBUG;
264     HILOG_DEBUG("avg cost 003: %f us", average);
265     EXPECT_LT(average, 100);
266 };
267 
268 /*
269  * @tc.name: ResourceManagerPerformanceFuncTest004
270  * @tc.desc: Test GetStringByID
271  * @tc.type: FUNC
272  */
273 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest004, TestSize.Level1)
274 {
275     if (rm == nullptr) {
276         ASSERT_TRUE(false);
277     }
278     unsigned long long total = 0;
279     double average = 0;
280     string name[] = {"app_name", "title"};
281     vector<uint32_t> ids;
282     int count = 2;
283     for (int i = 0; i < count; ++i) {
284         int id = GetResId(name[i], ResType::STRING);
285         ASSERT_TRUE(id > 0);
286         ids.push_back(static_cast<uint32_t>(id));
287     }
288 
289     std::string outValue;
290     for (int k = 0; k < 1000; ++k) {
291         for (int i = 0; i < count; ++i) {
292             auto t1 = std::chrono::high_resolution_clock::now();
293             rm->GetStringById(ids[i], outValue);
294             auto t2 = std::chrono::high_resolution_clock::now();
295             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
296         }
297     }
298     average = total / (1000.0 * count);
299     g_logLevel = LOG_DEBUG;
300     HILOG_DEBUG("avg cost 004: %f us", average);
301     EXPECT_LT(average, 100);
302 };
303 
304 /*
305  * @tc.name: ResourceManagerPerformanceFuncTest005
306  * @tc.desc: Test GetStringByName
307  * @tc.type: FUNC
308  */
309 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest005, TestSize.Level1)
310 {
311     if (rm == nullptr) {
312         ASSERT_TRUE(false);
313     }
314     unsigned long long total = 0;
315     double average = 0;
316     string name[] = {"app_name", "title"};
317     int count = 2;
318     std::string outValue;
319     for (int k = 0; k < 1000; ++k) {
320         for (int i = 0; i < count; ++i) {
321             auto t1 = std::chrono::high_resolution_clock::now();
322             rm->GetStringByName(name[i].c_str(), outValue);
323             auto t2 = std::chrono::high_resolution_clock::now();
324             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
325         }
326     }
327     average = total / (1000.0 * count);
328     g_logLevel = LOG_DEBUG;
329     HILOG_DEBUG("avg cost 005: %f us", average);
330     EXPECT_LT(average, 100);
331 };
332 
333 /*
334  * @tc.name: ResourceManagerPerformanceFuncTest006
335  * @tc.desc: Test GetStringByName
336  * @tc.type: FUNC
337  */
338 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest006, TestSize.Level1)
339 {
340     if (rm == nullptr) {
341         ASSERT_TRUE(false);
342     }
343     unsigned long long total = 0;
344     double average = 0;
345     string name[] = {"string_ref", "string_ref2"};
346     int count = 2;
347     std::string outValue;
348     for (int k = 0; k < 1000; ++k) {
349         for (int i = 0; i < count; ++i) {
350             auto t1 = std::chrono::high_resolution_clock::now();
351             rm->GetStringByName(name[i].c_str(), outValue);
352             auto t2 = std::chrono::high_resolution_clock::now();
353             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
354         }
355     }
356     average = total / (1000.0 * count);
357     g_logLevel = LOG_DEBUG;
358     HILOG_DEBUG("avg cost 006: %f us", average);
359     EXPECT_LT(average, 100);
360 };
361 
362 /*
363  * @tc.name: ResourceManagerPerformanceFuncTest007
364  * @tc.desc: Test GetStringFormatById
365  * @tc.type: FUNC
366  */
367 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest007, TestSize.Level1)
368 {
369     if (rm == nullptr) {
370         ASSERT_TRUE(false);
371     }
372     unsigned long long total = 0;
373     double average = 0;
374     string name[] = {"app_name", "title"};
375     vector<uint32_t> ids;
376     int count = 2;
377     for (int i = 0; i < count; ++i) {
378         int id = GetResId(name[i], ResType::STRING);
379         ASSERT_TRUE(id > 0);
380         ids.push_back(static_cast<uint32_t>(id));
381     }
382 
383     std::string outValue;
384     for (int k = 0; k < 1000; ++k) {
385         for (int i = 0; i < count; ++i) {
386             auto t1 = std::chrono::high_resolution_clock::now();
387             rm->GetStringFormatById(outValue, ids[i], 12);
388             auto t2 = std::chrono::high_resolution_clock::now();
389             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
390         }
391     }
392     average = total / (1000.0 * count);
393     g_logLevel = LOG_DEBUG;
394     HILOG_DEBUG("avg cost 007: %f us", average);
395     EXPECT_LT(average, 100);
396 };
397 
398 /*
399  * @tc.name: ResourceManagerPerformanceFuncTest008
400  * @tc.desc: Test GetStringFormatByName
401  * @tc.type: FUNC
402  */
403 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest008, TestSize.Level1)
404 {
405     if (rm == nullptr) {
406         ASSERT_TRUE(false);
407     }
408     unsigned long long total = 0;
409     double average = 0;
410     string name[] = {"app_name", "title"};
411     int count = 2;
412     std::string outValue;
413     for (int k = 0; k < 1000; ++k) {
414         for (int i = 0; i < count; ++i) {
415             auto t1 = std::chrono::high_resolution_clock::now();
416             rm->GetStringFormatByName(outValue, name[i].c_str(), 123);
417             auto t2 = std::chrono::high_resolution_clock::now();
418             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
419         }
420     }
421     average = total / (1000.0 * count);
422     g_logLevel = LOG_DEBUG;
423     HILOG_DEBUG("avg cost 008: %f us", average);
424     EXPECT_LT(average, 100);
425 };
426 
427 /*
428  * @tc.name: ResourceManagerPerformanceFuncTest009
429  * @tc.desc: Test GetStringArrayById
430  * @tc.type: FUNC
431  */
432 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest009, TestSize.Level1)
433 {
434     if (rm == nullptr) {
435         ASSERT_TRUE(false);
436     }
437     unsigned long long total = 0;
438     double average = 0;
439     int id = GetResId("size", ResType::STRINGARRAY);
440     ASSERT_TRUE(id > 0);
441 
442     std::vector<std::string> outValue;
443     for (int k = 0; k < 1000; ++k) {
444         auto t1 = std::chrono::high_resolution_clock::now();
445         rm->GetStringArrayById(id, outValue);
446         auto t2 = std::chrono::high_resolution_clock::now();
447         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
448     }
449     average = total / 1000.0;
450     g_logLevel = LOG_DEBUG;
451     HILOG_DEBUG("avg cost 009: %f us", average);
452     EXPECT_LT(average, 100);
453 };
454 
455 /*
456  * @tc.name: ResourceManagerPerformanceFuncTest010
457  * @tc.desc: Test GetStringArrayByName
458  * @tc.type: FUNC
459  */
460 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest010, TestSize.Level1)
461 {
462     if (rm == nullptr) {
463         ASSERT_TRUE(false);
464     }
465     unsigned long long total = 0;
466     double average = 0;
467     std::vector<std::string> outValue;
468     for (int k = 0; k < 1000; ++k) {
469         auto t1 = std::chrono::high_resolution_clock::now();
470         rm->GetStringArrayByName("size", outValue);
471         auto t2 = std::chrono::high_resolution_clock::now();
472         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
473     }
474     average = total / 1000.0;
475     g_logLevel = LOG_DEBUG;
476     HILOG_DEBUG("avg cost 010: %f us", average);
477     EXPECT_LT(average, 100);
478 };
479 
480 /*
481  * @tc.name: ResourceManagerPerformanceFuncTest011
482  * @tc.desc: Test GetPatternById
483  * @tc.type: FUNC
484  */
485 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest011, TestSize.Level1)
486 {
487     if (rm == nullptr) {
488         ASSERT_TRUE(false);
489     }
490     unsigned long long total = 0;
491     double average = 0;
492     string name[] = {"base", "child"};
493     vector<uint32_t> ids;
494     int count = 2;
495     for (int i = 0; i < count; ++i) {
496         int id = GetResId(name[i], ResType::PATTERN);
497         ASSERT_TRUE(id > 0);
498         ids.push_back(static_cast<uint32_t>(id));
499     }
500     std::map<std::string, std::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->GetPatternById(ids[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     HILOG_DEBUG("avg cost 011: %f us", average);
512     EXPECT_LT(average, 100);
513 };
514 
515 /*
516  * @tc.name: ResourceManagerPerformanceFuncTest012
517  * @tc.desc: Test GetPatternByName
518  * @tc.type: FUNC
519  */
520 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest012, TestSize.Level1)
521 {
522     if (rm == nullptr) {
523         ASSERT_TRUE(false);
524     }
525     unsigned long long total = 0;
526     double average = 0;
527     string name[] = {"base", "child"};
528     int count = 2;
529     std::map<std::string, std::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->GetPatternByName(name[i].c_str(), 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     HILOG_DEBUG("avg cost 012: %f us", average);
541     EXPECT_LT(average, 100);
542 };
543 
544 /*
545  * @tc.name: ResourceManagerPerformanceFuncTest013
546  * @tc.desc: Test GetPluralStringById
547  * @tc.type: FUNC
548  */
549 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest013, 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->GetPluralStringById(id, quantity[i], outValue);
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     HILOG_DEBUG("avg cost 013: %f us", average);
573     EXPECT_LT(average, 100);
574 };
575 
576 /*
577  * @tc.name: ResourceManagerPerformanceFuncTest014
578  * @tc.desc: Test GetPluralStringByName
579  * @tc.type: FUNC
580  */
581 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest014, 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->GetPluralStringByName("eat_apple", quantity[i], outValue);
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     HILOG_DEBUG("avg cost 014: %f us", average);
602     EXPECT_LT(average, 100);
603 };
604 
605 /*
606  * @tc.name: ResourceManagerPerformanceFuncTest015
607  * @tc.desc: Test GetPluralStringByIdFormat
608  * @tc.type: FUNC
609  */
610 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest015, TestSize.Level1)
611 {
612     if (rm == nullptr) {
613         ASSERT_TRUE(false);
614     }
615     unsigned long long total = 0;
616     double average = 0;
617     int quantity[] = {1, 100};
618     int count = 2;
619     int id = GetResId("eat_apple", ResType::PLURALS);
620     ASSERT_TRUE(id > 0);
621 
622     string outValue;
623     for (int k = 0; k < 1000; ++k) {
624         for (int i = 0; i < count; ++i) {
625             auto t1 = std::chrono::high_resolution_clock::now();
626             rm->GetPluralStringByIdFormat(outValue, id, quantity[i], quantity[i]);
627             auto t2 = std::chrono::high_resolution_clock::now();
628             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
629         }
630     }
631     average = total / (1000.0 * count);
632     g_logLevel = LOG_DEBUG;
633     HILOG_DEBUG("avg cost 015: %f us", average);
634     EXPECT_LT(average, 100);
635 };
636 
637 /*
638  * @tc.name: ResourceManagerPerformanceFuncTest016
639  * @tc.desc: Test GetPluralStringByNameFormat
640  * @tc.type: FUNC
641  */
642 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest016, TestSize.Level1)
643 {
644     if (rm == nullptr) {
645         ASSERT_TRUE(false);
646     }
647     unsigned long long total = 0;
648     double average = 0;
649     int quantity[] = {1, 100};
650     int count = 2;
651     string outValue;
652     for (int k = 0; k < 1000; ++k) {
653         for (int i = 0; i < count; ++i) {
654             auto t1 = std::chrono::high_resolution_clock::now();
655             rm->GetPluralStringByNameFormat(outValue, "eat_apple", quantity[i], quantity[i]);
656             auto t2 = std::chrono::high_resolution_clock::now();
657             total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
658         }
659     }
660     average = total / (1000.0 * count);
661     g_logLevel = LOG_DEBUG;
662     HILOG_DEBUG("avg cost 016: %f us", average);
663     EXPECT_LT(average, 100);
664 };
665 
666 /*
667  * @tc.name: ResourceManagerPerformanceFuncTest017
668  * @tc.desc: Test GetThemeById
669  * @tc.type: FUNC
670  */
671 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest017, TestSize.Level1)
672 {
673     if (rm == nullptr) {
674         ASSERT_TRUE(false);
675     }
676     unsigned long long total = 0;
677     double average = 0;
678     int id = GetResId("app_theme", ResType::THEME);
679     ASSERT_TRUE(id > 0);
680 
681     std::map<std::string, std::string> outValue;
682     for (int k = 0; k < 1000; ++k) {
683         auto t1 = std::chrono::high_resolution_clock::now();
684         rm->GetThemeById(id, outValue);
685         auto t2 = std::chrono::high_resolution_clock::now();
686         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
687     }
688     average = total / 1000.0;
689     g_logLevel = LOG_DEBUG;
690     HILOG_DEBUG("avg cost 017: %f us", average);
691     EXPECT_LT(average, 100);
692 };
693 
694 /*
695  * @tc.name: ResourceManagerPerformanceFuncTest018
696  * @tc.desc: Test GetThemeByName
697  * @tc.type: FUNC
698  */
699 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest018, TestSize.Level1)
700 {
701     if (rm == nullptr) {
702         ASSERT_TRUE(false);
703     }
704     unsigned long long total = 0;
705     double average = 0;
706     std::map<std::string, std::string> outValue;
707     for (int k = 0; k < 1000; ++k) {
708         auto t1 = std::chrono::high_resolution_clock::now();
709         rm->GetThemeByName("app_theme", outValue);
710         auto t2 = std::chrono::high_resolution_clock::now();
711         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
712     }
713     average = total / 1000.0;
714     g_logLevel = LOG_DEBUG;
715     HILOG_DEBUG("avg cost 018: %f us", average);
716     EXPECT_LT(average, 100);
717 };
718 
719 /*
720  * @tc.name: ResourceManagerPerformanceFuncTest019
721  * @tc.desc: Test GetBooleanById
722  * @tc.type: FUNC
723  */
724 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest019, TestSize.Level1)
725 {
726     if (rm == nullptr) {
727         ASSERT_TRUE(false);
728     }
729     unsigned long long total = 0;
730     double average = 0;
731     int id = GetResId("boolean_1", ResType::BOOLEAN);
732     ASSERT_TRUE(id > 0);
733 
734     bool outValue = true;
735     for (int k = 0; k < 1000; ++k) {
736         auto t1 = std::chrono::high_resolution_clock::now();
737         rm->GetBooleanById(id, outValue);
738         auto t2 = std::chrono::high_resolution_clock::now();
739         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
740     }
741     average = total / 1000.0;
742     g_logLevel = LOG_DEBUG;
743     HILOG_DEBUG("avg cost 019: %f us", average);
744     EXPECT_LT(average, 100);
745 };
746 
747 /*
748  * @tc.name: ResourceManagerPerformanceFuncTest020
749  * @tc.desc: Test GetBooleanByName
750  * @tc.type: FUNC
751  */
752 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest020, TestSize.Level1)
753 {
754     if (rm == nullptr) {
755         ASSERT_TRUE(false);
756     }
757     unsigned long long total = 0;
758     double average = 0;
759     bool outValue = true;
760     for (int k = 0; k < 1000; ++k) {
761         auto t1 = std::chrono::high_resolution_clock::now();
762         rm->GetBooleanByName("boolean_1", outValue);
763         auto t2 = std::chrono::high_resolution_clock::now();
764         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
765     }
766     average = total / 1000.0;
767     g_logLevel = LOG_DEBUG;
768     HILOG_DEBUG("avg cost 020: %f us", average);
769     EXPECT_LT(average, 100);
770 };
771 
772 /*
773  * @tc.name: ResourceManagerPerformanceFuncTest021
774  * @tc.desc: Test GetIntegerById
775  * @tc.type: FUNC
776  */
777 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest021, TestSize.Level1)
778 {
779     if (rm == nullptr) {
780         ASSERT_TRUE(false);
781     }
782     unsigned long long total = 0;
783     double average = 0;
784     int id = GetResId("integer_1", ResType::INTEGER);
785     ASSERT_TRUE(id > 0);
786 
787     int outValue = 0;
788     for (int k = 0; k < 1000; ++k) {
789         auto t1 = std::chrono::high_resolution_clock::now();
790         rm->GetIntegerById(id, outValue);
791         auto t2 = std::chrono::high_resolution_clock::now();
792         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
793     }
794     average = total / 1000.0;
795     g_logLevel = LOG_DEBUG;
796     HILOG_DEBUG("avg cost 021: %f us", average);
797     EXPECT_LT(average, 100);
798 };
799 
800 /*
801  * @tc.name: ResourceManagerPerformanceFuncTest022
802  * @tc.desc: Test GetIntegerByName
803  * @tc.type: FUNC
804  */
805 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest022, TestSize.Level1)
806 {
807     if (rm == nullptr) {
808         ASSERT_TRUE(false);
809     }
810     unsigned long long total = 0;
811     double average = 0;
812     int outValue = 0;
813     for (int k = 0; k < 1000; ++k) {
814         auto t1 = std::chrono::high_resolution_clock::now();
815         rm->GetIntegerByName("integer_ref", outValue);
816         auto t2 = std::chrono::high_resolution_clock::now();
817         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
818     }
819     average = total / 1000.0;
820     g_logLevel = LOG_DEBUG;
821     HILOG_DEBUG("avg cost 022: %f us", average);
822     EXPECT_LT(average, 100);
823 };
824 
825 /*
826  * @tc.name: ResourceManagerPerformanceFuncTest023
827  * @tc.desc: Test GetFloatById
828  * @tc.type: FUNC
829  */
830 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest023, TestSize.Level1)
831 {
832     if (rm == nullptr) {
833         ASSERT_TRUE(false);
834     }
835     unsigned long long total = 0;
836     double average = 0;
837     int id = GetResId("width_appBar_backButton_touchTarget", ResType::FLOAT);
838     ASSERT_TRUE(id > 0);
839 
840     float outValue = 0.0;
841     for (int k = 0; k < 1000; ++k) {
842         auto t1 = std::chrono::high_resolution_clock::now();
843         rm->GetFloatById(id, outValue);
844         auto t2 = std::chrono::high_resolution_clock::now();
845         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
846     }
847     average = total / 1000.0;
848     g_logLevel = LOG_DEBUG;
849     HILOG_DEBUG("avg cost 023: %f us", average);
850     EXPECT_LT(average, 100);
851 };
852 
853 /*
854  * @tc.name: ResourceManagerPerformanceFuncTest024
855  * @tc.desc: Test GetFloatByName
856  * @tc.type: FUNC
857  */
858 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest024, TestSize.Level1)
859 {
860     if (rm == nullptr) {
861         ASSERT_TRUE(false);
862     }
863     unsigned long long total = 0;
864     double average = 0;
865     float outValue = 0;
866     for (int k = 0; k < 1000; ++k) {
867         auto t1 = std::chrono::high_resolution_clock::now();
868         rm->GetFloatByName("width_appBar_backButton_touchTarget", outValue);
869         auto t2 = std::chrono::high_resolution_clock::now();
870         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
871     }
872     average = total / 1000.0;
873     g_logLevel = LOG_DEBUG;
874     HILOG_DEBUG("avg cost 024: %f us", average);
875     EXPECT_LT(average, 100);
876 };
877 
878 /*
879  * @tc.name: ResourceManagerPerformanceFuncTest025
880  * @tc.desc: Test GetIntArrayById
881  * @tc.type: FUNC
882  */
883 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest025, TestSize.Level1)
884 {
885     if (rm == nullptr) {
886         ASSERT_TRUE(false);
887     }
888     unsigned long long total = 0;
889     double average = 0;
890     int id = GetResId("intarray_1", ResType::INTARRAY);
891     ASSERT_TRUE(id > 0);
892 
893     std::vector<int> outValue;
894     for (int k = 0; k < 1000; ++k) {
895         auto t1 = std::chrono::high_resolution_clock::now();
896         rm->GetIntArrayById(id, outValue);
897         auto t2 = std::chrono::high_resolution_clock::now();
898         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
899     }
900     average = total / 1000.0;
901     g_logLevel = LOG_DEBUG;
902     HILOG_DEBUG("avg cost 025: %f us", average);
903     EXPECT_LT(average, 100);
904 };
905 
906 /*
907  * @tc.name: ResourceManagerPerformanceFuncTest026
908  * @tc.desc: Test GetIntArrayByName
909  * @tc.type: FUNC
910  */
911 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest026, TestSize.Level1)
912 {
913     if (rm == nullptr) {
914         ASSERT_TRUE(false);
915     }
916     unsigned long long total = 0;
917     double average = 0;
918     std::vector<int> outValue;
919     for (int k = 0; k < 1000; ++k) {
920         auto t1 = std::chrono::high_resolution_clock::now();
921         rm->GetIntArrayByName("intarray_1", outValue);
922         auto t2 = std::chrono::high_resolution_clock::now();
923         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
924     }
925     average = total / 1000.0;
926     g_logLevel = LOG_DEBUG;
927     HILOG_DEBUG("avg cost 026: %f us", average);
928     EXPECT_LT(average, 100);
929 };
930 
931 /*
932  * @tc.name: ResourceManagerPerformanceFuncTest027
933  * @tc.desc: Test GetColorById
934  * @tc.type: FUNC
935  */
936 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest027, TestSize.Level1)
937 {
938     if (rm == nullptr) {
939         ASSERT_TRUE(false);
940     }
941     unsigned long long total = 0;
942     double average = 0;
943     int id = GetResId("divider_color", ResType::COLOR);
944     ASSERT_TRUE(id > 0);
945 
946     uint32_t outValue;
947     for (int k = 0; k < 1000; ++k) {
948         auto t1 = std::chrono::high_resolution_clock::now();
949         rm->GetColorById(id, outValue);
950         auto t2 = std::chrono::high_resolution_clock::now();
951         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
952     }
953     average = total / 1000.0;
954     g_logLevel = LOG_DEBUG;
955     HILOG_DEBUG("avg cost 027: %f us", average);
956     EXPECT_LT(average, 100);
957 };
958 
959 /*
960  * @tc.name: ResourceManagerPerformanceFuncTest028
961  * @tc.desc: Test GetColorByName
962  * @tc.type: FUNC
963  */
964 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest028, TestSize.Level1)
965 {
966     if (rm == nullptr) {
967         ASSERT_TRUE(false);
968     }
969     unsigned long long total = 0;
970     double average = 0;
971     uint32_t outValue;
972     for (int k = 0; k < 1000; ++k) {
973         auto t1 = std::chrono::high_resolution_clock::now();
974         rm->GetColorByName("divider_color", outValue);
975         auto t2 = std::chrono::high_resolution_clock::now();
976         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
977     }
978     average = total / 1000.0;
979     g_logLevel = LOG_DEBUG;
980     HILOG_DEBUG("avg cost 028: %f us", average);
981     EXPECT_LT(average, 100);
982 };
983 
984 /*
985  * @tc.name: ResourceManagerPerformanceFuncTest029
986  * @tc.desc: Test GetProfileById
987  * @tc.type: FUNC
988  */
989 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest029, TestSize.Level1)
990 {
991     if (rm == nullptr) {
992         ASSERT_TRUE(false);
993     }
994     unsigned long long total = 0;
995     double average = 0;
996     int id = GetResId("test_common", ResType::PROF);
997     ASSERT_TRUE(id > 0);
998 
999     string outValue;
1000     for (int k = 0; k < 1000; ++k) {
1001         auto t1 = std::chrono::high_resolution_clock::now();
1002         rm->GetProfileById(id, outValue);
1003         auto t2 = std::chrono::high_resolution_clock::now();
1004         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1005     }
1006     average = total / 1000.0;
1007     g_logLevel = LOG_DEBUG;
1008     HILOG_DEBUG("avg cost 029: %f us", average);
1009     EXPECT_LT(average, 100);
1010 };
1011 
1012 /*
1013  * @tc.name: ResourceManagerPerformanceFuncTest030
1014  * @tc.desc: Test GetProfileByName
1015  * @tc.type: FUNC
1016  */
1017 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest030, TestSize.Level1)
1018 {
1019     if (rm == nullptr) {
1020         ASSERT_TRUE(false);
1021     }
1022     unsigned long long total = 0;
1023     double average = 0;
1024     string outValue;
1025     for (int k = 0; k < 1000; ++k) {
1026         auto t1 = std::chrono::high_resolution_clock::now();
1027         rm->GetProfileByName("test_common", outValue);
1028         auto t2 = std::chrono::high_resolution_clock::now();
1029         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1030     }
1031     average = total / 1000.0;
1032     g_logLevel = LOG_DEBUG;
1033     HILOG_DEBUG("avg cost 030: %f us", average);
1034     EXPECT_LT(average, 100);
1035 };
1036 
1037 /*
1038  * @tc.name: ResourceManagerPerformanceFuncTest031
1039  * @tc.desc: Test GetMediaById
1040  * @tc.type: FUNC
1041  */
1042 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest031, TestSize.Level1)
1043 {
1044     if (rm == nullptr) {
1045         ASSERT_TRUE(false);
1046     }
1047     unsigned long long total = 0;
1048     double average = 0;
1049     int id = GetResId("icon", ResType::MEDIA);
1050     ASSERT_TRUE(id > 0);
1051 
1052     string outValue;
1053     for (int k = 0; k < 1000; ++k) {
1054         auto t1 = std::chrono::high_resolution_clock::now();
1055         rm->GetMediaById(id, outValue);
1056         auto t2 = std::chrono::high_resolution_clock::now();
1057         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1058     }
1059     average = total / 1000.0;
1060     g_logLevel = LOG_DEBUG;
1061     HILOG_DEBUG("avg cost 031: %f us", average);
1062     EXPECT_LT(average, 100);
1063 };
1064 
1065 /*
1066  * @tc.name: ResourceManagerPerformanceFuncTest032
1067  * @tc.desc: Test GetMediaByName
1068  * @tc.type: FUNC
1069  */
1070 HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest032, TestSize.Level1)
1071 {
1072     if (rm == nullptr) {
1073         ASSERT_TRUE(false);
1074     }
1075     unsigned long long total = 0;
1076     double average = 0;
1077     string outValue;
1078     for (int k = 0; k < 1000; ++k) {
1079         auto t1 = std::chrono::high_resolution_clock::now();
1080         rm->GetMediaByName("icon", outValue);
1081         auto t2 = std::chrono::high_resolution_clock::now();
1082         total += std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
1083     }
1084     average = total / 1000.0;
1085     g_logLevel = LOG_DEBUG;
1086     HILOG_DEBUG("avg cost 032: %f us", average);
1087     EXPECT_LT(average, 100);
1088 };
1089 }
1090