• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstddef>
17 #include <ctime>
18 #include <sys/time.h>
19 
20 #include "gtest/gtest.h"
21 #include "ecmascript/base/string_helper.h"
22 #include "ecmascript/builtins/builtins.h"
23 #include "ecmascript/builtins/builtins_function.h"
24 #include "ecmascript/builtins/builtins_locale.h"
25 #include "ecmascript/builtins/builtins_regexp.h"
26 #include "ecmascript/containers/containers_hashset.h"
27 #include "ecmascript/containers/containers_lightweightmap.h"
28 #include "ecmascript/containers/containers_lightweightset.h"
29 #include "ecmascript/containers/containers_private.h"
30 #include "ecmascript/debugger/hot_reload_manager.h"
31 #include "ecmascript/debugger/js_debugger_manager.h"
32 #include "ecmascript/ecma_global_storage.h"
33 #include "ecmascript/ecma_vm.h"
34 #include "ecmascript/global_env.h"
35 #include "ecmascript/js_api/js_api_arraylist.h"
36 #include "ecmascript/js_api/js_api_deque.h"
37 #include "ecmascript/js_api/js_api_hashmap.h"
38 #include "ecmascript/js_api/js_api_linked_list.h"
39 #include "ecmascript/js_api/js_api_linked_list_iterator.h"
40 #include "ecmascript/js_api/js_api_list.h"
41 #include "ecmascript/js_api/js_api_plain_array.h"
42 #include "ecmascript/js_api/js_api_queue.h"
43 #include "ecmascript/js_api/js_api_stack.h"
44 #include "ecmascript/js_api/js_api_tree_map.h"
45 #include "ecmascript/js_api/js_api_tree_set.h"
46 #include "ecmascript/js_api/js_api_vector.h"
47 #include "ecmascript/js_array.h"
48 #include "ecmascript/js_bigint.h"
49 #include "ecmascript/js_collator.h"
50 #include "ecmascript/js_date.h"
51 #include "ecmascript/js_date_time_format.h"
52 #include "ecmascript/js_generator_object.h"
53 #include "ecmascript/js_iterator.h"
54 #include "ecmascript/js_list_format.h"
55 #include "ecmascript/js_locale.h"
56 #include "ecmascript/js_map.h"
57 #include "ecmascript/js_map_iterator.h"
58 #include "ecmascript/js_number_format.h"
59 #include "ecmascript/jspandafile/js_pandafile_manager.h"
60 #include "ecmascript/js_plural_rules.h"
61 #include "ecmascript/js_primitive_ref.h"
62 #include "ecmascript/js_regexp.h"
63 #include "ecmascript/js_runtime_options.h"
64 #include "ecmascript/js_set.h"
65 #include "ecmascript/js_set_iterator.h"
66 #include "ecmascript/js_string_iterator.h"
67 #include "ecmascript/js_tagged_number.h"
68 #include "ecmascript/js_thread.h"
69 #include "ecmascript/linked_hash_table.h"
70 #include "ecmascript/module/js_module_deregister.h"
71 #include "ecmascript/module/js_module_namespace.h"
72 #include "ecmascript/module/js_module_record.h"
73 #include "ecmascript/module/js_module_source_text.h"
74 #include "ecmascript/napi/include/jsnapi.h"
75 #include "ecmascript/napi/jsnapi_helper.h"
76 #include "ecmascript/object_factory.h"
77 #include "ecmascript/tagged_array.h"
78 #include "ecmascript/tagged_hash_array.h"
79 #include "ecmascript/tagged_list.h"
80 #include "ecmascript/tagged_tree.h"
81 #include "ecmascript/tests/test_helper.h"
82 
83 using namespace panda;
84 using namespace panda::ecmascript;
85 
86 static constexpr int NUM_COUNT = 10000;
87 static constexpr int TIME_UNIT = 1000000;
88 time_t g_timeFor = 0;
89 struct timeval g_beginTime;
90 struct timeval g_endTime;
91 time_t g_time1 = 0;
92 time_t g_time2 = 0;
93 time_t g_time = 0;
94 
95 #define TEST_TIME(NAME)                                                                  \
96     {                                                                                    \
97         g_time1 = (g_beginTime.tv_sec * TIME_UNIT) + (g_beginTime.tv_usec);              \
98         g_time2 = (g_endTime.tv_sec * TIME_UNIT) + (g_endTime.tv_usec);                  \
99         g_time = g_time2 - g_time1;                                                      \
100         GTEST_LOG_(INFO) << "name =" << #NAME << " = Time =" << int(g_time - g_timeFor); \
101     }
102 
103 namespace panda::test {
104 using BuiltinsFunction = ecmascript::builtins::BuiltinsFunction;
105 
FunCallback(JsiRuntimeCallInfo * info)106 Local<JSValueRef> FunCallback(JsiRuntimeCallInfo *info)
107 {
108     EscapeLocalScope scope(info->GetVM());
109     return scope.Escape(ArrayRef::New(info->GetVM(), info->GetArgsNumber()));
110 }
111 
112 class JSNApiSplTest : public testing::Test {
113 public:
SetUpTestCase(void)114     static void SetUpTestCase(void)
115     {
116         GTEST_LOG_(INFO) << "SetUpTestCase";
117     }
118 
TearDownTestCase(void)119     static void TearDownTestCase(void)
120     {
121         GTEST_LOG_(INFO) << "TearDownCase";
122     }
123 
SetUp()124     void SetUp() override
125     {
126         RuntimeOption option;
127         option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
128         vm_ = JSNApi::CreateJSVM(option);
129         ASSERT_TRUE(vm_ != nullptr) << "Cannot create Runtime";
130         thread_ = vm_->GetJSThread();
131         vm_->SetEnableForceGC(true);
132         GTEST_LOG_(INFO) << "SetUp";
133     }
134 
TearDown()135     void TearDown() override
136     {
137         vm_->SetEnableForceGC(false);
138         JSNApi::DestroyJSVM(vm_);
139         GTEST_LOG_(INFO) << "TearDown";
140     }
141 
142 protected:
143     JSThread *thread_ = nullptr;
144     EcmaVM *vm_ = nullptr;
145 };
146 
147 #ifndef UNUSED
148 #define UNUSED(X) (void)(X)
149 #endif
150 
FreeGlobalCallBack(void * ptr)151 template <typename T> void FreeGlobalCallBack(void *ptr)
152 {
153     T *i = static_cast<T *>(ptr);
154     UNUSED(i);
155 }
NativeFinalizeCallback(void * ptr)156 template <typename T> void NativeFinalizeCallback(void *ptr)
157 {
158     T *i = static_cast<T *>(ptr);
159     delete i;
160 }
161 
CalculateForTime()162 void CalculateForTime()
163 {
164     gettimeofday(&g_beginTime, nullptr);
165     for (int i = 0; i < NUM_COUNT; i++) {
166     }
167     gettimeofday(&g_endTime, nullptr);
168     time_t start = (g_beginTime.tv_sec * TIME_UNIT) + (g_beginTime.tv_usec);
169     time_t end = (g_endTime.tv_sec * TIME_UNIT) + (g_endTime.tv_usec);
170     g_timeFor = end - start;
171     GTEST_LOG_(INFO) << "timefor = " << g_timeFor;
172 }
173 
JSLocaleCreateWithOptionTest(JSThread * thread)174 static JSTaggedValue JSLocaleCreateWithOptionTest(JSThread *thread)
175 {
176     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
177     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
178     JSHandle<JSFunction> newTarget(env->GetLocaleFunction());
179     JSHandle<JSTaggedValue> objFun = env->GetObjectFunction();
180     JSHandle<JSTaggedValue> languageKey = thread->GlobalConstants()->GetHandledLanguageString();
181     JSHandle<JSTaggedValue> regionKey = thread->GlobalConstants()->GetHandledRegionString();
182     JSHandle<JSTaggedValue> scriptKey = thread->GlobalConstants()->GetHandledScriptString();
183     JSHandle<JSTaggedValue> languageValue(factory->NewFromASCII("en"));
184     JSHandle<JSTaggedValue> regionValue(factory->NewFromASCII("US"));
185     JSHandle<JSTaggedValue> scriptValue(factory->NewFromASCII("Latn"));
186     JSHandle<JSTaggedValue> locale(factory->NewFromASCII("en-Latn-US"));
187     JSHandle<JSObject> optionsObj = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(objFun), objFun);
188     JSObject::SetProperty(thread, optionsObj, languageKey, languageValue);
189     JSObject::SetProperty(thread, optionsObj, regionKey, regionValue);
190     JSObject::SetProperty(thread, optionsObj, scriptKey, scriptValue);
191     auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*newTarget), 8);
192     ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue());
193     ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined());
194     ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue());
195     ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue());
196     auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo);
197     JSTaggedValue result = ecmascript::builtins::BuiltinsLocale::LocaleConstructor(ecmaRuntimeCallInfo);
198     TestHelper::TearDownFrame(thread, prev);
199     return result;
200 }
201 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_False)202 HWTEST_F_L0(JSNApiSplTest, JSValueRef_False)
203 {
204     LocalScope scope(vm_);
205     CalculateForTime();
206     gettimeofday(&g_beginTime, nullptr);
207     for (int i = 0; i < NUM_COUNT; i++) {
208         (void)JSValueRef::False(vm_);
209     }
210     gettimeofday(&g_endTime, nullptr);
211     TEST_TIME(JSValueRef::False);
212 }
213 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToObject_NewFromUtf8)214 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_NewFromUtf8)
215 {
216     LocalScope scope(vm_);
217     CalculateForTime();
218     Local<StringRef> obj(StringRef::NewFromUtf8(vm_, "-123.3"));
219     gettimeofday(&g_beginTime, nullptr);
220     for (int i = 0; i < NUM_COUNT; i++) {
221         (void)obj->ToObject(vm_);
222     }
223     gettimeofday(&g_endTime, nullptr);
224     TEST_TIME(JSValueRef::ToObject);
225 }
226 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToObject_NewFromUtf16)227 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_NewFromUtf16)
228 {
229     LocalScope scope(vm_);
230     CalculateForTime();
231     char16_t data = 0Xdf06;
232     Local<StringRef> obj = StringRef::NewFromUtf16(vm_, &data);
233     gettimeofday(&g_beginTime, nullptr);
234     for (int i = 0; i < NUM_COUNT; i++) {
235         (void)obj->ToObject(vm_);
236     }
237     gettimeofday(&g_endTime, nullptr);
238     TEST_TIME(JSValueRef::ToObject);
239 }
240 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToObject_NumberRef)241 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_NumberRef)
242 {
243     LocalScope scope(vm_);
244     CalculateForTime();
245     double num = 1.236;
246     Local<NumberRef> numberObj(NumberRef::New(vm_, num));
247     gettimeofday(&g_beginTime, nullptr);
248     for (int i = 0; i < NUM_COUNT; i++) {
249         (void)numberObj->ToObject(vm_);
250     }
251     gettimeofday(&g_endTime, nullptr);
252     TEST_TIME(JSValueRef::ToObject);
253 }
254 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToObject_Int32_Max)255 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_Int32_Max)
256 {
257     LocalScope scope(vm_);
258     CalculateForTime();
259     int32_t num = std::numeric_limits<int32_t>::max();
260     Local<NumberRef> obj = NumberRef::New(vm_, num);
261     gettimeofday(&g_beginTime, nullptr);
262     for (int i = 0; i < NUM_COUNT; i++) {
263         (void)obj->ToObject(vm_);
264     }
265     gettimeofday(&g_endTime, nullptr);
266     TEST_TIME(JSValueRef::ToObject);
267 }
268 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToObject_Int32_Min)269 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_Int32_Min)
270 {
271     LocalScope scope(vm_);
272     CalculateForTime();
273     int32_t num = std::numeric_limits<int32_t>::min();
274     Local<NumberRef> obj = NumberRef::New(vm_, num);
275     gettimeofday(&g_beginTime, nullptr);
276     for (int i = 0; i < NUM_COUNT; i++) {
277         (void)obj->ToObject(vm_);
278     }
279     gettimeofday(&g_endTime, nullptr);
280     TEST_TIME(JSValueRef::ToObject);
281 }
282 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToObject_Int64_Max)283 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_Int64_Max)
284 {
285     LocalScope scope(vm_);
286     CalculateForTime();
287     int64_t num = std::numeric_limits<int64_t>::max();
288     Local<NumberRef> obj = NumberRef::New(vm_, num);
289     gettimeofday(&g_beginTime, nullptr);
290     for (int i = 0; i < NUM_COUNT; i++) {
291         (void)obj->ToObject(vm_);
292     }
293     gettimeofday(&g_endTime, nullptr);
294     TEST_TIME(JSValueRef::ToObject);
295 }
296 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToObject_BigIntRef)297 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_BigIntRef)
298 {
299     LocalScope scope(vm_);
300     CalculateForTime();
301     uint64_t num = std::numeric_limits<uint64_t>::max();
302     Local<BigIntRef> bigIntObj = BigIntRef::New(vm_, num);
303     gettimeofday(&g_beginTime, nullptr);
304     for (int i = 0; i < NUM_COUNT; i++) {
305         (void)bigIntObj->ToObject(vm_);
306     }
307     gettimeofday(&g_endTime, nullptr);
308     TEST_TIME(JSValueRef::ToObject);
309 }
310 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToObject_SymbolRef)311 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_SymbolRef)
312 {
313     LocalScope scope(vm_);
314     CalculateForTime();
315     Local<SymbolRef> symbolObj(SymbolRef::New(vm_, StringRef::NewFromUtf8(vm_, "-123.3")));
316     gettimeofday(&g_beginTime, nullptr);
317     for (int i = 0; i < NUM_COUNT; i++) {
318         (void)symbolObj->ToObject(vm_);
319     }
320     gettimeofday(&g_endTime, nullptr);
321     TEST_TIME(JSValueRef::ToObject);
322 }
323 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsInt_True)324 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt_True)
325 {
326     LocalScope scope(vm_);
327     CalculateForTime();
328     int32_t num = 10;
329     Local<NumberRef> obj(NumberRef::New(vm_, num));
330     gettimeofday(&g_beginTime, nullptr);
331     for (int i = 0; i < NUM_COUNT; i++) {
332         (void)obj->IsInt();
333     }
334     gettimeofday(&g_endTime, nullptr);
335     TEST_TIME(JSValueRef::IsInt);
336 }
337 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsInt_False)338 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt_False)
339 {
340     LocalScope scope(vm_);
341     CalculateForTime();
342     Local<StringRef> obj(StringRef::NewFromUtf8(vm_, "-123.3"));
343     gettimeofday(&g_beginTime, nullptr);
344     for (int i = 0; i < NUM_COUNT; i++) {
345         (void)obj->IsInt();
346     }
347     gettimeofday(&g_endTime, nullptr);
348     TEST_TIME(JSValueRef::IsInt);
349 }
350 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsInt_Int64_Max)351 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt_Int64_Max)
352 {
353     LocalScope scope(vm_);
354     CalculateForTime();
355     int64_t num = std::numeric_limits<int64_t>::max();
356     Local<NumberRef> obj = NumberRef::New(vm_, num);
357     gettimeofday(&g_beginTime, nullptr);
358     for (int i = 0; i < NUM_COUNT; i++) {
359         (void)obj->IsInt();
360     }
361     gettimeofday(&g_endTime, nullptr);
362     TEST_TIME(JSValueRef::IsInt);
363 }
364 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsInt_Double)365 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt_Double)
366 {
367     LocalScope scope(vm_);
368     CalculateForTime();
369     double num = 1.235;
370     Local<NumberRef> obj = NumberRef::New(vm_, num);
371     gettimeofday(&g_beginTime, nullptr);
372     for (int i = 0; i < NUM_COUNT; i++) {
373         (void)obj->IsInt();
374     }
375     gettimeofday(&g_endTime, nullptr);
376     TEST_TIME(JSValueRef::IsInt);
377 }
378 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsFunction_True)379 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsFunction_True)
380 {
381     LocalScope scope(vm_);
382     CalculateForTime();
383     NativePointerCallback deleter = nullptr;
384     void *cb = reinterpret_cast<void *>(BuiltinsFunction::FunctionPrototypeInvokeSelf);
385     bool callNative = true;
386     size_t nativeBindingSize = 15;
387     Local<FunctionRef> obj(FunctionRef::NewClassFunction(vm_, FunCallback, deleter, cb, callNative, nativeBindingSize));
388     gettimeofday(&g_beginTime, nullptr);
389     for (int i = 0; i < NUM_COUNT; i++) {
390         (void)obj->IsFunction(vm_);
391     }
392     gettimeofday(&g_endTime, nullptr);
393     TEST_TIME(JSValueRef::IsFunction);
394 }
395 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsFunction_False)396 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsFunction_False)
397 {
398     LocalScope scope(vm_);
399     CalculateForTime();
400     double num = 1.235;
401     Local<NumberRef> obj = NumberRef::New(vm_, num);
402     gettimeofday(&g_beginTime, nullptr);
403     for (int i = 0; i < NUM_COUNT; i++) {
404         (void)obj->IsInt();
405     }
406     gettimeofday(&g_endTime, nullptr);
407     TEST_TIME(JSValueRef::IsFunction);
408 }
409 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsSet)410 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsSet)
411 {
412     LocalScope scope(vm_);
413     CalculateForTime();
414     JSThread *thread = vm_->GetJSThread();
415     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
416     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
417     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsSetFunction();
418     JSHandle<JSSet> set =
419         JSHandle<JSSet>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
420     JSHandle<LinkedHashSet> hashSet = LinkedHashSet::Create(thread);
421     set->SetLinkedSet(thread, hashSet);
422     JSHandle<JSTaggedValue> setTag = JSHandle<JSTaggedValue>::Cast(set);
423     gettimeofday(&g_beginTime, nullptr);
424     for (int i = 0; i < NUM_COUNT; i++) {
425         JSNApiHelper::ToLocal<SetRef>(setTag)->IsSet(vm_);
426     }
427     gettimeofday(&g_endTime, nullptr);
428     TEST_TIME(JSValueRef::IsSet);
429 }
430 
HWTEST_F_L0(JSNApiSplTest,BooleanRef_New_True)431 HWTEST_F_L0(JSNApiSplTest, BooleanRef_New_True)
432 {
433     LocalScope scope(vm_);
434     CalculateForTime();
435     int num = -10000;
436     Local<BooleanRef> obj;
437     gettimeofday(&g_beginTime, nullptr);
438     for (int i = 0; i < NUM_COUNT; i++) {
439         obj = BooleanRef::New(vm_, num);
440     }
441     gettimeofday(&g_endTime, nullptr);
442     TEST_TIME(BooleanRef::New);
443 }
444 
HWTEST_F_L0(JSNApiSplTest,BooleanRef_New_False)445 HWTEST_F_L0(JSNApiSplTest, BooleanRef_New_False)
446 {
447     LocalScope scope(vm_);
448     CalculateForTime();
449     Local<BooleanRef> obj;
450     bool flag = false;
451     gettimeofday(&g_beginTime, nullptr);
452     for (int i = 0; i < NUM_COUNT; i++) {
453         obj = BooleanRef::New(vm_, flag);
454     }
455     gettimeofday(&g_endTime, nullptr);
456     TEST_TIME(BooleanRef::New);
457 }
458 
HWTEST_F_L0(JSNApiSplTest,BooleanRef_Value_True)459 HWTEST_F_L0(JSNApiSplTest, BooleanRef_Value_True)
460 {
461     LocalScope scope(vm_);
462     CalculateForTime();
463     int num = -10000;
464     Local<BooleanRef> obj(BooleanRef::New(vm_, num));
465     gettimeofday(&g_beginTime, nullptr);
466     for (int i = 0; i < NUM_COUNT; i++) {
467         (void)obj->Value();
468     }
469     gettimeofday(&g_endTime, nullptr);
470     TEST_TIME(BooleanRef::Value);
471 }
472 
HWTEST_F_L0(JSNApiSplTest,BooleanRef_Value_False)473 HWTEST_F_L0(JSNApiSplTest, BooleanRef_Value_False)
474 {
475     LocalScope scope(vm_);
476     CalculateForTime();
477     Local<BooleanRef> obj = BooleanRef::New(vm_, 0);
478     gettimeofday(&g_beginTime, nullptr);
479     for (int i = 0; i < NUM_COUNT; i++) {
480         (void)obj->Value();
481     }
482     gettimeofday(&g_endTime, nullptr);
483     TEST_TIME(BooleanRef::Value);
484 }
485 
HWTEST_F_L0(JSNApiSplTest,IsGeneratorFunction_True)486 HWTEST_F_L0(JSNApiSplTest, IsGeneratorFunction_True)
487 {
488     ObjectFactory *factory = vm_->GetFactory();
489     auto env = vm_->GetGlobalEnv();
490     JSHandle<JSTaggedValue> genFunc = env->GetGeneratorFunctionFunction();
491     JSHandle<JSGeneratorObject> genObjHandleVal = factory->NewJSGeneratorObject(genFunc);
492     JSHandle<JSHClass> hclass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
493     JSHandle<JSFunction> generatorFunc = JSHandle<JSFunction>::Cast(factory->NewJSObject(hclass));
494     JSFunction::InitializeJSFunction(vm_->GetJSThread(), generatorFunc, FunctionKind::GENERATOR_FUNCTION);
495     JSHandle<GeneratorContext> generatorContext = factory->NewGeneratorContext();
496     generatorContext->SetMethod(vm_->GetJSThread(), generatorFunc.GetTaggedValue());
497     JSHandle<JSTaggedValue> generatorContextVal = JSHandle<JSTaggedValue>::Cast(generatorContext);
498     genObjHandleVal->SetGeneratorContext(vm_->GetJSThread(), generatorContextVal.GetTaggedValue());
499     JSHandle<JSTaggedValue> genObjTagHandleVal = JSHandle<JSTaggedValue>::Cast(genObjHandleVal);
500     Local<GeneratorObjectRef> genObjectRef = JSNApiHelper::ToLocal<GeneratorObjectRef>(genObjTagHandleVal);
501     Local<JSValueRef> genObject = genObjectRef->GetGeneratorFunction(vm_);
502     gettimeofday(&g_beginTime, nullptr);
503     for (int i = 0; i < NUM_COUNT; i++) {
504         genObject->IsGeneratorFunction(vm_);
505     }
506     gettimeofday(&g_endTime, nullptr);
507     TEST_TIME(JSValueRef::IsGeneratorFunction);
508 }
509 
HWTEST_F_L0(JSNApiSplTest,IsGeneratorFunction_False)510 HWTEST_F_L0(JSNApiSplTest, IsGeneratorFunction_False)
511 {
512     LocalScope scope(vm_);
513     CalculateForTime();
514     Local<BooleanRef> obj = BooleanRef::New(vm_, 0);
515     gettimeofday(&g_beginTime, nullptr);
516     for (int i = 0; i < NUM_COUNT; i++) {
517         obj->IsGeneratorFunction(vm_);
518     }
519     gettimeofday(&g_endTime, nullptr);
520     TEST_TIME(JSValueRef::IsGeneratorFunction);
521 }
522 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsArrayBuffer)523 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArrayBuffer)
524 {
525     static bool isFree = false;
526     struct Data {
527         int32_t length;
528     };
529     const int32_t length = 15;
530     Data *data = new Data();
531     data->length = length;
532     NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
533         delete[] reinterpret_cast<uint8_t *>(buffer);
534         Data *currentData = reinterpret_cast<Data *>(data);
535         delete currentData;
536         isFree = true;
537     };
538     LocalScope scope(vm_);
539     CalculateForTime();
540     uint8_t *buffer = new uint8_t[length]();
541     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, buffer, length, deleter, data);
542     gettimeofday(&g_beginTime, nullptr);
543     for (int i = 0; i < NUM_COUNT; i++) {
544         (void)arrayBuffer->IsArrayBuffer(vm_);
545     }
546     gettimeofday(&g_endTime, nullptr);
547     TEST_TIME(JSValueRef::IsArrayBuffer);
548 }
549 
HWTEST_F_L0(JSNApiSplTest,BufferRef_New1)550 HWTEST_F_L0(JSNApiSplTest, BufferRef_New1)
551 {
552     static bool isFree = false;
553     struct Data {
554         int32_t length;
555     };
556     const int32_t length = 15;
557     NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
558         delete[] reinterpret_cast<uint8_t *>(buffer);
559         Data *currentData = reinterpret_cast<Data *>(data);
560         delete currentData;
561         isFree = true;
562     };
563     LocalScope scope(vm_);
564     CalculateForTime();
565     gettimeofday(&g_beginTime, nullptr);
566     for (int i = 0; i < NUM_COUNT; i++) {
567         isFree = false;
568         uint8_t *buffer = new uint8_t[length]();
569         Data *data = new Data();
570         data->length = length;
571         (void)BufferRef::New(vm_, buffer, length, deleter, data);
572     }
573     gettimeofday(&g_endTime, nullptr);
574     TEST_TIME(BufferRef::New);
575 }
576 
HWTEST_F_L0(JSNApiSplTest,BufferRef_New2)577 HWTEST_F_L0(JSNApiSplTest, BufferRef_New2)
578 {
579     LocalScope scope(vm_);
580     CalculateForTime();
581     const int32_t length = 15;
582     gettimeofday(&g_beginTime, nullptr);
583     for (int i = 0; i < NUM_COUNT; i++) {
584         (void)BufferRef::New(vm_, length);
585     }
586     gettimeofday(&g_endTime, nullptr);
587     TEST_TIME(BufferRef::New);
588 }
589 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsBuffer)590 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBuffer)
591 {
592     LocalScope scope(vm_);
593     CalculateForTime();
594     const int32_t length = 15;
595     Local<BufferRef> bufferRef = BufferRef::New(vm_, length);
596     gettimeofday(&g_beginTime, nullptr);
597     for (int i = 0; i < NUM_COUNT; i++) {
598         (void)bufferRef->IsBuffer(vm_);
599     }
600     gettimeofday(&g_endTime, nullptr);
601     TEST_TIME(JSValueRef::IsBuffer);
602 }
603 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsUint32Array)604 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsUint32Array)
605 {
606     LocalScope scope(vm_);
607     CalculateForTime();
608     const int32_t length = 30;
609     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
610     Local<Uint32ArrayRef> typedArray = Uint32ArrayRef::New(vm_, arrayBuffer, 4, 6);
611     gettimeofday(&g_beginTime, nullptr);
612     for (int i = 0; i < NUM_COUNT; i++) {
613         (void)typedArray->IsUint32Array(vm_);
614     }
615     gettimeofday(&g_endTime, nullptr);
616     TEST_TIME(JSValueRef::IsBuIsUint32Arrayffer);
617 }
618 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsFloat32Array)619 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsFloat32Array)
620 {
621     LocalScope scope(vm_);
622     CalculateForTime();
623     const int32_t length = 30;
624     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
625     Local<Float32ArrayRef> typedArray = Float32ArrayRef::New(vm_, arrayBuffer, 4, 6);
626     gettimeofday(&g_beginTime, nullptr);
627     for (int i = 0; i < NUM_COUNT; i++) {
628         (void)typedArray->IsFloat32Array(vm_);
629     }
630     gettimeofday(&g_endTime, nullptr);
631     TEST_TIME(JSValueRef::IsFloat32Array);
632 }
633 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsFloat64Array)634 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsFloat64Array)
635 {
636     LocalScope scope(vm_);
637     CalculateForTime();
638     const int32_t length = 30;
639     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
640     Local<Float64ArrayRef> floatArray = Float64ArrayRef::New(vm_, arrayBuffer, 4, 6);
641     gettimeofday(&g_beginTime, nullptr);
642     for (int i = 0; i < NUM_COUNT; i++) {
643         (void)floatArray->IsFloat64Array(vm_);
644     }
645     gettimeofday(&g_endTime, nullptr);
646     TEST_TIME(JSValueRef::IsFloat64Array);
647 }
648 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_TypeOf_String)649 HWTEST_F_L0(JSNApiSplTest, JSValueRef_TypeOf_String)
650 {
651     LocalScope scope(vm_);
652     CalculateForTime();
653     Local<StringRef> origin = StringRef::NewFromUtf8(vm_, "1");
654     gettimeofday(&g_beginTime, nullptr);
655     for (int i = 0; i < NUM_COUNT; i++) {
656         (void)origin->Typeof(vm_);
657     }
658     gettimeofday(&g_endTime, nullptr);
659     TEST_TIME(JSValueRef::TypeOf);
660 }
661 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_TypeOf_NumberRef)662 HWTEST_F_L0(JSNApiSplTest, JSValueRef_TypeOf_NumberRef)
663 {
664     LocalScope scope(vm_);
665     CalculateForTime();
666     Local<NumberRef> origin = NumberRef::New(vm_, 1);
667     gettimeofday(&g_beginTime, nullptr);
668     for (int i = 0; i < NUM_COUNT; i++) {
669         (void)origin->Typeof(vm_);
670     }
671     gettimeofday(&g_endTime, nullptr);
672     TEST_TIME(JSValueRef::TypeOf);
673 }
674 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_InstanceOf)675 HWTEST_F_L0(JSNApiSplTest, JSValueRef_InstanceOf)
676 {
677     LocalScope scope(vm_);
678     CalculateForTime();
679     Local<ObjectRef> origin = ObjectRef::New(vm_);
680     JSHandle<GlobalEnv> globalEnv = vm_->GetGlobalEnv();
681     JSHandle<JSFunction> constructor(globalEnv->GetObjectFunction());
682     JSHandle<JSTaggedValue> arryListTag = JSHandle<JSTaggedValue>::Cast(constructor);
683     Local<JSValueRef> value = JSNApiHelper::ToLocal<JSValueRef>(arryListTag);
684     gettimeofday(&g_beginTime, nullptr);
685     for (int i = 0; i < NUM_COUNT; i++) {
686         (void)origin->InstanceOf(vm_, value);
687     }
688     gettimeofday(&g_endTime, nullptr);
689     TEST_TIME(JSValueRef::InstanceOf);
690 }
691 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsArrayList)692 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArrayList)
693 {
694     LocalScope scope(vm_);
695     CalculateForTime();
696     JSThread *thread = vm_->GetJSThread();
697     auto factory = thread->GetEcmaVM()->GetFactory();
698     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
699     JSHandle<JSTaggedValue> proto = globalEnv->GetFunctionPrototype();
700     JSHandle<JSHClass> arrayListClass = factory->NewEcmaHClass(JSAPIArrayList::SIZE, JSType::JS_API_ARRAY_LIST, proto);
701     JSHandle<JSAPIArrayList> jsArrayList = JSHandle<JSAPIArrayList>::Cast(factory->NewJSObjectWithInit(arrayListClass));
702     jsArrayList->SetLength(thread, JSTaggedValue(0));
703     JSHandle<JSTaggedValue> arryListTag = JSHandle<JSTaggedValue>::Cast(jsArrayList);
704     gettimeofday(&g_beginTime, nullptr);
705     for (int i = 0; i < NUM_COUNT; i++) {
706         JSNApiHelper::ToLocal<JSValueRef>(arryListTag)->IsArrayList(vm_);
707     }
708     gettimeofday(&g_endTime, nullptr);
709     TEST_TIME(JSValueRef::IsArrayList);
710 }
711 
HWTEST_F_L0(JSNApiSplTest,PromiseRef_Catch)712 HWTEST_F_L0(JSNApiSplTest, PromiseRef_Catch)
713 {
714     LocalScope scope(vm_);
715     CalculateForTime();
716     Local<PromiseCapabilityRef> capability = PromiseCapabilityRef::New(vm_);
717     Local<PromiseRef> promise = capability->GetPromise(vm_);
718     Local<FunctionRef> reject = FunctionRef::New(vm_, FunCallback);
719     gettimeofday(&g_beginTime, nullptr);
720     for (int i = 0; i < NUM_COUNT; i++) {
721         (void)promise->Catch(vm_, reject);
722     }
723     gettimeofday(&g_endTime, nullptr);
724     TEST_TIME(PromiseRef::Catch);
725 }
726 
HWTEST_F_L0(JSNApiSplTest,PromiseRef_Finally)727 HWTEST_F_L0(JSNApiSplTest, PromiseRef_Finally)
728 {
729     LocalScope scope(vm_);
730     CalculateForTime();
731     Local<PromiseCapabilityRef> capability = PromiseCapabilityRef::New(vm_);
732     Local<PromiseRef> promise = capability->GetPromise(vm_);
733     Local<FunctionRef> reject = FunctionRef::New(vm_, FunCallback);
734     gettimeofday(&g_beginTime, nullptr);
735     for (int i = 0; i < NUM_COUNT; i++) {
736         (void)promise->Finally(vm_, reject);
737     }
738     gettimeofday(&g_endTime, nullptr);
739     TEST_TIME(PromiseRef::Finally);
740 }
741 
HWTEST_F_L0(JSNApiSplTest,PromiseRef_Then)742 HWTEST_F_L0(JSNApiSplTest, PromiseRef_Then)
743 {
744     LocalScope scope(vm_);
745     CalculateForTime();
746     Local<PromiseCapabilityRef> capability = PromiseCapabilityRef::New(vm_);
747     Local<PromiseRef> promise = capability->GetPromise(vm_);
748     Local<FunctionRef> callback = FunctionRef::New(vm_, FunCallback);
749     gettimeofday(&g_beginTime, nullptr);
750     for (int i = 0; i < NUM_COUNT; i++) {
751         (void)promise->Then(vm_, callback);
752     }
753     gettimeofday(&g_endTime, nullptr);
754     TEST_TIME(PromiseRef::Then);
755 }
756 
HWTEST_F_L0(JSNApiSplTest,PromiseRef_Then1)757 HWTEST_F_L0(JSNApiSplTest, PromiseRef_Then1)
758 {
759     LocalScope scope(vm_);
760     CalculateForTime();
761     Local<PromiseCapabilityRef> capability = PromiseCapabilityRef::New(vm_);
762     Local<PromiseRef> promise = capability->GetPromise(vm_);
763     Local<FunctionRef> callback = FunctionRef::New(vm_, FunCallback);
764     gettimeofday(&g_beginTime, nullptr);
765     for (int i = 0; i < NUM_COUNT; i++) {
766         (void)promise->Then(vm_, callback, callback);
767     }
768     gettimeofday(&g_endTime, nullptr);
769     TEST_TIME(PromiseRef::Then);
770 }
771 
HWTEST_F_L0(JSNApiSplTest,PromiseCapabilityRef_New)772 HWTEST_F_L0(JSNApiSplTest, PromiseCapabilityRef_New)
773 {
774     LocalScope scope(vm_);
775     CalculateForTime();
776     gettimeofday(&g_beginTime, nullptr);
777     for (int i = 0; i < NUM_COUNT; i++) {
778         (void)PromiseCapabilityRef::New(vm_);
779     }
780     gettimeofday(&g_endTime, nullptr);
781     TEST_TIME(PromiseCapabilityRef::New);
782 }
783 
HWTEST_F_L0(JSNApiSplTest,PromiseCapabilityRef_GetPromise)784 HWTEST_F_L0(JSNApiSplTest, PromiseCapabilityRef_GetPromise)
785 {
786     LocalScope scope(vm_);
787     CalculateForTime();
788     Local<PromiseCapabilityRef> capability = PromiseCapabilityRef::New(vm_);
789     gettimeofday(&g_beginTime, nullptr);
790     for (int i = 0; i < NUM_COUNT; i++) {
791         (void)capability->GetPromise(vm_);
792     }
793     gettimeofday(&g_endTime, nullptr);
794     TEST_TIME(PromiseCapabilityRef::GetPromise);
795 }
796 
HWTEST_F_L0(JSNApiSplTest,PromiseCapabilityRef_Resolve)797 HWTEST_F_L0(JSNApiSplTest, PromiseCapabilityRef_Resolve)
798 {
799     LocalScope scope(vm_);
800     CalculateForTime();
801     Local<PromiseCapabilityRef> capability = PromiseCapabilityRef::New(vm_);
802     Local<PromiseRef> promise = capability->GetPromise(vm_);
803     Local<FunctionRef> resolve = FunctionRef::New(vm_, FunCallback);
804     Local<FunctionRef> reject = FunctionRef::New(vm_, FunCallback);
805     promise->Then(vm_, resolve, reject);
806     Local<StringRef> value = NumberRef::New(vm_, 300.3);
807     gettimeofday(&g_beginTime, nullptr);
808     for (int i = 0; i < NUM_COUNT; i++) {
809         (void)capability->Resolve(vm_, value);
810     }
811     gettimeofday(&g_endTime, nullptr);
812     TEST_TIME(PromiseCapabilityRef::Resolve);
813 }
814 
HWTEST_F_L0(JSNApiSplTest,PromiseCapabilityRef_Reject)815 HWTEST_F_L0(JSNApiSplTest, PromiseCapabilityRef_Reject)
816 {
817     LocalScope scope(vm_);
818     CalculateForTime();
819     Local<PromiseCapabilityRef> capability = PromiseCapabilityRef::New(vm_);
820     Local<PromiseRef> promise = capability->GetPromise(vm_);
821     Local<FunctionRef> resolve = FunctionRef::New(vm_, FunCallback);
822     Local<FunctionRef> reject = FunctionRef::New(vm_, FunCallback);
823     promise->Then(vm_, resolve, reject);
824     Local<StringRef> value = NumberRef::New(vm_, 300.3);
825     gettimeofday(&g_beginTime, nullptr);
826     for (int i = 0; i < NUM_COUNT; i++) {
827         (void)capability->Reject(vm_, value);
828     }
829     gettimeofday(&g_endTime, nullptr);
830     TEST_TIME(PromiseCapabilityRef::Reject);
831 }
832 
HWTEST_F_L0(JSNApiSplTest,ArrayBufferRef_New)833 HWTEST_F_L0(JSNApiSplTest, ArrayBufferRef_New)
834 {
835     LocalScope scope(vm_);
836     CalculateForTime();
837     const int32_t length = 30;
838     gettimeofday(&g_beginTime, nullptr);
839     for (int i = 0; i < NUM_COUNT; i++) {
840         (void)ArrayBufferRef::New(vm_, length);
841     }
842     gettimeofday(&g_endTime, nullptr);
843     TEST_TIME(ArrayBufferRef::New);
844 }
845 
HWTEST_F_L0(JSNApiSplTest,ArrayBufferRef_New1)846 HWTEST_F_L0(JSNApiSplTest, ArrayBufferRef_New1)
847 {
848     static bool isFree = false;
849     struct Data {
850         int32_t length;
851     };
852     const int32_t length = 15;
853     NativePointerCallback deleter = [](void *env, void *buffer, void *data) -> void {
854         delete[] reinterpret_cast<uint8_t *>(buffer);
855         Data *currentData = reinterpret_cast<Data *>(data);
856         delete currentData;
857         isFree = true;
858     };
859     LocalScope scope(vm_);
860     CalculateForTime();
861     gettimeofday(&g_beginTime, nullptr);
862     for (int i = 0; i < NUM_COUNT; i++) {
863         isFree = false;
864         uint8_t *buffer = new uint8_t[length]();
865         Data *data = new Data();
866         data->length = length;
867         (void)ArrayBufferRef::New(vm_, buffer, length, deleter, data);
868     }
869     gettimeofday(&g_endTime, nullptr);
870     TEST_TIME(ArrayBufferRef::New);
871 }
872 
HWTEST_F_L0(JSNApiSplTest,ArrayBufferRef_ByteLength)873 HWTEST_F_L0(JSNApiSplTest, ArrayBufferRef_ByteLength)
874 {
875     LocalScope scope(vm_);
876     CalculateForTime();
877     const int32_t length = 30;
878     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
879     gettimeofday(&g_beginTime, nullptr);
880     for (int i = 0; i < NUM_COUNT; i++) {
881         (void)arrayBuffer->ByteLength(vm_);
882     }
883     gettimeofday(&g_endTime, nullptr);
884     TEST_TIME(ArrayBufferRef::ByteLength);
885 }
886 
HWTEST_F_L0(JSNApiSplTest,ArrayBufferRef_Detach)887 HWTEST_F_L0(JSNApiSplTest, ArrayBufferRef_Detach)
888 {
889     LocalScope scope(vm_);
890     CalculateForTime();
891     const int32_t length = 30;
892     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
893     gettimeofday(&g_beginTime, nullptr);
894     for (int i = 0; i < NUM_COUNT; i++) {
895         (void)arrayBuffer->Detach(vm_);
896     }
897     gettimeofday(&g_endTime, nullptr);
898     TEST_TIME(ArrayBufferRef::Detach);
899 }
900 
HWTEST_F_L0(JSNApiSplTest,ArrayBufferRef_IsDetach)901 HWTEST_F_L0(JSNApiSplTest, ArrayBufferRef_IsDetach)
902 {
903     LocalScope scope(vm_);
904     CalculateForTime();
905     const int32_t length = 30;
906     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
907     arrayBuffer->Detach(vm_);
908     gettimeofday(&g_beginTime, nullptr);
909     for (int i = 0; i < NUM_COUNT; i++) {
910         (void)arrayBuffer->IsDetach(vm_);
911     }
912     gettimeofday(&g_endTime, nullptr);
913     TEST_TIME(ArrayBufferRef::IsDetach);
914 }
915 
HWTEST_F_L0(JSNApiSplTest,BufferRef_ByteLength)916 HWTEST_F_L0(JSNApiSplTest, BufferRef_ByteLength)
917 {
918     LocalScope scope(vm_);
919     CalculateForTime();
920     const int32_t length = 30;
921     Local<BufferRef> obj = BufferRef::New(vm_, length);
922     gettimeofday(&g_beginTime, nullptr);
923     for (int i = 0; i < NUM_COUNT; i++) {
924         obj->ByteLength(vm_);
925     }
926     gettimeofday(&g_endTime, nullptr);
927     TEST_TIME(ArrayBufferRef::ByteLength);
928 }
929 
HWTEST_F_L0(JSNApiSplTest,BufferRef_BufferRef)930 HWTEST_F_L0(JSNApiSplTest, BufferRef_BufferRef)
931 {
932     LocalScope scope(vm_);
933     CalculateForTime();
934     const int32_t length = 30;
935     Local<BufferRef> obj = BufferRef::New(vm_, length);
936     gettimeofday(&g_beginTime, nullptr);
937     for (int i = 0; i < NUM_COUNT; i++) {
938         (void)obj->GetBuffer(vm_);
939     }
940     gettimeofday(&g_endTime, nullptr);
941     TEST_TIME(BufferRef::BufferRef);
942 }
943 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsArgumentsObject)944 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArgumentsObject)
945 {
946     LocalScope scope(vm_);
947     CalculateForTime();
948     ObjectFactory *factory = vm_->GetFactory();
949     JSHandle<JSArguments> obj = factory->NewJSArguments();
950     JSHandle<JSTaggedValue> argumentTag = JSHandle<JSTaggedValue>::Cast(obj);
951     gettimeofday(&g_beginTime, nullptr);
952     for (int i = 0; i < NUM_COUNT; i++) {
953         JSNApiHelper::ToLocal<ObjectRef>(argumentTag)->IsArgumentsObject(vm_);
954     }
955     gettimeofday(&g_endTime, nullptr);
956     TEST_TIME(JSValueRef::IsArgumentsObject);
957 }
958 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsAsyncFunction)959 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsAsyncFunction)
960 {
961     ObjectFactory *factory = vm_->GetFactory();
962     JSHandle<JSAsyncFuncObject> asyncFuncObj = factory->NewJSAsyncFuncObject();
963     JSHandle<JSTaggedValue> argumentTag = JSHandle<JSTaggedValue>::Cast(asyncFuncObj);
964     gettimeofday(&g_beginTime, nullptr);
965     for (int i = 0; i < NUM_COUNT; i++) {
966         JSNApiHelper::ToLocal<ObjectRef>(argumentTag)->IsAsyncFunction(vm_);
967     }
968     gettimeofday(&g_endTime, nullptr);
969     TEST_TIME(JSValueRef::IsAsyncFunction);
970 }
971 
972 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSLocale)973 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSLocale)
974 {
975     JSThread *thread = vm_->GetJSThread();
976     JSHandle<JSLocale> jsLocale = JSHandle<JSLocale>(thread, JSLocaleCreateWithOptionTest(thread));
977     JSHandle<JSTaggedValue> argumentTag = JSHandle<JSTaggedValue>::Cast(jsLocale);
978     gettimeofday(&g_beginTime, nullptr);
979     for (int i = 0; i < NUM_COUNT; i++) {
980         JSNApiHelper::ToLocal<ObjectRef>(argumentTag)->IsJSLocale(vm_);
981     }
982     gettimeofday(&g_endTime, nullptr);
983     TEST_TIME(JSValueRef::IsJSLocale);
984 }
985 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsDeque)986 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsDeque)
987 {
988     LocalScope scope(vm_);
989     CalculateForTime();
990     ObjectFactory *factory = vm_->GetFactory();
991     JSThread *thread = vm_->GetJSThread();
992     JSHandle<JSTaggedValue> proto = thread->GetEcmaVM()->GetGlobalEnv()->GetFunctionPrototype();
993     JSHandle<JSHClass> queueClass = factory->NewEcmaHClass(JSAPIDeque::SIZE, JSType::JS_API_DEQUE, proto);
994     JSHandle<JSAPIQueue> jsQueue = JSHandle<JSAPIQueue>::Cast(factory->NewJSObjectWithInit(queueClass));
995     JSHandle<TaggedArray> newElements = factory->NewTaggedArray(JSAPIDeque::DEFAULT_CAPACITY_LENGTH);
996     jsQueue->SetLength(thread, JSTaggedValue(0));
997     jsQueue->SetFront(0);
998     jsQueue->SetTail(0);
999     jsQueue->SetElements(thread, newElements);
1000     JSHandle<JSTaggedValue> deQue = JSHandle<JSTaggedValue>::Cast(jsQueue);
1001     gettimeofday(&g_beginTime, nullptr);
1002     for (int i = 0; i < NUM_COUNT; i++) {
1003         (void)JSNApiHelper::ToLocal<JSValueRef>(deQue)->IsDeque(vm_);
1004     }
1005     gettimeofday(&g_endTime, nullptr);
1006     TEST_TIME(JSValueRef::IsDeque);
1007 }
1008 
HWTEST_F_L0(JSNApiSplTest,DataView_New)1009 HWTEST_F_L0(JSNApiSplTest, DataView_New)
1010 {
1011     LocalScope scope(vm_);
1012     CalculateForTime();
1013     const int32_t length = 15;
1014     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1015     gettimeofday(&g_beginTime, nullptr);
1016     for (int i = 0; i < NUM_COUNT; i++) {
1017         (void)DataViewRef::New(vm_, arrayBuffer, 5, 7);
1018     }
1019     gettimeofday(&g_endTime, nullptr);
1020     TEST_TIME(DataView::New);
1021 }
1022 
HWTEST_F_L0(JSNApiSplTest,DataView_ByteLength)1023 HWTEST_F_L0(JSNApiSplTest, DataView_ByteLength)
1024 {
1025     LocalScope scope(vm_);
1026     CalculateForTime();
1027     const int32_t length = 15;
1028     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1029     Local<DataViewRef> dataView = DataViewRef::New(vm_, arrayBuffer, 5, 7);
1030     gettimeofday(&g_beginTime, nullptr);
1031     for (int i = 0; i < NUM_COUNT; i++) {
1032         (void)dataView->ByteLength();
1033     }
1034     gettimeofday(&g_endTime, nullptr);
1035     TEST_TIME(DataView::ByteLength);
1036 }
1037 
HWTEST_F_L0(JSNApiSplTest,DataView_ByteOffset)1038 HWTEST_F_L0(JSNApiSplTest, DataView_ByteOffset)
1039 {
1040     LocalScope scope(vm_);
1041     CalculateForTime();
1042     const int32_t length = 15;
1043     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1044     Local<DataViewRef> dataView = DataViewRef::New(vm_, arrayBuffer, 5, 7);
1045     gettimeofday(&g_beginTime, nullptr);
1046     for (int i = 0; i < NUM_COUNT; i++) {
1047         (void)dataView->ByteOffset();
1048     }
1049     gettimeofday(&g_endTime, nullptr);
1050     TEST_TIME(DataView::ByteOffset);
1051 }
1052 
HWTEST_F_L0(JSNApiSplTest,DataView_GetArrayBuffer)1053 HWTEST_F_L0(JSNApiSplTest, DataView_GetArrayBuffer)
1054 {
1055     LocalScope scope(vm_);
1056     CalculateForTime();
1057     const int32_t length = 15;
1058     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1059     Local<DataViewRef> dataView = DataViewRef::New(vm_, arrayBuffer, 5, 7);
1060     gettimeofday(&g_beginTime, nullptr);
1061     for (int i = 0; i < NUM_COUNT; i++) {
1062         (void)dataView->GetArrayBuffer(vm_);
1063     }
1064     gettimeofday(&g_endTime, nullptr);
1065     TEST_TIME(DataView::GetArrayBuffer);
1066 }
1067 
HWTEST_F_L0(JSNApiSplTest,TypedArrayRef_ByteLength)1068 HWTEST_F_L0(JSNApiSplTest, TypedArrayRef_ByteLength)
1069 {
1070     LocalScope scope(vm_);
1071     CalculateForTime();
1072     const int32_t length = 15;
1073     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1074     Local<Int8ArrayRef> obj = Int8ArrayRef::New(vm_, arrayBuffer, 5, 6);
1075     gettimeofday(&g_beginTime, nullptr);
1076     for (int i = 0; i < NUM_COUNT; i++) {
1077         (void)obj->ByteLength(vm_);
1078     }
1079     gettimeofday(&g_endTime, nullptr);
1080     TEST_TIME(TypedArrayRef::ByteLength);
1081 }
1082 
HWTEST_F_L0(JSNApiSplTest,TypedArrayRef_ByteOffset)1083 HWTEST_F_L0(JSNApiSplTest, TypedArrayRef_ByteOffset)
1084 {
1085     LocalScope scope(vm_);
1086     CalculateForTime();
1087     const int32_t length = 15;
1088     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1089     Local<Int8ArrayRef> obj = Int8ArrayRef::New(vm_, arrayBuffer, 5, 6);
1090     gettimeofday(&g_beginTime, nullptr);
1091     for (int i = 0; i < NUM_COUNT; i++) {
1092         (void)obj->ByteOffset(vm_);
1093     }
1094     gettimeofday(&g_endTime, nullptr);
1095     TEST_TIME(TypedArrayRef::ByteOffset);
1096 }
1097 
HWTEST_F_L0(JSNApiSplTest,TypedArrayRef_ArrayLength)1098 HWTEST_F_L0(JSNApiSplTest, TypedArrayRef_ArrayLength)
1099 {
1100     LocalScope scope(vm_);
1101     CalculateForTime();
1102     const int32_t length = 15;
1103     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1104     Local<Int8ArrayRef> obj = Int8ArrayRef::New(vm_, arrayBuffer, 5, 6);
1105     gettimeofday(&g_beginTime, nullptr);
1106     for (int i = 0; i < NUM_COUNT; i++) {
1107         (void)obj->ArrayLength(vm_);
1108     }
1109     gettimeofday(&g_endTime, nullptr);
1110     TEST_TIME(TypedArrayRef::ArrayLength);
1111 }
1112 
HWTEST_F_L0(JSNApiSplTest,TypedArrayRef_GetArrayBuffer)1113 HWTEST_F_L0(JSNApiSplTest, TypedArrayRef_GetArrayBuffer)
1114 {
1115     LocalScope scope(vm_);
1116     CalculateForTime();
1117     const int32_t length = 15;
1118     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1119     Local<Int8ArrayRef> obj = Int8ArrayRef::New(vm_, arrayBuffer, 5, 6);
1120     gettimeofday(&g_beginTime, nullptr);
1121     for (int i = 0; i < NUM_COUNT; i++) {
1122         (void)obj->GetArrayBuffer(vm_);
1123     }
1124     gettimeofday(&g_endTime, nullptr);
1125     TEST_TIME(TypedArrayRef::GetArrayBuffer);
1126 }
1127 
HWTEST_F_L0(JSNApiSplTest,Int8ArrayRef_New)1128 HWTEST_F_L0(JSNApiSplTest, Int8ArrayRef_New)
1129 {
1130     LocalScope scope(vm_);
1131     CalculateForTime();
1132     const int32_t length = 15;
1133     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1134     gettimeofday(&g_beginTime, nullptr);
1135     for (int i = 0; i < NUM_COUNT; i++) {
1136         (void)Int8ArrayRef::New(vm_, arrayBuffer, 5, 6);
1137     }
1138     gettimeofday(&g_endTime, nullptr);
1139     TEST_TIME(Int8ArrayRef::New);
1140 }
1141 
HWTEST_F_L0(JSNApiSplTest,Uint8ArrayRef_New)1142 HWTEST_F_L0(JSNApiSplTest, Uint8ArrayRef_New)
1143 {
1144     LocalScope scope(vm_);
1145     CalculateForTime();
1146     const int32_t length = 15;
1147     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1148     gettimeofday(&g_beginTime, nullptr);
1149     for (int i = 0; i < NUM_COUNT; i++) {
1150         (void)Uint8ArrayRef::New(vm_, arrayBuffer, 5, 6);
1151     }
1152     gettimeofday(&g_endTime, nullptr);
1153     TEST_TIME(Uint8ArrayRef::New);
1154 }
1155 
HWTEST_F_L0(JSNApiSplTest,Uint8ClampedArrayRef_New)1156 HWTEST_F_L0(JSNApiSplTest, Uint8ClampedArrayRef_New)
1157 {
1158     LocalScope scope(vm_);
1159     CalculateForTime();
1160     const int32_t length = 15;
1161     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1162     gettimeofday(&g_beginTime, nullptr);
1163     for (int i = 0; i < NUM_COUNT; i++) {
1164         (void)Uint8ClampedArrayRef::New(vm_, arrayBuffer, 5, 6);
1165     }
1166     gettimeofday(&g_endTime, nullptr);
1167     TEST_TIME(Uint8ClampedArrayRef::New);
1168 }
1169 
HWTEST_F_L0(JSNApiSplTest,Int16ArrayRef_New)1170 HWTEST_F_L0(JSNApiSplTest, Int16ArrayRef_New)
1171 {
1172     LocalScope scope(vm_);
1173     CalculateForTime();
1174     const int32_t length = 15;
1175     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1176     gettimeofday(&g_beginTime, nullptr);
1177     for (int i = 0; i < NUM_COUNT; i++) {
1178         (void)Int16ArrayRef::New(vm_, arrayBuffer, 5, 6);
1179     }
1180     gettimeofday(&g_endTime, nullptr);
1181     TEST_TIME(Int16ArrayRef::New);
1182 }
1183 
HWTEST_F_L0(JSNApiSplTest,Uint16ArrayRef_New)1184 HWTEST_F_L0(JSNApiSplTest, Uint16ArrayRef_New)
1185 {
1186     LocalScope scope(vm_);
1187     CalculateForTime();
1188     const int32_t length = 15;
1189     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1190     gettimeofday(&g_beginTime, nullptr);
1191     for (int i = 0; i < NUM_COUNT; i++) {
1192         (void)Uint16ArrayRef::New(vm_, arrayBuffer, 5, 6);
1193     }
1194     gettimeofday(&g_endTime, nullptr);
1195     TEST_TIME(Uint16ArrayRef::New);
1196 }
1197 
HWTEST_F_L0(JSNApiSplTest,Int32ArrayRef_New)1198 HWTEST_F_L0(JSNApiSplTest, Int32ArrayRef_New)
1199 {
1200     LocalScope scope(vm_);
1201     CalculateForTime();
1202     const int32_t length = 15;
1203     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1204     gettimeofday(&g_beginTime, nullptr);
1205     for (int i = 0; i < NUM_COUNT; i++) {
1206         (void)Int32ArrayRef::New(vm_, arrayBuffer, 5, 6);
1207     }
1208     gettimeofday(&g_endTime, nullptr);
1209     TEST_TIME(Int32ArrayRef::New);
1210 }
1211 
HWTEST_F_L0(JSNApiSplTest,Uint32ArrayRef_New)1212 HWTEST_F_L0(JSNApiSplTest, Uint32ArrayRef_New)
1213 {
1214     LocalScope scope(vm_);
1215     CalculateForTime();
1216     const int32_t length = 15;
1217     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
1218     gettimeofday(&g_beginTime, nullptr);
1219     for (int i = 0; i < NUM_COUNT; i++) {
1220         (void)Uint32ArrayRef::New(vm_, arrayBuffer, 5, 6);
1221     }
1222     gettimeofday(&g_endTime, nullptr);
1223     TEST_TIME(Uint32ArrayRef::New);
1224 }
1225 
HWTEST_F_L0(JSNApiSplTest,BufferRef_BufferToStringCallback)1226 HWTEST_F_L0(JSNApiSplTest, BufferRef_BufferToStringCallback)
1227 {
1228     LocalScope scope(vm_);
1229     CalculateForTime();
1230     JSThread *thread = vm_->GetJSThread();
1231     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1232     JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
1233     JSHandle<JSArrayBuffer> arrayBuffer = factory->NewJSArrayBuffer(10);
1234     JSHandle<JSTaggedValue> arryListTag = JSHandle<JSTaggedValue>::Cast(arrayBuffer);
1235     EcmaRuntimeCallInfo *objCallInfo =
1236         EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, arryListTag, undefined, 1);
1237     gettimeofday(&g_beginTime, nullptr);
1238     for (int i = 0; i < NUM_COUNT; i++) {
1239         BufferRef::BufferToStringCallback(objCallInfo);
1240     }
1241     gettimeofday(&g_endTime, nullptr);
1242     TEST_TIME(BufferRef::BufferToStringCallback);
1243 }
1244 
ConstructobjectHashMap(const EcmaVM * vm_)1245 JSHandle<JSAPIHashMap> ConstructobjectHashMap(const EcmaVM *vm_)
1246 {
1247     JSThread *thread = vm_->GetJSThread();
1248     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1249     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
1250     JSHandle<JSTaggedValue> globalObject = env->GetJSGlobalObject();
1251     JSHandle<JSTaggedValue> key(factory->NewFromASCII("ArkPrivate"));
1252     JSHandle<JSTaggedValue> value =
1253         JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(globalObject), key).GetValue();
1254     auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1255     objCallInfo->SetFunction(JSTaggedValue::Undefined());
1256     objCallInfo->SetThis(value.GetTaggedValue());
1257     objCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int>(containers::ContainerTag::HashMap)));
1258     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo);
1259     JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo);
1260     TestHelper::TearDownFrame(thread, prev);
1261     JSHandle<JSTaggedValue> constructor(thread, result);
1262     JSHandle<JSAPIHashMap> map(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
1263     return map;
1264 }
1265 
ConstructobjectHashSet(const EcmaVM * vm_)1266 JSHandle<JSAPIHashSet> ConstructobjectHashSet(const EcmaVM *vm_)
1267 {
1268     JSThread *thread = vm_->GetJSThread();
1269     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1270     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
1271     JSHandle<JSTaggedValue> globalObject = env->GetJSGlobalObject();
1272     JSHandle<JSTaggedValue> key(factory->NewFromASCII("ArkPrivate"));
1273     JSHandle<JSTaggedValue> value =
1274         JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(globalObject), key).GetValue();
1275     auto objCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1276     objCallInfo1->SetFunction(JSTaggedValue::Undefined());
1277     objCallInfo1->SetThis(value.GetTaggedValue());
1278     objCallInfo1->SetCallArg(0, JSTaggedValue(static_cast<int>(containers::ContainerTag::HashSet)));
1279     [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, objCallInfo1);
1280     JSTaggedValue result1 = containers::ContainersPrivate::Load(objCallInfo1);
1281     JSHandle<JSFunction> newTarget(thread, result1);
1282     auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
1283     objCallInfo->SetFunction(newTarget.GetTaggedValue());
1284     objCallInfo->SetNewTarget(newTarget.GetTaggedValue());
1285     objCallInfo->SetThis(JSTaggedValue::Undefined());
1286     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo);
1287     JSTaggedValue result = ecmascript::containers::ContainersHashSet::HashSetConstructor(objCallInfo);
1288     TestHelper::TearDownFrame(thread, prev);
1289     JSHandle<JSAPIHashSet> setHandle(thread, result);
1290     return setHandle;
1291 }
1292 
ConstructobjectLightWeightMap(const EcmaVM * vm_)1293 JSHandle<JSAPILightWeightMap> ConstructobjectLightWeightMap(const EcmaVM *vm_)
1294 {
1295     JSThread *thread = vm_->GetJSThread();
1296     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1297     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
1298     JSHandle<JSTaggedValue> globalObject = env->GetJSGlobalObject();
1299     JSHandle<JSTaggedValue> key(factory->NewFromASCII("ArkPrivate"));
1300     JSHandle<JSTaggedValue> value =
1301         JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(globalObject), key).GetValue();
1302     auto objCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1303     objCallInfo1->SetFunction(JSTaggedValue::Undefined());
1304     objCallInfo1->SetThis(value.GetTaggedValue());
1305     objCallInfo1->SetCallArg(0, JSTaggedValue(static_cast<int>(containers::ContainerTag::LightWeightMap)));
1306     [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, objCallInfo1);
1307     JSTaggedValue result1 = ecmascript::containers::ContainersPrivate::Load(objCallInfo1);
1308     JSHandle<JSFunction> newTarget(thread, result1);
1309     auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
1310     objCallInfo->SetFunction(newTarget.GetTaggedValue());
1311     objCallInfo->SetNewTarget(newTarget.GetTaggedValue());
1312     objCallInfo->SetThis(JSTaggedValue::Undefined());
1313     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo);
1314     JSTaggedValue result = ecmascript::containers::ContainersLightWeightMap::LightWeightMapConstructor(objCallInfo);
1315     TestHelper::TearDownFrame(thread, prev);
1316     JSHandle<JSAPILightWeightMap> mapHandle(thread, result);
1317     return mapHandle;
1318 }
1319 
ConstructobjectLightWeightSet(const EcmaVM * vm_)1320 JSHandle<JSAPILightWeightSet> ConstructobjectLightWeightSet(const EcmaVM *vm_)
1321 {
1322     JSThread *thread = vm_->GetJSThread();
1323     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1324     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
1325     JSHandle<JSTaggedValue> globalObject = env->GetJSGlobalObject();
1326     JSHandle<JSTaggedValue> key(factory->NewFromASCII("ArkPrivate"));
1327     JSHandle<JSTaggedValue> value =
1328         JSObject::GetProperty(thread, JSHandle<JSTaggedValue>(globalObject), key).GetValue();
1329     auto objCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
1330     objCallInfo1->SetFunction(JSTaggedValue::Undefined());
1331     objCallInfo1->SetThis(value.GetTaggedValue());
1332     objCallInfo1->SetCallArg(0, JSTaggedValue(static_cast<int>(containers::ContainerTag::LightWeightSet)));
1333     [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, objCallInfo1);
1334     JSTaggedValue result1 = ecmascript::containers::ContainersPrivate::Load(objCallInfo1);
1335     JSHandle<JSFunction> newTarget(thread, result1);
1336     auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4);
1337     objCallInfo->SetFunction(newTarget.GetTaggedValue());
1338     objCallInfo->SetNewTarget(newTarget.GetTaggedValue());
1339     objCallInfo->SetThis(JSTaggedValue::Undefined());
1340     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo);
1341     JSTaggedValue result = ecmascript::containers::ContainersLightWeightSet::LightWeightSetConstructor(objCallInfo);
1342     TestHelper::TearDownFrame(thread, prev);
1343     JSHandle<JSAPILightWeightSet> mapHandle(thread, result);
1344     return mapHandle;
1345 }
1346 
HWTEST_F_L0(JSNApiSplTest,IsStringIterator)1347 HWTEST_F_L0(JSNApiSplTest, IsStringIterator)
1348 {
1349     LocalScope scope(vm_);
1350     CalculateForTime();
1351     JSHandle<EcmaString> recordName = vm_->GetFactory()->NewFromUtf8("646458");
1352     JSHandle<JSStringIterator> jsStringIter = JSStringIterator::CreateStringIterator(vm_->GetJSThread(), recordName);
1353     JSHandle<JSTaggedValue> setTag = JSHandle<JSTaggedValue>::Cast(jsStringIter);
1354     gettimeofday(&g_beginTime, nullptr);
1355     for (int i = 0; i < NUM_COUNT; i++) {
1356         JSNApiHelper::ToLocal<StringRef>(setTag)->IsStringIterator(vm_);
1357     }
1358     gettimeofday(&g_endTime, nullptr);
1359     TEST_TIME(JSValueRef::IsStringIterator);
1360     GTEST_LOG_(INFO) << std::boolalpha << JSNApiHelper::ToLocal<StringRef>(setTag)->IsStringIterator(vm_);
1361 }
1362 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsUint8Array)1363 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsUint8Array)
1364 {
1365     LocalScope scope(vm_);
1366     CalculateForTime();
1367     Local<ArrayBufferRef> buffer = ArrayBufferRef::New(vm_, 5);
1368     Local<Uint8ArrayRef> object = Uint8ArrayRef::New(vm_, buffer, 4, 5);
1369     gettimeofday(&g_beginTime, nullptr);
1370     for (int i = 0; i < NUM_COUNT; i++) {
1371         object->IsUint8Array(vm_);
1372     }
1373     gettimeofday(&g_endTime, nullptr);
1374     TEST_TIME(JSValueRef::IsUint8Array);
1375     GTEST_LOG_(INFO) << std::boolalpha << object->IsUint8Array(vm_);
1376 }
1377 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsInt8Array)1378 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt8Array)
1379 {
1380     LocalScope scope(vm_);
1381     CalculateForTime();
1382     Local<ArrayBufferRef> buffer = ArrayBufferRef::New(vm_, 5);
1383     Local<ObjectRef> object = Int8ArrayRef::New(vm_, buffer, 4, 5);
1384     gettimeofday(&g_beginTime, nullptr);
1385     for (int i = 0; i < NUM_COUNT; i++) {
1386         object->IsInt8Array(vm_);
1387     }
1388     gettimeofday(&g_endTime, nullptr);
1389     TEST_TIME(JSValueRef::IsInt8Array);
1390     GTEST_LOG_(INFO) << std::boolalpha << object->IsInt8Array(vm_);
1391 }
1392 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsBigInt64Array)1393 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBigInt64Array)
1394 {
1395     LocalScope scope(vm_);
1396     CalculateForTime();
1397     Local<ArrayBufferRef> buffer = ArrayBufferRef::New(vm_, 5);
1398     Local<ObjectRef> object = BigInt64ArrayRef::New(vm_, buffer, 4, 5);
1399     gettimeofday(&g_beginTime, nullptr);
1400     for (int i = 0; i < NUM_COUNT; i++) {
1401         object->IsBigInt64Array(vm_);
1402     }
1403     gettimeofday(&g_endTime, nullptr);
1404     TEST_TIME(JSValueRef::IsBigInt64Array);
1405     GTEST_LOG_(INFO) << std::boolalpha << object->IsBigInt64Array(vm_);
1406 }
1407 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsBigUint64Array)1408 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBigUint64Array)
1409 {
1410     LocalScope scope(vm_);
1411     CalculateForTime();
1412     Local<ArrayBufferRef> buffer = ArrayBufferRef::New(vm_, 5);
1413     Local<ObjectRef> object = BigUint64ArrayRef::New(vm_, buffer, 4, 5);
1414     gettimeofday(&g_beginTime, nullptr);
1415     for (int i = 0; i < NUM_COUNT; i++) {
1416         object->IsBigUint64Array(vm_);
1417     }
1418     gettimeofday(&g_endTime, nullptr);
1419     TEST_TIME(JSValueRef::IsBigUint64Array);
1420     GTEST_LOG_(INFO) << std::boolalpha << object->IsBigUint64Array(vm_);
1421 }
1422 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSPrimitiveRef)1423 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPrimitiveRef)
1424 {
1425     LocalScope scope(vm_);
1426     CalculateForTime();
1427     auto factory = vm_->GetFactory();
1428     int num = 0;
1429     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
1430     EXPECT_EQ(intValue->Value(), num);
1431     Local<JSValueRef> jsValue = intValue->GetValue(vm_);
1432     EXPECT_TRUE(*jsValue == nullptr);
1433     JSHandle<JSTaggedValue> nullHandle(thread_, JSTaggedValue::Null());
1434     JSHandle<JSHClass> jsClassHandle = factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_PRIMITIVE_REF, nullHandle);
1435     TaggedObject *taggedObject = factory->NewObject(jsClassHandle);
1436     JSHandle<JSTaggedValue> jsTaggedValue(thread_, JSTaggedValue(taggedObject));
1437     Local<PrimitiveRef> jsValueRef = JSNApiHelper::ToLocal<JSPrimitiveRef>(jsTaggedValue);
1438     gettimeofday(&g_beginTime, nullptr);
1439     for (int i = 0; i < NUM_COUNT; i++) {
1440         jsValueRef->IsJSPrimitiveRef(vm_);
1441     }
1442     gettimeofday(&g_endTime, nullptr);
1443     TEST_TIME(JSValueRef::IsJSPrimitiveRef);
1444     GTEST_LOG_(INFO) << std::boolalpha << jsValueRef->IsJSPrimitiveRef(vm_);
1445 }
1446 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSDateTimeFormat)1447 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSDateTimeFormat)
1448 {
1449     LocalScope scope(vm_);
1450     CalculateForTime();
1451     auto factory = vm_->GetFactory();
1452     int num = 0;
1453     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
1454     EXPECT_EQ(intValue->Value(), num);
1455     Local<JSValueRef> jsValue = intValue->GetValue(vm_);
1456     EXPECT_TRUE(*jsValue == nullptr);
1457     JSHandle<JSTaggedValue> nullHandle(thread_, JSTaggedValue::Null());
1458     JSHandle<JSHClass> jsClassHandle = factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_DATE_TIME_FORMAT, nullHandle);
1459     TaggedObject *taggedObject = factory->NewObject(jsClassHandle);
1460     JSHandle<JSTaggedValue> jsTaggedValue(thread_, JSTaggedValue(taggedObject));
1461     gettimeofday(&g_beginTime, nullptr);
1462     for (int i = 0; i < NUM_COUNT; i++) {
1463         JSNApiHelper::ToLocal<JSValueRef>(jsTaggedValue)->IsJSDateTimeFormat(vm_);
1464     }
1465     gettimeofday(&g_endTime, nullptr);
1466     TEST_TIME(JSValueRef::IsJSDateTimeFormat);
1467     GTEST_LOG_(INFO) << std::boolalpha << JSNApiHelper::ToLocal<JSValueRef>(jsTaggedValue)->IsJSDateTimeFormat(vm_);
1468 }
1469 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSRelativeTimeFormat)1470 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSRelativeTimeFormat)
1471 {
1472     LocalScope scope(vm_);
1473     CalculateForTime();
1474     auto factory = vm_->GetFactory();
1475     Local<IntegerRef> intValue = IntegerRef::New(vm_, 0);
1476     EXPECT_EQ(intValue->Value(), 0);
1477     Local<JSValueRef> jsValue = intValue->GetValue(vm_);
1478     EXPECT_TRUE(*jsValue == nullptr);
1479     JSHandle<JSTaggedValue> nullHandle(thread_, JSTaggedValue::Null());
1480     JSHandle<JSHClass> jsClassHandle =
1481         factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_RELATIVE_TIME_FORMAT, nullHandle);
1482     TaggedObject *taggedObject = factory->NewObject(jsClassHandle);
1483     JSHandle<JSTaggedValue> jsTaggedValue(thread_, JSTaggedValue(taggedObject));
1484     gettimeofday(&g_beginTime, nullptr);
1485     for (int i = 0; i < NUM_COUNT; i++) {
1486         JSNApiHelper::ToLocal<JSValueRef>(jsTaggedValue)->IsJSRelativeTimeFormat(vm_);
1487     }
1488     gettimeofday(&g_endTime, nullptr);
1489     TEST_TIME(JSValueRef::IsJSRelativeTimeFormat);
1490     GTEST_LOG_(INFO) << std::boolalpha <<
1491         JSNApiHelper::ToLocal<JSValueRef>(jsTaggedValue)->IsJSRelativeTimeFormat(vm_);
1492 }
1493 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSIntl)1494 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSIntl)
1495 {
1496     LocalScope scope(vm_);
1497     CalculateForTime();
1498     auto factory = vm_->GetFactory();
1499     Local<IntegerRef> intValue = IntegerRef::New(vm_, 0);
1500     EXPECT_EQ(intValue->Value(), 0);
1501     Local<JSValueRef> jsValue = intValue->GetValue(vm_);
1502     EXPECT_TRUE(*jsValue == nullptr);
1503     JSHandle<JSTaggedValue> nullHandle(thread_, JSTaggedValue::Null());
1504     JSHandle<JSHClass> jsClassHandle = factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_INTL, nullHandle);
1505     TaggedObject *taggedObject = factory->NewObject(jsClassHandle);
1506     JSHandle<JSTaggedValue> jsTaggedValue(thread_, JSTaggedValue(taggedObject));
1507     gettimeofday(&g_beginTime, nullptr);
1508     for (int i = 0; i < NUM_COUNT; i++) {
1509         JSNApiHelper::ToLocal<JSValueRef>(jsTaggedValue)->IsJSIntl(vm_);
1510     }
1511     gettimeofday(&g_endTime, nullptr);
1512     TEST_TIME(JSValueRef::IsJSIntl);
1513     GTEST_LOG_(INFO) << std::boolalpha << JSNApiHelper::ToLocal<JSValueRef>(jsTaggedValue)->IsJSIntl(vm_);
1514 }
1515 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSNumberFormat)1516 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSNumberFormat)
1517 {
1518     LocalScope scope(vm_);
1519     CalculateForTime();
1520     auto factory = vm_->GetFactory();
1521     Local<IntegerRef> intValue = IntegerRef::New(vm_, 0);
1522     EXPECT_EQ(intValue->Value(), 0);
1523     Local<JSValueRef> jsValue = intValue->GetValue(vm_);
1524     EXPECT_TRUE(*jsValue == nullptr);
1525     JSHandle<JSTaggedValue> nullHandle(thread_, JSTaggedValue::Null());
1526     JSHandle<JSHClass> jsClassHandle = factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_NUMBER_FORMAT, nullHandle);
1527     TaggedObject *taggedObject = factory->NewObject(jsClassHandle);
1528     JSHandle<JSTaggedValue> jsTaggedValue(thread_, JSTaggedValue(taggedObject));
1529     gettimeofday(&g_beginTime, nullptr);
1530     for (int i = 0; i < NUM_COUNT; i++) {
1531         JSNApiHelper::ToLocal<JSValueRef>(jsTaggedValue)->IsJSNumberFormat(vm_);
1532     }
1533     gettimeofday(&g_endTime, nullptr);
1534     TEST_TIME(JSValueRef::IsJSNumberFormat);
1535     GTEST_LOG_(INFO) << std::boolalpha << JSNApiHelper::ToLocal<JSValueRef>(jsTaggedValue)->IsJSNumberFormat(vm_);
1536 }
1537 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsHashMap)1538 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsHashMap)
1539 {
1540     LocalScope scope(vm_);
1541     CalculateForTime();
1542     JSHandle<JSAPIHashMap> map = ConstructobjectHashMap(vm_);
1543     JSHandle<JSTaggedValue> jsHashMap = JSHandle<JSTaggedValue>::Cast(map);
1544     Local<JSValueRef> tag = JSNApiHelper::ToLocal<JSValueRef>(jsHashMap);
1545     gettimeofday(&g_beginTime, nullptr);
1546     for (int i = 0; i < NUM_COUNT; i++) {
1547         ASSERT_TRUE(tag->IsHashMap(vm_));
1548     }
1549     gettimeofday(&g_endTime, nullptr);
1550     TEST_TIME(JSValueRef::IsHashMap);
1551 }
1552 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsHashSet)1553 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsHashSet)
1554 {
1555     LocalScope scope(vm_);
1556     CalculateForTime();
1557     JSHandle<JSAPIHashSet> setHandle = ConstructobjectHashSet(vm_);
1558     JSHandle<JSTaggedValue> jsHashMap = JSHandle<JSTaggedValue>::Cast(setHandle);
1559     Local<JSValueRef> tag = JSNApiHelper::ToLocal<JSValueRef>(jsHashMap);
1560     gettimeofday(&g_beginTime, nullptr);
1561     for (int i = 0; i < NUM_COUNT; i++) {
1562         ASSERT_TRUE(tag->IsHashSet(vm_));
1563     }
1564     gettimeofday(&g_endTime, nullptr);
1565     TEST_TIME(JSValueRef::IsHashSet);
1566 }
1567 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsLightWeightMap)1568 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsLightWeightMap)
1569 {
1570     LocalScope scope(vm_);
1571     CalculateForTime();
1572     JSHandle<JSAPILightWeightMap> mapHandle = ConstructobjectLightWeightMap(vm_);
1573     JSHandle<JSTaggedValue> jsHashMap = JSHandle<JSTaggedValue>::Cast(mapHandle);
1574     Local<JSValueRef> tag = JSNApiHelper::ToLocal<JSValueRef>(jsHashMap);
1575     gettimeofday(&g_beginTime, nullptr);
1576     for (int i = 0; i < NUM_COUNT; i++) {
1577         ASSERT_TRUE(tag->IsLightWeightMap(vm_));
1578     }
1579     gettimeofday(&g_endTime, nullptr);
1580     TEST_TIME(JSValueRef::IsLightWeightMap);
1581 }
1582 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsLightWeightSet)1583 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsLightWeightSet)
1584 {
1585     LocalScope scope(vm_);
1586     CalculateForTime();
1587     JSHandle<JSAPILightWeightSet> mapHandle = ConstructobjectLightWeightSet(vm_);
1588     JSHandle<JSTaggedValue> jsHashMap = JSHandle<JSTaggedValue>::Cast(mapHandle);
1589     Local<JSValueRef> tag = JSNApiHelper::ToLocal<JSValueRef>(jsHashMap);
1590     gettimeofday(&g_beginTime, nullptr);
1591     for (int i = 0; i < NUM_COUNT; i++) {
1592         ASSERT_TRUE(tag->IsLightWeightSet(vm_));
1593     }
1594     gettimeofday(&g_endTime, nullptr);
1595     TEST_TIME(JSValueRef::IsLightWeightSet);
1596 }
1597 
HWTEST_F_L0(JSNApiSplTest,PropertyAttribute_Default)1598 HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_Default)
1599 {
1600     LocalScope scope(vm_);
1601     CalculateForTime();
1602     Local<JSValueRef> value = ObjectRef::New(vm_);
1603     PropertyAttribute object(value, true, true, true);
1604     gettimeofday(&g_beginTime, nullptr);
1605     for (int i = 0; i < NUM_COUNT; i++) {
1606         object.Default();
1607     }
1608     gettimeofday(&g_endTime, nullptr);
1609     TEST_TIME(PropertyAttribute::Default);
1610 }
1611 
HWTEST_F_L0(JSNApiSplTest,PropertyAttribute_PropertyAttribute)1612 HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_PropertyAttribute)
1613 {
1614     LocalScope scope(vm_);
1615     CalculateForTime();
1616     gettimeofday(&g_beginTime, nullptr);
1617     for (int i = 0; i < NUM_COUNT; i++) {
1618         PropertyAttribute *p = new PropertyAttribute();
1619         delete p;
1620     }
1621     gettimeofday(&g_endTime, nullptr);
1622     TEST_TIME(PropertyAttribute::PropertyAttribute);
1623 }
1624 
HWTEST_F_L0(JSNApiSplTest,PropertyAttribute_PropertyAttribute1)1625 HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_PropertyAttribute1)
1626 {
1627     LocalScope scope(vm_);
1628     CalculateForTime();
1629     Local<JSValueRef> value = ObjectRef::New(vm_);
1630     gettimeofday(&g_beginTime, nullptr);
1631     for (int i = 0; i < NUM_COUNT; i++) {
1632         PropertyAttribute *p = new PropertyAttribute(value, true, true, true);
1633         delete p;
1634     }
1635     gettimeofday(&g_endTime, nullptr);
1636     TEST_TIME(PropertyAttribute::PropertyAttribute);
1637 }
1638 
HWTEST_F_L0(JSNApiSplTest,PropertyAttribute_IsWritable)1639 HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_IsWritable)
1640 {
1641     LocalScope scope(vm_);
1642     CalculateForTime();
1643     Local<JSValueRef> value = ObjectRef::New(vm_);
1644     PropertyAttribute object(value, true, true, true);
1645     ASSERT_EQ(true, object.IsWritable());
1646     gettimeofday(&g_beginTime, nullptr);
1647     for (int i = 0; i < NUM_COUNT; i++) {
1648         bool b = object.IsWritable();
1649         UNUSED(b);
1650     }
1651     gettimeofday(&g_endTime, nullptr);
1652     TEST_TIME(PropertyAttribute::IsWritable);
1653 }
1654 
HWTEST_F_L0(JSNApiSplTest,PropertyAttribute_SetWritable)1655 HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_SetWritable)
1656 {
1657     LocalScope scope(vm_);
1658     CalculateForTime();
1659     Local<JSValueRef> value = ObjectRef::New(vm_);
1660     PropertyAttribute object(value, false, true, true);
1661     gettimeofday(&g_beginTime, nullptr);
1662     for (int i = 0; i < NUM_COUNT; i++) {
1663         object.SetWritable(true);
1664         bool b = object.IsWritable();
1665         bool b1 = object.HasWritable();
1666         UNUSED(b);
1667         UNUSED(b1);
1668     }
1669     gettimeofday(&g_endTime, nullptr);
1670     TEST_TIME(PropertyAttribute::SetWritable);
1671 }
1672 
HWTEST_F_L0(JSNApiSplTest,PropertyAttribute_IsEnumerable)1673 HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_IsEnumerable)
1674 {
1675     LocalScope scope(vm_);
1676     CalculateForTime();
1677     Local<JSValueRef> value = ObjectRef::New(vm_);
1678     PropertyAttribute object(value, true, true, true);
1679     ASSERT_EQ(true, object.IsEnumerable());
1680     gettimeofday(&g_beginTime, nullptr);
1681     for (int i = 0; i < NUM_COUNT; i++) {
1682         bool b = object.IsEnumerable();
1683         UNUSED(b);
1684     }
1685     gettimeofday(&g_endTime, nullptr);
1686     TEST_TIME(PropertyAttribute::IsEnumerable);
1687 }
1688 
HWTEST_F_L0(JSNApiSplTest,PropertyAttribute_SetEnumerable)1689 HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_SetEnumerable)
1690 {
1691     LocalScope scope(vm_);
1692     CalculateForTime();
1693     Local<JSValueRef> value = ObjectRef::New(vm_);
1694     PropertyAttribute object(value, true, false, true);
1695     gettimeofday(&g_beginTime, nullptr);
1696     for (int i = 0; i < NUM_COUNT; i++) {
1697         object.SetEnumerable(true);
1698         bool b = object.IsEnumerable();
1699         bool b1 = object.HasEnumerable();
1700         UNUSED(b);
1701         UNUSED(b1);
1702     }
1703     gettimeofday(&g_endTime, nullptr);
1704     TEST_TIME(PropertyAttribute::SetEnumerable);
1705 }
1706 
HWTEST_F_L0(JSNApiSplTest,PropertyAttribute_IsConfigurable)1707 HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_IsConfigurable)
1708 {
1709     LocalScope scope(vm_);
1710     CalculateForTime();
1711     Local<JSValueRef> value = ObjectRef::New(vm_);
1712     PropertyAttribute object(value, true, true, true);
1713     ASSERT_EQ(true, object.IsConfigurable());
1714     gettimeofday(&g_beginTime, nullptr);
1715     for (int i = 0; i < NUM_COUNT; i++) {
1716         bool b = object.IsConfigurable();
1717         UNUSED(b);
1718     }
1719     gettimeofday(&g_endTime, nullptr);
1720     TEST_TIME(PropertyAttribute::IsConfigurable);
1721 }
1722 
HWTEST_F_L0(JSNApiSplTest,PropertyAttribute_SetConfigurable)1723 HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_SetConfigurable)
1724 {
1725     LocalScope scope(vm_);
1726     CalculateForTime();
1727     Local<JSValueRef> value = ObjectRef::New(vm_);
1728     PropertyAttribute object(value, true, true, false);
1729     gettimeofday(&g_beginTime, nullptr);
1730     for (int i = 0; i < NUM_COUNT; i++) {
1731         object.SetConfigurable(true);
1732         bool b = object.IsConfigurable();
1733         bool b1 = object.HasConfigurable();
1734         UNUSED(b);
1735         UNUSED(b1);
1736     }
1737     gettimeofday(&g_endTime, nullptr);
1738     TEST_TIME(PropertyAttribute::SetConfigurable);
1739 }
1740 
HWTEST_F_L0(JSNApiSplTest,HasWritable_True)1741 HWTEST_F_L0(JSNApiSplTest, HasWritable_True)
1742 {
1743     LocalScope scope(vm_);
1744     CalculateForTime();
1745     Local<JSValueRef> value = ObjectRef::New(vm_);
1746     PropertyAttribute object(value, true, true, true);
1747     gettimeofday(&g_beginTime, nullptr);
1748     for (int i = 0; i < NUM_COUNT; i++) {
1749         bool b = object.HasWritable();
1750         UNUSED(b);
1751     }
1752     gettimeofday(&g_endTime, nullptr);
1753     TEST_TIME(PropertyAttribute::HasWritable);
1754 }
1755 
HWTEST_F_L0(JSNApiSplTest,HasConfigurable_False)1756 HWTEST_F_L0(JSNApiSplTest, HasConfigurable_False)
1757 {
1758     LocalScope scope(vm_);
1759     CalculateForTime();
1760     Local<PropertyAttribute> obj;
1761     gettimeofday(&g_beginTime, nullptr);
1762     for (int i = 0; i < NUM_COUNT; i++) {
1763         bool b = obj->HasConfigurable();
1764         UNUSED(b);
1765     }
1766     gettimeofday(&g_endTime, nullptr);
1767     TEST_TIME(PropertyAttribute::HasConfigurable);
1768 }
1769 
HWTEST_F_L0(JSNApiSplTest,HasEnumerable_True)1770 HWTEST_F_L0(JSNApiSplTest, HasEnumerable_True)
1771 {
1772     LocalScope scope(vm_);
1773     CalculateForTime();
1774     Local<JSValueRef> value = ObjectRef::New(vm_);
1775     PropertyAttribute object(value, true, true, true);
1776     gettimeofday(&g_beginTime, nullptr);
1777     for (int i = 0; i < NUM_COUNT; i++) {
1778         bool b = object.HasEnumerable();
1779         UNUSED(b);
1780     }
1781     gettimeofday(&g_endTime, nullptr);
1782     TEST_TIME(PropertyAttribute::HasEnumerable);
1783 }
1784 
HWTEST_F_L0(JSNApiSplTest,GetValue)1785 HWTEST_F_L0(JSNApiSplTest, GetValue)
1786 {
1787     LocalScope scope(vm_);
1788     CalculateForTime();
1789     Local<JSValueRef> value = ObjectRef::New(vm_);
1790     PropertyAttribute object(value, true, true, true);
1791     gettimeofday(&g_beginTime, nullptr);
1792     for (int i = 0; i < NUM_COUNT; i++) {
1793         object.GetValue(vm_);
1794     }
1795     gettimeofday(&g_endTime, nullptr);
1796     TEST_TIME(PropertyAttribute::GetValue);
1797 }
1798 
HWTEST_F_L0(JSNApiSplTest,SetValue)1799 HWTEST_F_L0(JSNApiSplTest, SetValue)
1800 {
1801     LocalScope scope(vm_);
1802     CalculateForTime();
1803     Local<JSValueRef> value = ObjectRef::New(vm_);
1804     PropertyAttribute object;
1805     gettimeofday(&g_beginTime, nullptr);
1806     for (int i = 0; i < NUM_COUNT; i++) {
1807         object.SetValue(value);
1808     }
1809     gettimeofday(&g_endTime, nullptr);
1810     TEST_TIME(PropertyAttribute::SetValue);
1811 }
1812 
HWTEST_F_L0(JSNApiSplTest,PropertyAttribute_HasValue)1813 HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_HasValue)
1814 {
1815     LocalScope scope(vm_);
1816     CalculateForTime();
1817     Local<JSValueRef> value = ObjectRef::New(vm_);
1818     PropertyAttribute object(value, true, true, true);
1819     gettimeofday(&g_beginTime, nullptr);
1820     for (int i = 0; i < NUM_COUNT; i++) {
1821         (void)object.HasValue();
1822     }
1823     gettimeofday(&g_endTime, nullptr);
1824     TEST_TIME(PropertyAttribute::HasValue);
1825 }
1826 
HWTEST_F_L0(JSNApiSplTest,PropertyAttribute_SetGetter)1827 HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_SetGetter)
1828 {
1829     LocalScope scope(vm_);
1830     CalculateForTime();
1831     Local<JSValueRef> value = ObjectRef::New(vm_);
1832     PropertyAttribute object;
1833     gettimeofday(&g_beginTime, nullptr);
1834     for (int i = 0; i < NUM_COUNT; i++) {
1835         object.SetGetter(value);
1836     }
1837     gettimeofday(&g_endTime, nullptr);
1838     TEST_TIME(PropertyAttribute::SetGetter);
1839 }
1840 
HWTEST_F_L0(JSNApiSplTest,PropertyAttribute_GetGetter)1841 HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_GetGetter)
1842 {
1843     LocalScope scope(vm_);
1844     CalculateForTime();
1845     Local<JSValueRef> value = BooleanRef::New(vm_, true);
1846     PropertyAttribute object;
1847     object.SetGetter(value);
1848     gettimeofday(&g_beginTime, nullptr);
1849     for (int i = 0; i < NUM_COUNT; i++) {
1850         (void)object.GetGetter(vm_);
1851     }
1852     gettimeofday(&g_endTime, nullptr);
1853     TEST_TIME(PropertyAttribute::GetGetter);
1854 }
1855 
HWTEST_F_L0(JSNApiSplTest,HasGetter)1856 HWTEST_F_L0(JSNApiSplTest, HasGetter)
1857 {
1858     LocalScope scope(vm_);
1859     CalculateForTime();
1860     Local<JSValueRef> value = ObjectRef::New(vm_);
1861     PropertyAttribute object;
1862     object.SetGetter(value);
1863     gettimeofday(&g_beginTime, nullptr);
1864     for (int i = 0; i < NUM_COUNT; i++) {
1865         object.HasGetter();
1866     }
1867     gettimeofday(&g_endTime, nullptr);
1868     TEST_TIME(PropertyAttribute::HasGetter);
1869 }
1870 
HWTEST_F_L0(JSNApiSplTest,SetSetter)1871 HWTEST_F_L0(JSNApiSplTest, SetSetter)
1872 {
1873     LocalScope scope(vm_);
1874     CalculateForTime();
1875     Local<JSValueRef> value = ObjectRef::New(vm_);
1876     PropertyAttribute object;
1877     gettimeofday(&g_beginTime, nullptr);
1878     for (int i = 0; i < NUM_COUNT; i++) {
1879         object.SetSetter(value);
1880     }
1881     gettimeofday(&g_endTime, nullptr);
1882     TEST_TIME(PropertyAttribute::SetSetter);
1883 }
1884 
HWTEST_F_L0(JSNApiSplTest,GetSetter)1885 HWTEST_F_L0(JSNApiSplTest, GetSetter)
1886 {
1887     LocalScope scope(vm_);
1888     CalculateForTime();
1889     Local<JSValueRef> value = ObjectRef::New(vm_);
1890     PropertyAttribute object;
1891     object.SetSetter(value);
1892     gettimeofday(&g_beginTime, nullptr);
1893     for (int i = 0; i < NUM_COUNT; i++) {
1894         object.GetSetter(vm_);
1895     }
1896     gettimeofday(&g_endTime, nullptr);
1897     TEST_TIME(PropertyAttribute::GetSetter);
1898 }
1899 
HWTEST_F_L0(JSNApiSplTest,HasSetter)1900 HWTEST_F_L0(JSNApiSplTest, HasSetter)
1901 {
1902     LocalScope scope(vm_);
1903     CalculateForTime();
1904     Local<JSValueRef> value = ObjectRef::New(vm_);
1905     PropertyAttribute object;
1906     object.SetGetter(value);
1907     gettimeofday(&g_beginTime, nullptr);
1908     for (int i = 0; i < NUM_COUNT; i++) {
1909         object.HasSetter();
1910     }
1911     gettimeofday(&g_endTime, nullptr);
1912     TEST_TIME(PropertyAttribute::HasSetter);
1913 }
1914 
HWTEST_F_L0(JSNApiSplTest,Float32ArrayRef_New)1915 HWTEST_F_L0(JSNApiSplTest, Float32ArrayRef_New)
1916 {
1917     LocalScope scope(vm_);
1918     CalculateForTime();
1919     int32_t num = 4;
1920     Local<ArrayBufferRef> buffer = ArrayBufferRef::New(vm_, num);
1921     int32_t byteOffset = 4;
1922     int32_t length = 20;
1923     gettimeofday(&g_beginTime, nullptr);
1924     for (int i = 0; i < NUM_COUNT; i++) {
1925         Float32ArrayRef::New(vm_, buffer, byteOffset, length);
1926     }
1927     gettimeofday(&g_endTime, nullptr);
1928     TEST_TIME(Float32ArrayRef::New);
1929 }
1930 
HWTEST_F_L0(JSNApiSplTest,Float64ArrayRef_New)1931 HWTEST_F_L0(JSNApiSplTest, Float64ArrayRef_New)
1932 {
1933     LocalScope scope(vm_);
1934     CalculateForTime();
1935     int32_t num = 4;
1936     Local<ArrayBufferRef> buffer = ArrayBufferRef::New(vm_, num);
1937     int32_t byteOffset = 4;
1938     int32_t length = 20;
1939     gettimeofday(&g_beginTime, nullptr);
1940     for (int i = 0; i < NUM_COUNT; i++) {
1941         Float64ArrayRef::New(vm_, buffer, byteOffset, length);
1942     }
1943     gettimeofday(&g_endTime, nullptr);
1944     TEST_TIME(Float64ArrayRef::New);
1945 }
1946 
HWTEST_F_L0(JSNApiSplTest,BigInt64ArrayRef_New)1947 HWTEST_F_L0(JSNApiSplTest, BigInt64ArrayRef_New)
1948 {
1949     LocalScope scope(vm_);
1950     CalculateForTime();
1951     int32_t num = 4;
1952     Local<ArrayBufferRef> buffer = ArrayBufferRef::New(vm_, num);
1953     int32_t byteOffset = 4;
1954     int32_t length = 20;
1955     gettimeofday(&g_beginTime, nullptr);
1956     for (int i = 0; i < NUM_COUNT; i++) {
1957         BigInt64ArrayRef::New(vm_, buffer, byteOffset, length);
1958     }
1959     gettimeofday(&g_endTime, nullptr);
1960     TEST_TIME(BigInt64ArrayRef::New);
1961 }
1962 
HWTEST_F_L0(JSNApiSplTest,BigUint64ArrayRef_New)1963 HWTEST_F_L0(JSNApiSplTest, BigUint64ArrayRef_New)
1964 {
1965     LocalScope scope(vm_);
1966     CalculateForTime();
1967     int32_t num = 4;
1968     Local<ArrayBufferRef> buffer = ArrayBufferRef::New(vm_, num);
1969     int32_t byteOffset = 4;
1970     int32_t length = 20;
1971     gettimeofday(&g_beginTime, nullptr);
1972     for (int i = 0; i < NUM_COUNT; i++) {
1973         BigUint64ArrayRef::New(vm_, buffer, byteOffset, length);
1974     }
1975     gettimeofday(&g_endTime, nullptr);
1976     TEST_TIME(BigUint64ArrayRef::New);
1977 }
1978 
HWTEST_F_L0(JSNApiSplTest,GetOriginalSource)1979 HWTEST_F_L0(JSNApiSplTest, GetOriginalSource)
1980 {
1981     LocalScope scope(vm_);
1982     CalculateForTime();
1983     JSThread *thread = vm_->GetJSThread();
1984     ObjectFactory *factory = vm_->GetFactory();
1985     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
1986     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
1987     JSHandle<JSHClass> jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto);
1988     JSHandle<JSRegExp> jSRegExp = JSHandle<JSRegExp>::Cast(factory->NewJSObject(jSRegExpClass));
1989     jSRegExp->SetByteCodeBuffer(thread, JSTaggedValue::Undefined());
1990     jSRegExp->SetOriginalSource(thread, JSTaggedValue::Undefined());
1991     jSRegExp->SetGroupName(thread, JSTaggedValue::Undefined());
1992     jSRegExp->SetOriginalFlags(thread, JSTaggedValue(0));
1993     jSRegExp->SetLength(0);
1994     JSHandle<JSTaggedValue> jsRegTag = JSHandle<JSTaggedValue>::Cast(jSRegExp);
1995     Local<RegExpRef> object = JSNApiHelper::ToLocal<RegExpRef>(jsRegTag);
1996     gettimeofday(&g_beginTime, nullptr);
1997     for (int i = 0; i < NUM_COUNT; i++) {
1998         object->GetOriginalSource(vm_);
1999     }
2000     gettimeofday(&g_endTime, nullptr);
2001     TEST_TIME(RegExpRef::GetOriginalSource);
2002 }
2003 
HWTEST_F_L0(JSNApiSplTest,GetOriginalFlags)2004 HWTEST_F_L0(JSNApiSplTest, GetOriginalFlags)
2005 {
2006     LocalScope scope(vm_);
2007     CalculateForTime();
2008     JSThread *thread = vm_->GetJSThread();
2009     ObjectFactory *factory = vm_->GetFactory();
2010     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
2011     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
2012     JSHandle<JSHClass> jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto);
2013     JSHandle<JSRegExp> jSRegExp = JSHandle<JSRegExp>::Cast(factory->NewJSObject(jSRegExpClass));
2014     jSRegExp->SetByteCodeBuffer(thread, JSTaggedValue::Undefined());
2015     jSRegExp->SetOriginalSource(thread, JSTaggedValue::Undefined());
2016     jSRegExp->SetGroupName(thread, JSTaggedValue::Undefined());
2017     jSRegExp->SetOriginalFlags(thread, JSTaggedValue(0));
2018     jSRegExp->SetLength(0);
2019     JSHandle<JSTaggedValue> jsRegTag = JSHandle<JSTaggedValue>::Cast(jSRegExp);
2020     Local<RegExpRef> object = JSNApiHelper::ToLocal<RegExpRef>(jsRegTag);
2021     gettimeofday(&g_beginTime, nullptr);
2022     for (int i = 0; i < NUM_COUNT; i++) {
2023         object->GetOriginalFlags(vm_);
2024     }
2025     gettimeofday(&g_endTime, nullptr);
2026     TEST_TIME(RegExpRef::GetOriginalFlags);
2027 }
2028 
HWTEST_F_L0(JSNApiSplTest,IsGlobal)2029 HWTEST_F_L0(JSNApiSplTest, IsGlobal)
2030 {
2031     LocalScope scope(vm_);
2032     CalculateForTime();
2033     JSThread *thread = vm_->GetJSThread();
2034     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
2035     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
2036     JSHandle<JSGlobalObject> globalObject = JSHandle<JSGlobalObject>::Cast(proto);
2037     JSHandle<JSTaggedValue> jsRegTag = JSHandle<JSTaggedValue>::Cast(globalObject);
2038     Local<RegExpRef> object = JSNApiHelper::ToLocal<RegExpRef>(jsRegTag);
2039     gettimeofday(&g_beginTime, nullptr);
2040     for (int i = 0; i < NUM_COUNT; i++) {
2041         object->IsGlobal(vm_);
2042     }
2043     gettimeofday(&g_endTime, nullptr);
2044     TEST_TIME(RegExpRef::IsGlobal);
2045 }
2046 
HWTEST_F_L0(JSNApiSplTest,IsIgnoreCase)2047 HWTEST_F_L0(JSNApiSplTest, IsIgnoreCase)
2048 {
2049     LocalScope scope(vm_);
2050     CalculateForTime();
2051     JSThread *thread = vm_->GetJSThread();
2052     ObjectFactory *factory = vm_->GetFactory();
2053     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
2054     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
2055     JSHandle<JSHClass> jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto);
2056     JSHandle<JSRegExp> jSRegExp = JSHandle<JSRegExp>::Cast(factory->NewJSObject(jSRegExpClass));
2057     JSHandle<JSTaggedValue> jsRegTag = JSHandle<JSTaggedValue>::Cast(jSRegExp);
2058     Local<RegExpRef> object = JSNApiHelper::ToLocal<RegExpRef>(jsRegTag);
2059     gettimeofday(&g_beginTime, nullptr);
2060     for (int i = 0; i < NUM_COUNT; i++) {
2061         object->IsIgnoreCase(vm_);
2062     }
2063     gettimeofday(&g_endTime, nullptr);
2064     TEST_TIME(RegExpRef::IsIgnoreCase);
2065 }
2066 
HWTEST_F_L0(JSNApiSplTest,IsMultiline)2067 HWTEST_F_L0(JSNApiSplTest, IsMultiline)
2068 {
2069     LocalScope scope(vm_);
2070     CalculateForTime();
2071     JSThread *thread = vm_->GetJSThread();
2072     ObjectFactory *factory = vm_->GetFactory();
2073     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
2074     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
2075     JSHandle<JSHClass> jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto);
2076     JSHandle<JSRegExp> jSRegExp = JSHandle<JSRegExp>::Cast(factory->NewJSObject(jSRegExpClass));
2077     JSHandle<JSTaggedValue> jsRegTag = JSHandle<JSTaggedValue>::Cast(jSRegExp);
2078     Local<RegExpRef> object = JSNApiHelper::ToLocal<RegExpRef>(jsRegTag);
2079     gettimeofday(&g_beginTime, nullptr);
2080     for (int i = 0; i < NUM_COUNT; i++) {
2081         object->IsMultiline(vm_);
2082     }
2083     gettimeofday(&g_endTime, nullptr);
2084     TEST_TIME(RegExpRef::IsMultiline);
2085 }
2086 
HWTEST_F_L0(JSNApiSplTest,IsDotAll)2087 HWTEST_F_L0(JSNApiSplTest, IsDotAll)
2088 {
2089     LocalScope scope(vm_);
2090     CalculateForTime();
2091     JSThread *thread = vm_->GetJSThread();
2092     ObjectFactory *factory = vm_->GetFactory();
2093     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
2094     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
2095     JSHandle<JSHClass> jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto);
2096     JSHandle<JSRegExp> jSRegExp = JSHandle<JSRegExp>::Cast(factory->NewJSObject(jSRegExpClass));
2097     JSHandle<JSTaggedValue> jsregtag = JSHandle<JSTaggedValue>::Cast(jSRegExp);
2098     Local<RegExpRef> object = JSNApiHelper::ToLocal<RegExpRef>(jsregtag);
2099     gettimeofday(&g_beginTime, nullptr);
2100     for (int i = 0; i < NUM_COUNT; i++) {
2101         object->IsDotAll(vm_);
2102     }
2103     gettimeofday(&g_endTime, nullptr);
2104     TEST_TIME(RegExpRef::IsDotAll);
2105 }
2106 
HWTEST_F_L0(JSNApiSplTest,IsUtf16)2107 HWTEST_F_L0(JSNApiSplTest, IsUtf16)
2108 {
2109     LocalScope scope(vm_);
2110     CalculateForTime();
2111     JSThread *thread = vm_->GetJSThread();
2112     ObjectFactory *factory = vm_->GetFactory();
2113     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
2114     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
2115     JSHandle<JSHClass> jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto);
2116     JSHandle<JSRegExp> jSRegExp = JSHandle<JSRegExp>::Cast(factory->NewJSObject(jSRegExpClass));
2117     JSHandle<JSTaggedValue> jsregtag = JSHandle<JSTaggedValue>::Cast(jSRegExp);
2118     Local<RegExpRef> object = JSNApiHelper::ToLocal<RegExpRef>(jsregtag);
2119     gettimeofday(&g_beginTime, nullptr);
2120     for (int i = 0; i < NUM_COUNT; i++) {
2121         object->IsUtf16(vm_);
2122     }
2123     gettimeofday(&g_endTime, nullptr);
2124     TEST_TIME(RegExpRef::IsUtf16);
2125 }
2126 
HWTEST_F_L0(JSNApiSplTest,IsStick)2127 HWTEST_F_L0(JSNApiSplTest, IsStick)
2128 {
2129     LocalScope scope(vm_);
2130     CalculateForTime();
2131     JSThread *thread = vm_->GetJSThread();
2132     ObjectFactory *factory = vm_->GetFactory();
2133     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
2134     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
2135     JSHandle<JSHClass> jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto);
2136     JSHandle<JSRegExp> jSRegExp = JSHandle<JSRegExp>::Cast(factory->NewJSObject(jSRegExpClass));
2137     JSHandle<JSTaggedValue> jsregtag = JSHandle<JSTaggedValue>::Cast(jSRegExp);
2138     Local<RegExpRef> object = JSNApiHelper::ToLocal<RegExpRef>(jsregtag);
2139     gettimeofday(&g_beginTime, nullptr);
2140     for (int i = 0; i < NUM_COUNT; i++) {
2141         object->IsStick(vm_);
2142     }
2143     gettimeofday(&g_endTime, nullptr);
2144     TEST_TIME(RegExpRef::IsStick);
2145 }
2146 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_BooleaValue_True)2147 HWTEST_F_L0(JSNApiSplTest, JSValueRef_BooleaValue_True)
2148 {
2149     LocalScope scope(vm_);
2150     CalculateForTime();
2151     Local<JSValueRef> tag = JSValueRef::True(vm_);
2152     gettimeofday(&g_beginTime, nullptr);
2153     for (int i = 0; i < NUM_COUNT; i++) {
2154         bool b = tag->BooleaValue(vm_);
2155         UNUSED(b);
2156     }
2157     gettimeofday(&g_endTime, nullptr);
2158     TEST_TIME(JSValueRef_BooleaValue_true);
2159 }
2160 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_BooleaValue_False)2161 HWTEST_F_L0(JSNApiSplTest, JSValueRef_BooleaValue_False)
2162 {
2163     LocalScope scope(vm_);
2164     CalculateForTime();
2165     Local<JSValueRef> tag = JSValueRef::False(vm_);
2166     gettimeofday(&g_beginTime, nullptr);
2167     for (int i = 0; i < NUM_COUNT; i++) {
2168         bool b = tag->BooleaValue(vm_);
2169         UNUSED(b);
2170     }
2171     gettimeofday(&g_endTime, nullptr);
2172     TEST_TIME(JSValueRef_BooleaValue_false);
2173 }
2174 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IntegerValue_Int64)2175 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IntegerValue_Int64)
2176 {
2177     LocalScope scope(vm_);
2178     CalculateForTime();
2179     int64_t num = 0xffffffffffff; // 0xffffffffffff = A number exceeding 32 bits
2180     Local<JSValueRef> targetInt = NumberRef::New(vm_, num);
2181     gettimeofday(&g_beginTime, nullptr);
2182     for (int i = 0; i < NUM_COUNT; i++) {
2183         int64_t i64 = targetInt->IntegerValue(vm_);
2184         UNUSED(i64);
2185     }
2186     gettimeofday(&g_endTime, nullptr);
2187     TEST_TIME(JSValueRef_IntegerValue_Int64);
2188 }
2189 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IntegerValue_Double)2190 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IntegerValue_Double)
2191 {
2192     LocalScope scope(vm_);
2193     CalculateForTime();
2194     double num = 123.456; // 123.456 = random number
2195     Local<JSValueRef> targetInt = NumberRef::New(vm_, num);
2196     gettimeofday(&g_beginTime, nullptr);
2197     for (int i = 0; i < NUM_COUNT; i++) {
2198         int64_t i64 = targetInt->IntegerValue(vm_);
2199         UNUSED(i64);
2200     }
2201     gettimeofday(&g_endTime, nullptr);
2202     TEST_TIME(JSValueRef_IntegerValue_Double);
2203 }
2204 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IntegerValue_Int)2205 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IntegerValue_Int)
2206 {
2207     LocalScope scope(vm_);
2208     CalculateForTime();
2209     int num = 789; // 789 = random number
2210     Local<JSValueRef> targetInt = IntegerRef::New(vm_, num);
2211     gettimeofday(&g_beginTime, nullptr);
2212     for (int i = 0; i < NUM_COUNT; i++) {
2213         int64_t i64 = targetInt->IntegerValue(vm_);
2214         UNUSED(i64);
2215     }
2216     gettimeofday(&g_endTime, nullptr);
2217     TEST_TIME(JSValueRef_IntegerValue_Int);
2218 }
2219 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_Uint32Value)2220 HWTEST_F_L0(JSNApiSplTest, JSValueRef_Uint32Value)
2221 {
2222     LocalScope scope(vm_);
2223     CalculateForTime();
2224     unsigned int num = 456; // 456 = random number
2225     Local<JSValueRef> targetUInt = IntegerRef::NewFromUnsigned(vm_, num);
2226     gettimeofday(&g_beginTime, nullptr);
2227     for (int i = 0; i < NUM_COUNT; i++) {
2228         uint32_t ui = targetUInt->Uint32Value(vm_);
2229         UNUSED(ui);
2230     }
2231     gettimeofday(&g_endTime, nullptr);
2232     TEST_TIME(JSValueRef_Uint32Value);
2233 }
2234 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToNativePointer_String)2235 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToNativePointer_String)
2236 {
2237     LocalScope scope(vm_);
2238     CalculateForTime();
2239     void *vp1 = static_cast<void *>(new std::string("test1"));
2240     Local<JSValueRef> tag = NativePointerRef::New(vm_, vp1);
2241     gettimeofday(&g_beginTime, nullptr);
2242     for (int i = 0; i < NUM_COUNT; i++) {
2243         Local<NativePointerRef> npr = tag->ToNativePointer(vm_);
2244         UNUSED(npr);
2245     }
2246     gettimeofday(&g_endTime, nullptr);
2247     TEST_TIME(JSValueRef_ToNativePointer_String);
2248 }
2249 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToNativePointer_Int)2250 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToNativePointer_Int)
2251 {
2252     LocalScope scope(vm_);
2253     CalculateForTime();
2254     void *vp1 = static_cast<void *>(new int(123)); // 123 = random number
2255     Local<JSValueRef> tag = NativePointerRef::New(vm_, vp1);
2256     gettimeofday(&g_beginTime, nullptr);
2257     for (int i = 0; i < NUM_COUNT; i++) {
2258         Local<NativePointerRef> npr = tag->ToNativePointer(vm_);
2259         UNUSED(npr);
2260     }
2261     gettimeofday(&g_endTime, nullptr);
2262     TEST_TIME(JSValueRef_ToNativePointer_Int);
2263 }
2264 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToNativePointer_Double)2265 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToNativePointer_Double)
2266 {
2267     LocalScope scope(vm_);
2268     CalculateForTime();
2269     void *vp1 = static_cast<void *>(new double(123.456)); // 123.456 = random number
2270     Local<JSValueRef> tag = NativePointerRef::New(vm_, vp1);
2271     gettimeofday(&g_beginTime, nullptr);
2272     for (int i = 0; i < NUM_COUNT; i++) {
2273         Local<NativePointerRef> npr = tag->ToNativePointer(vm_);
2274         UNUSED(npr);
2275     }
2276     gettimeofday(&g_endTime, nullptr);
2277     TEST_TIME(JSValueRef_ToNativePointer_Double);
2278 }
2279 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToNativePointer_Char)2280 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToNativePointer_Char)
2281 {
2282     LocalScope scope(vm_);
2283     CalculateForTime();
2284     void *vp1 = static_cast<void *>(new char('a'));
2285     Local<JSValueRef> tag = NativePointerRef::New(vm_, vp1);
2286     gettimeofday(&g_beginTime, nullptr);
2287     for (int i = 0; i < NUM_COUNT; i++) {
2288         Local<NativePointerRef> npr = tag->ToNativePointer(vm_);
2289         UNUSED(npr);
2290     }
2291     gettimeofday(&g_endTime, nullptr);
2292     TEST_TIME(JSValueRef_ToNativePointer_Char);
2293 }
2294 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToNativePointer_Long)2295 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToNativePointer_Long)
2296 {
2297     LocalScope scope(vm_);
2298     CalculateForTime();
2299     void *vp1 = static_cast<void *>(new long(123456)); // 123456 = random number
2300     Local<JSValueRef> tag = NativePointerRef::New(vm_, vp1);
2301     gettimeofday(&g_beginTime, nullptr);
2302     for (int i = 0; i < NUM_COUNT; i++) {
2303         Local<NativePointerRef> npr = tag->ToNativePointer(vm_);
2304         UNUSED(npr);
2305     }
2306     gettimeofday(&g_endTime, nullptr);
2307     TEST_TIME(JSValueRef_ToNativePointer_Long);
2308 }
2309 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsUndefined_False)2310 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsUndefined_False)
2311 {
2312     LocalScope scope(vm_);
2313     CalculateForTime();
2314     int num = 123; // 123 = random number
2315     Local<JSValueRef> tag = IntegerRef::New(vm_, num);
2316     gettimeofday(&g_beginTime, nullptr);
2317     for (int i = 0; i < NUM_COUNT; i++) {
2318         bool b = tag->IsUndefined();
2319         UNUSED(b);
2320     }
2321     gettimeofday(&g_endTime, nullptr);
2322     TEST_TIME(JSValueRef_IsUndefined_False);
2323 }
2324 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsUndefined_True)2325 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsUndefined_True)
2326 {
2327     LocalScope scope(vm_);
2328     CalculateForTime();
2329     Local<JSValueRef> tag = JSValueRef::Undefined(vm_);
2330     gettimeofday(&g_beginTime, nullptr);
2331     for (int i = 0; i < NUM_COUNT; i++) {
2332         bool b = tag->IsUndefined();
2333         UNUSED(b);
2334     }
2335     gettimeofday(&g_endTime, nullptr);
2336     TEST_TIME(JSValueRef_IsUndefined_True);
2337 }
2338 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsNull_False)2339 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsNull_False)
2340 {
2341     LocalScope scope(vm_);
2342     CalculateForTime();
2343     int num = 123; // 123 = random number
2344     Local<JSValueRef> tag = IntegerRef::New(vm_, num);
2345     gettimeofday(&g_beginTime, nullptr);
2346     for (int i = 0; i < NUM_COUNT; i++) {
2347         bool b = tag->IsNull();
2348         UNUSED(b);
2349     }
2350     gettimeofday(&g_endTime, nullptr);
2351     TEST_TIME(JSValueRef_IsNull_False);
2352 }
2353 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsNull_True)2354 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsNull_True)
2355 {
2356     LocalScope scope(vm_);
2357     CalculateForTime();
2358     Local<JSValueRef> tag = JSValueRef::Null(vm_);
2359     gettimeofday(&g_beginTime, nullptr);
2360     for (int i = 0; i < NUM_COUNT; i++) {
2361         bool b = tag->IsNull();
2362         UNUSED(b);
2363     }
2364     gettimeofday(&g_endTime, nullptr);
2365     TEST_TIME(JSValueRef_IsNull_True);
2366 }
2367 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_WithinInt32_False)2368 HWTEST_F_L0(JSNApiSplTest, JSValueRef_WithinInt32_False)
2369 {
2370     LocalScope scope(vm_);
2371     CalculateForTime();
2372     Local<JSValueRef> tag = StringRef::NewFromUtf8(vm_, "abcd");
2373     gettimeofday(&g_beginTime, nullptr);
2374     for (int i = 0; i < NUM_COUNT; i++) {
2375         bool b = tag->WithinInt32();
2376         UNUSED(b);
2377     }
2378     gettimeofday(&g_endTime, nullptr);
2379     TEST_TIME(JSValueRef_WithinInt32_False);
2380 }
2381 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_WithinInt32_True)2382 HWTEST_F_L0(JSNApiSplTest, JSValueRef_WithinInt32_True)
2383 {
2384     LocalScope scope(vm_);
2385     CalculateForTime();
2386     int num = 456; // 456 = random number
2387     Local<JSValueRef> tag = IntegerRef::New(vm_, num);
2388     gettimeofday(&g_beginTime, nullptr);
2389     for (int i = 0; i < NUM_COUNT; i++) {
2390         bool b = tag->WithinInt32();
2391         UNUSED(b);
2392     }
2393     gettimeofday(&g_endTime, nullptr);
2394     TEST_TIME(JSValueRef_WithinInt32_True);
2395 }
2396 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsBoolean_False)2397 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBoolean_False)
2398 {
2399     LocalScope scope(vm_);
2400     CalculateForTime();
2401     int num = 123; // 123 = random number
2402     Local<JSValueRef> tag = IntegerRef::New(vm_, num);
2403     gettimeofday(&g_beginTime, nullptr);
2404     for (int i = 0; i < NUM_COUNT; i++) {
2405         bool b = tag->IsBoolean();
2406         UNUSED(b);
2407     }
2408     gettimeofday(&g_endTime, nullptr);
2409     TEST_TIME(JSValueRef_IsBoolean_False);
2410 }
2411 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsBoolean_True)2412 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBoolean_True)
2413 {
2414     LocalScope scope(vm_);
2415     CalculateForTime();
2416     Local<JSValueRef> tag = BooleanRef::New(vm_, false);
2417     gettimeofday(&g_beginTime, nullptr);
2418     for (int i = 0; i < NUM_COUNT; i++) {
2419         bool b = tag->IsBoolean();
2420         UNUSED(b);
2421     }
2422     gettimeofday(&g_endTime, nullptr);
2423     TEST_TIME(JSValueRef_IsBoolean_True);
2424 }
2425 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsString_False)2426 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsString_False)
2427 {
2428     LocalScope scope(vm_);
2429     CalculateForTime();
2430     Local<JSValueRef> tag = BooleanRef::New(vm_, true);
2431     gettimeofday(&g_beginTime, nullptr);
2432     for (int i = 0; i < NUM_COUNT; i++) {
2433         bool b = tag->IsString(vm_);
2434         UNUSED(b);
2435     }
2436     gettimeofday(&g_endTime, nullptr);
2437     TEST_TIME(JSValueRef_IsString_False);
2438 }
2439 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsString_True)2440 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsString_True)
2441 {
2442     LocalScope scope(vm_);
2443     CalculateForTime();
2444     Local<JSValueRef> tag = StringRef::NewFromUtf8(vm_, "abc");
2445     gettimeofday(&g_beginTime, nullptr);
2446     for (int i = 0; i < NUM_COUNT; i++) {
2447         bool b = tag->IsString(vm_);
2448         UNUSED(b);
2449     }
2450     gettimeofday(&g_endTime, nullptr);
2451     TEST_TIME(JSValueRef_IsString_True);
2452 }
2453 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsProxy_False)2454 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsProxy_False)
2455 {
2456     LocalScope scope(vm_);
2457     CalculateForTime();
2458     Local<JSValueRef> tag = BooleanRef::New(vm_, true);
2459     gettimeofday(&g_beginTime, nullptr);
2460     for (int i = 0; i < NUM_COUNT; i++) {
2461         bool b = tag->IsProxy(vm_);
2462         UNUSED(b);
2463     }
2464     gettimeofday(&g_endTime, nullptr);
2465     TEST_TIME(JSValueRef_IsProxy_False);
2466 }
2467 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsProxy_True)2468 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsProxy_True)
2469 {
2470     LocalScope scope(vm_);
2471     CalculateForTime();
2472     Local<JSValueRef> tag = ProxyRef::New(vm_);
2473     gettimeofday(&g_beginTime, nullptr);
2474     for (int i = 0; i < NUM_COUNT; i++) {
2475         bool b = tag->IsProxy(vm_);
2476         UNUSED(b);
2477     }
2478     gettimeofday(&g_endTime, nullptr);
2479     TEST_TIME(JSValueRef_IsProxy_True);
2480 }
2481 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsPromise_False)2482 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsPromise_False)
2483 {
2484     LocalScope scope(vm_);
2485     CalculateForTime();
2486     Local<JSValueRef> tag = BooleanRef::New(vm_, true);
2487     gettimeofday(&g_beginTime, nullptr);
2488     for (int i = 0; i < NUM_COUNT; i++) {
2489         bool b = tag->IsPromise(vm_);
2490         UNUSED(b);
2491     }
2492     gettimeofday(&g_endTime, nullptr);
2493     TEST_TIME(JSValueRef_IsPromise_False);
2494 }
2495 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsPromise_True)2496 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsPromise_True)
2497 {
2498     LocalScope scope(vm_);
2499     CalculateForTime();
2500     Local<JSValueRef> tag = PromiseCapabilityRef::New(vm_)->GetPromise(vm_);
2501     gettimeofday(&g_beginTime, nullptr);
2502     for (int i = 0; i < NUM_COUNT; i++) {
2503         bool b = tag->IsPromise(vm_);
2504         UNUSED(b);
2505     }
2506     gettimeofday(&g_endTime, nullptr);
2507     TEST_TIME(JSValueRef_IsPromise_True);
2508 }
2509 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsDataView_False)2510 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsDataView_False)
2511 {
2512     LocalScope scope(vm_);
2513     CalculateForTime();
2514     Local<JSValueRef> tag = BooleanRef::New(vm_, true);
2515     gettimeofday(&g_beginTime, nullptr);
2516     for (int i = 0; i < NUM_COUNT; i++) {
2517         bool b = tag->IsDataView(vm_);
2518         UNUSED(b);
2519     }
2520     gettimeofday(&g_endTime, nullptr);
2521     TEST_TIME(JSValueRef_IsDataView_False);
2522 }
2523 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsDataView_True)2524 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsDataView_True)
2525 {
2526     LocalScope scope(vm_);
2527     CalculateForTime();
2528     int num = 0; // 0 = random number
2529     Local<JSValueRef> tag = DataViewRef::New(vm_, ArrayBufferRef::New(vm_, num), num, num);
2530     gettimeofday(&g_beginTime, nullptr);
2531     for (int i = 0; i < NUM_COUNT; i++) {
2532         bool b = tag->IsDataView(vm_);
2533         UNUSED(b);
2534     }
2535     gettimeofday(&g_endTime, nullptr);
2536     TEST_TIME(JSValueRef_IsDataView_True);
2537 }
2538 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsWeakRef_False)2539 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsWeakRef_False)
2540 {
2541     LocalScope scope(vm_);
2542     CalculateForTime();
2543     Local<JSValueRef> tag = BooleanRef::New(vm_, true);
2544     gettimeofday(&g_beginTime, nullptr);
2545     for (int i = 0; i < NUM_COUNT; i++) {
2546         bool b = tag->IsWeakRef(vm_);
2547         UNUSED(b);
2548     }
2549     gettimeofday(&g_endTime, nullptr);
2550     TEST_TIME(JSValueRef_IsWeakRef_False);
2551 }
2552 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsWeakMap_False)2553 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsWeakMap_False)
2554 {
2555     LocalScope scope(vm_);
2556     CalculateForTime();
2557     Local<JSValueRef> tag = BooleanRef::New(vm_, true);
2558     gettimeofday(&g_beginTime, nullptr);
2559     for (int i = 0; i < NUM_COUNT; i++) {
2560         bool b = tag->IsWeakMap(vm_);
2561         UNUSED(b);
2562     }
2563     gettimeofday(&g_endTime, nullptr);
2564     TEST_TIME(JSValueRef_IsWeakMap_False);
2565 }
2566 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsWeakMap_True)2567 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsWeakMap_True)
2568 {
2569     LocalScope scope(vm_);
2570     CalculateForTime();
2571     Local<JSValueRef> tag = WeakMapRef::New(vm_);
2572     gettimeofday(&g_beginTime, nullptr);
2573     for (int i = 0; i < NUM_COUNT; i++) {
2574         bool b = tag->IsWeakMap(vm_);
2575         UNUSED(b);
2576     }
2577     gettimeofday(&g_endTime, nullptr);
2578     TEST_TIME(JSValueRef_IsWeakMap_True);
2579 }
2580 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsWeakSet_False)2581 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsWeakSet_False)
2582 {
2583     LocalScope scope(vm_);
2584     CalculateForTime();
2585     Local<JSValueRef> tag = JSValueRef::Null(vm_);
2586     gettimeofday(&g_beginTime, nullptr);
2587     for (int i = 0; i < NUM_COUNT; i++) {
2588         bool b = tag->IsWeakSet(vm_);
2589         UNUSED(b);
2590     }
2591     gettimeofday(&g_endTime, nullptr);
2592     TEST_TIME(JSValueRef_IsWeakSet_False);
2593 }
2594 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsWeakSet_True)2595 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsWeakSet_True)
2596 {
2597     LocalScope scope(vm_);
2598     CalculateForTime();
2599     Local<JSValueRef> tag = WeakSetRef::New(vm_);
2600     gettimeofday(&g_beginTime, nullptr);
2601     for (int i = 0; i < NUM_COUNT; i++) {
2602         bool b = tag->IsWeakSet(vm_);
2603         UNUSED(b);
2604     }
2605     gettimeofday(&g_endTime, nullptr);
2606     TEST_TIME(JSValueRef_IsWeakSet_True);
2607 }
2608 
HWTEST_F_L0(JSNApiSplTest,Global_Global)2609 HWTEST_F_L0(JSNApiSplTest, Global_Global)
2610 {
2611     LocalScope scope(vm_);
2612     CalculateForTime();
2613     Global<JSValueRef> param;
2614     gettimeofday(&g_beginTime, nullptr);
2615     for (int i = 0; i < NUM_COUNT; i++) {
2616         Global<JSValueRef> global(param);
2617         UNUSED(global);
2618     }
2619     gettimeofday(&g_endTime, nullptr);
2620     TEST_TIME(Global_Global);
2621 }
2622 
HWTEST_F_L0(JSNApiSplTest,Global_OperatorEqual)2623 HWTEST_F_L0(JSNApiSplTest, Global_OperatorEqual)
2624 {
2625     LocalScope scope(vm_);
2626     CalculateForTime();
2627     Global<JSValueRef> param;
2628     Global<JSValueRef> global;
2629     gettimeofday(&g_beginTime, nullptr);
2630     for (int i = 0; i < NUM_COUNT; i++) {
2631         global = param;
2632     }
2633     gettimeofday(&g_endTime, nullptr);
2634     TEST_TIME(Global_OperatorEqual);
2635 }
2636 
HWTEST_F_L0(JSNApiSplTest,Global_GlobalMove)2637 HWTEST_F_L0(JSNApiSplTest, Global_GlobalMove)
2638 {
2639     LocalScope scope(vm_);
2640     CalculateForTime();
2641     Global<JSValueRef> param;
2642     gettimeofday(&g_beginTime, nullptr);
2643     for (int i = 0; i < NUM_COUNT; i++) {
2644         Global<JSValueRef> global(std::move(param));
2645         UNUSED(global);
2646     }
2647     gettimeofday(&g_endTime, nullptr);
2648     TEST_TIME(Global_GlobalMove);
2649 }
2650 
HWTEST_F_L0(JSNApiSplTest,Global_OperatorEqualMove)2651 HWTEST_F_L0(JSNApiSplTest, Global_OperatorEqualMove)
2652 {
2653     LocalScope scope(vm_);
2654     CalculateForTime();
2655     Global<JSValueRef> param;
2656     Global<JSValueRef> global;
2657     gettimeofday(&g_beginTime, nullptr);
2658     for (int i = 0; i < NUM_COUNT; i++) {
2659         global = std::move(param);
2660     }
2661     gettimeofday(&g_endTime, nullptr);
2662     TEST_TIME(Global_OperatorEqualMove);
2663 }
2664 
HWTEST_F_L0(JSNApiSplTest,Global_Global_VM_Local)2665 HWTEST_F_L0(JSNApiSplTest, Global_Global_VM_Local)
2666 {
2667     LocalScope scope(vm_);
2668     CalculateForTime();
2669     Local<BooleanRef> current = BooleanRef::New(vm_, true);
2670     gettimeofday(&g_beginTime, nullptr);
2671     for (int i = 0; i < NUM_COUNT; i++) {
2672         Global<JSValueRef> global(vm_, current);
2673         UNUSED(global);
2674     }
2675     gettimeofday(&g_endTime, nullptr);
2676     TEST_TIME(Global_Global_VM_Local);
2677 }
2678 
HWTEST_F_L0(JSNApiSplTest,Global_Global_VM_Global)2679 HWTEST_F_L0(JSNApiSplTest, Global_Global_VM_Global)
2680 {
2681     LocalScope scope(vm_);
2682     CalculateForTime();
2683     Global<BooleanRef> current(vm_, BooleanRef::New(vm_, true));
2684     gettimeofday(&g_beginTime, nullptr);
2685     for (int i = 0; i < NUM_COUNT; i++) {
2686         Global<JSValueRef> global(vm_, current);
2687         UNUSED(global);
2688     }
2689     gettimeofday(&g_endTime, nullptr);
2690     TEST_TIME(Global_Global_VM_Global);
2691 }
2692 
HWTEST_F_L0(JSNApiSplTest,Global_ToLocal)2693 HWTEST_F_L0(JSNApiSplTest, Global_ToLocal)
2694 {
2695     LocalScope scope(vm_);
2696     CalculateForTime();
2697     Global<BooleanRef> global(vm_, BooleanRef::New(vm_, true));
2698     gettimeofday(&g_beginTime, nullptr);
2699     for (int i = 0; i < NUM_COUNT; i++) {
2700         Local<JSValueRef> local = global.ToLocal();
2701         UNUSED(local);
2702     }
2703     gettimeofday(&g_endTime, nullptr);
2704     TEST_TIME(Global_ToLocal);
2705 }
2706 
HWTEST_F_L0(JSNApiSplTest,Global_ToLocal_VM)2707 HWTEST_F_L0(JSNApiSplTest, Global_ToLocal_VM)
2708 {
2709     LocalScope scope(vm_);
2710     CalculateForTime();
2711     Global<BooleanRef> global(vm_, BooleanRef::New(vm_, true));
2712     gettimeofday(&g_beginTime, nullptr);
2713     for (int i = 0; i < NUM_COUNT; i++) {
2714         Local<JSValueRef> local = global.ToLocal(vm_);
2715         UNUSED(local);
2716     }
2717     gettimeofday(&g_endTime, nullptr);
2718     TEST_TIME(Global_ToLocal_VM);
2719 }
2720 
HWTEST_F_L0(JSNApiSplTest,Global_Empty)2721 HWTEST_F_L0(JSNApiSplTest, Global_Empty)
2722 {
2723     LocalScope scope(vm_);
2724     CalculateForTime();
2725     Global<BooleanRef> global(vm_, BooleanRef::New(vm_, true));
2726     gettimeofday(&g_beginTime, nullptr);
2727     for (int i = 0; i < NUM_COUNT; i++) {
2728         global.Empty();
2729     }
2730     gettimeofday(&g_endTime, nullptr);
2731     TEST_TIME(Global_Empty);
2732 }
2733 
HWTEST_F_L0(JSNApiSplTest,Global_FreeGlobalHandleAddr)2734 HWTEST_F_L0(JSNApiSplTest, Global_FreeGlobalHandleAddr)
2735 {
2736     LocalScope scope(vm_);
2737     CalculateForTime();
2738     Global<BooleanRef> global(vm_, BooleanRef::New(vm_, true));
2739     gettimeofday(&g_beginTime, nullptr);
2740     for (int i = 0; i < NUM_COUNT; i++) {
2741         global.FreeGlobalHandleAddr();
2742     }
2743     gettimeofday(&g_endTime, nullptr);
2744     TEST_TIME(Global_FreeGlobalHandleAddr);
2745 }
2746 
HWTEST_F_L0(JSNApiSplTest,Global_OperatorStar)2747 HWTEST_F_L0(JSNApiSplTest, Global_OperatorStar)
2748 {
2749     LocalScope scope(vm_);
2750     CalculateForTime();
2751     Global<JSValueRef> global(vm_, BooleanRef::New(vm_, true));
2752     gettimeofday(&g_beginTime, nullptr);
2753     for (int i = 0; i < NUM_COUNT; i++) {
2754         bool b = (*global)->BooleaValue(vm_);
2755         UNUSED(b);
2756     }
2757     gettimeofday(&g_endTime, nullptr);
2758     TEST_TIME(Global_OperatorStar);
2759 }
2760 
HWTEST_F_L0(JSNApiSplTest,Global_OperatorPointTo)2761 HWTEST_F_L0(JSNApiSplTest, Global_OperatorPointTo)
2762 {
2763     LocalScope scope(vm_);
2764     CalculateForTime();
2765     Global<JSValueRef> global(vm_, BooleanRef::New(vm_, true));
2766     gettimeofday(&g_beginTime, nullptr);
2767     for (int i = 0; i < NUM_COUNT; i++) {
2768         bool b = global->BooleaValue(vm_);
2769         UNUSED(b);
2770     }
2771     gettimeofday(&g_endTime, nullptr);
2772     TEST_TIME(Global_OperatorPointTo);
2773 }
2774 
HWTEST_F_L0(JSNApiSplTest,Global_IsEmpty_True)2775 HWTEST_F_L0(JSNApiSplTest, Global_IsEmpty_True)
2776 {
2777     LocalScope scope(vm_);
2778     CalculateForTime();
2779     Global<JSValueRef> global;
2780     gettimeofday(&g_beginTime, nullptr);
2781     for (int i = 0; i < NUM_COUNT; i++) {
2782         bool b = global.IsEmpty();
2783         UNUSED(b);
2784     }
2785     gettimeofday(&g_endTime, nullptr);
2786     TEST_TIME(Global_IsEmpty_True);
2787 }
2788 
HWTEST_F_L0(JSNApiSplTest,Global_IsEmpty_False)2789 HWTEST_F_L0(JSNApiSplTest, Global_IsEmpty_False)
2790 {
2791     LocalScope scope(vm_);
2792     CalculateForTime();
2793     Global<JSValueRef> global(vm_, BooleanRef::New(vm_, true));
2794     gettimeofday(&g_beginTime, nullptr);
2795     for (int i = 0; i < NUM_COUNT; i++) {
2796         bool b = global.IsEmpty();
2797         UNUSED(b);
2798     }
2799     gettimeofday(&g_endTime, nullptr);
2800     TEST_TIME(Global_IsEmpty_False);
2801 }
2802 
HWTEST_F_L0(JSNApiSplTest,Global_SetWeak)2803 HWTEST_F_L0(JSNApiSplTest, Global_SetWeak)
2804 {
2805     LocalScope scope(vm_);
2806     CalculateForTime();
2807     Global<JSValueRef> global(vm_, BooleanRef::New(vm_, true));
2808     gettimeofday(&g_beginTime, nullptr);
2809     for (int i = 0; i < NUM_COUNT; i++) {
2810         global.SetWeak();
2811     }
2812     gettimeofday(&g_endTime, nullptr);
2813     TEST_TIME(Global_SetWeak);
2814 }
2815 
HWTEST_F_L0(JSNApiSplTest,Global_SetWeakCallback_Int)2816 HWTEST_F_L0(JSNApiSplTest, Global_SetWeakCallback_Int)
2817 {
2818     LocalScope scope(vm_);
2819     CalculateForTime();
2820     Global<JSValueRef> global(vm_, BooleanRef::New(vm_, true));
2821     void *ref = new int(123); // 123 = random number
2822     WeakRefClearCallBack freeGlobalCallBack = FreeGlobalCallBack<int>;
2823     WeakRefClearCallBack nativeFinalizeCallback = NativeFinalizeCallback<int>;
2824     gettimeofday(&g_beginTime, nullptr);
2825     for (int i = 0; i < NUM_COUNT; i++) {
2826         global.SetWeakCallback(ref, freeGlobalCallBack, nativeFinalizeCallback);
2827     }
2828     gettimeofday(&g_endTime, nullptr);
2829     TEST_TIME(Global_SetWeakCallback_Int);
2830 }
2831 
HWTEST_F_L0(JSNApiSplTest,Global_SetWeakCallback_String)2832 HWTEST_F_L0(JSNApiSplTest, Global_SetWeakCallback_String)
2833 {
2834     LocalScope scope(vm_);
2835     CalculateForTime();
2836     Global<JSValueRef> global(vm_, BooleanRef::New(vm_, true));
2837     void *ref = new std::string("abc");
2838     WeakRefClearCallBack freeGlobalCallBack = FreeGlobalCallBack<std::string>;
2839     WeakRefClearCallBack nativeFinalizeCallback = NativeFinalizeCallback<std::string>;
2840     gettimeofday(&g_beginTime, nullptr);
2841     for (int i = 0; i < NUM_COUNT; i++) {
2842         global.SetWeakCallback(ref, freeGlobalCallBack, nativeFinalizeCallback);
2843     }
2844     gettimeofday(&g_endTime, nullptr);
2845     TEST_TIME(Global_SetWeakCallback_String);
2846 }
2847 
HWTEST_F_L0(JSNApiSplTest,Global_SetWeakCallback_Double)2848 HWTEST_F_L0(JSNApiSplTest, Global_SetWeakCallback_Double)
2849 {
2850     LocalScope scope(vm_);
2851     CalculateForTime();
2852     Global<JSValueRef> global(vm_, BooleanRef::New(vm_, true));
2853     void *ref = new double(123.456); // 123.456 = random number
2854     WeakRefClearCallBack freeGlobalCallBack = FreeGlobalCallBack<double>;
2855     WeakRefClearCallBack nativeFinalizeCallback = NativeFinalizeCallback<double>;
2856     gettimeofday(&g_beginTime, nullptr);
2857     for (int i = 0; i < NUM_COUNT; i++) {
2858         global.SetWeakCallback(ref, freeGlobalCallBack, nativeFinalizeCallback);
2859     }
2860     gettimeofday(&g_endTime, nullptr);
2861     TEST_TIME(Global_SetWeakCallback_Double);
2862 }
2863 
HWTEST_F_L0(JSNApiSplTest,Global_SetWeakCallback_Char)2864 HWTEST_F_L0(JSNApiSplTest, Global_SetWeakCallback_Char)
2865 {
2866     LocalScope scope(vm_);
2867     CalculateForTime();
2868     Global<JSValueRef> global(vm_, BooleanRef::New(vm_, true));
2869     void *ref = new char('a');
2870     WeakRefClearCallBack freeGlobalCallBack = FreeGlobalCallBack<char>;
2871     WeakRefClearCallBack nativeFinalizeCallback = NativeFinalizeCallback<char>;
2872     gettimeofday(&g_beginTime, nullptr);
2873     for (int i = 0; i < NUM_COUNT; i++) {
2874         global.SetWeakCallback(ref, freeGlobalCallBack, nativeFinalizeCallback);
2875     }
2876     gettimeofday(&g_endTime, nullptr);
2877     TEST_TIME(Global_SetWeakCallback_Char);
2878 }
2879 
HWTEST_F_L0(JSNApiSplTest,Global_SetWeakCallback_Long)2880 HWTEST_F_L0(JSNApiSplTest, Global_SetWeakCallback_Long)
2881 {
2882     LocalScope scope(vm_);
2883     CalculateForTime();
2884     Global<JSValueRef> global(vm_, BooleanRef::New(vm_, true));
2885     void *ref = new long(123456); // 123456 = random number
2886     WeakRefClearCallBack freeGlobalCallBack = FreeGlobalCallBack<long>;
2887     WeakRefClearCallBack nativeFinalizeCallback = NativeFinalizeCallback<long>;
2888     gettimeofday(&g_beginTime, nullptr);
2889     for (int i = 0; i < NUM_COUNT; i++) {
2890         global.SetWeakCallback(ref, freeGlobalCallBack, nativeFinalizeCallback);
2891     }
2892     gettimeofday(&g_endTime, nullptr);
2893     TEST_TIME(Global_SetWeakCallback_Long);
2894 }
2895 
HWTEST_F_L0(JSNApiSplTest,Global_ClearWeak)2896 HWTEST_F_L0(JSNApiSplTest, Global_ClearWeak)
2897 {
2898     LocalScope scope(vm_);
2899     CalculateForTime();
2900     Global<JSValueRef> global(vm_, BooleanRef::New(vm_, true));
2901     gettimeofday(&g_beginTime, nullptr);
2902     for (int i = 0; i < NUM_COUNT; i++) {
2903         global.ClearWeak();
2904     }
2905     gettimeofday(&g_endTime, nullptr);
2906     TEST_TIME(Global_ClearWeak);
2907 }
2908 
HWTEST_F_L0(JSNApiSplTest,Global_IsWeak_False)2909 HWTEST_F_L0(JSNApiSplTest, Global_IsWeak_False)
2910 {
2911     LocalScope scope(vm_);
2912     CalculateForTime();
2913     Global<JSValueRef> global(vm_, BooleanRef::New(vm_, true));
2914     gettimeofday(&g_beginTime, nullptr);
2915     for (int i = 0; i < NUM_COUNT; i++) {
2916         bool b = global.IsWeak();
2917         UNUSED(b);
2918     }
2919     gettimeofday(&g_endTime, nullptr);
2920     TEST_TIME(Global_IsWeak_False);
2921 }
2922 
HWTEST_F_L0(JSNApiSplTest,Global_IsWeak_True)2923 HWTEST_F_L0(JSNApiSplTest, Global_IsWeak_True)
2924 {
2925     LocalScope scope(vm_);
2926     CalculateForTime();
2927     Global<JSValueRef> global(vm_, BooleanRef::New(vm_, true));
2928     global.SetWeak();
2929     gettimeofday(&g_beginTime, nullptr);
2930     for (int i = 0; i < NUM_COUNT; i++) {
2931         bool b = global.IsWeak();
2932         UNUSED(b);
2933     }
2934     gettimeofday(&g_endTime, nullptr);
2935     TEST_TIME(Global_IsWeak_True);
2936 }
2937 
HWTEST_F_L0(JSNApiSplTest,StringRef_Cast)2938 HWTEST_F_L0(JSNApiSplTest, StringRef_Cast)
2939 {
2940     LocalScope scope(vm_);
2941     CalculateForTime();
2942     Local<JSValueRef> local = StringRef::NewFromUtf8(vm_, "abcdefbb");
2943     JSValueRef *jsValue = (*local);
2944     gettimeofday(&g_beginTime, nullptr);
2945     for (int i = 0; i < NUM_COUNT; i++) {
2946         StringRef *str = StringRef::Cast(jsValue);
2947         UNUSED(str);
2948     }
2949     gettimeofday(&g_endTime, nullptr);
2950     TEST_TIME(StringRef_Cast);
2951 }
2952 
HWTEST_F_L0(JSNApiSplTest,StringRef_NewFromUtf8)2953 HWTEST_F_L0(JSNApiSplTest, StringRef_NewFromUtf8)
2954 {
2955     LocalScope scope(vm_);
2956     CalculateForTime();
2957     gettimeofday(&g_beginTime, nullptr);
2958     for (int i = 0; i < NUM_COUNT; i++) {
2959         Local<StringRef> local = StringRef::NewFromUtf8(vm_, "abcdefbb");
2960         UNUSED(local);
2961     }
2962     gettimeofday(&g_endTime, nullptr);
2963     TEST_TIME(StringRef_NewFromUtf8);
2964 }
2965 
HWTEST_F_L0(JSNApiSplTest,StringRef_NewFromUtf8_0)2966 HWTEST_F_L0(JSNApiSplTest, StringRef_NewFromUtf8_0)
2967 {
2968     LocalScope scope(vm_);
2969     CalculateForTime();
2970     gettimeofday(&g_beginTime, nullptr);
2971     for (int i = 0; i < NUM_COUNT; i++) {
2972         Local<StringRef> local = StringRef::NewFromUtf8(vm_, "abcdefbb", 0);
2973         UNUSED(local);
2974     }
2975     gettimeofday(&g_endTime, nullptr);
2976     TEST_TIME(StringRef_NewFromUtf8_0);
2977 }
2978 
HWTEST_F_L0(JSNApiSplTest,StringRef_NewFromUtf8_3)2979 HWTEST_F_L0(JSNApiSplTest, StringRef_NewFromUtf8_3)
2980 {
2981     LocalScope scope(vm_);
2982     CalculateForTime();
2983     gettimeofday(&g_beginTime, nullptr);
2984     for (int i = 0; i < NUM_COUNT; i++) {
2985         Local<StringRef> local = StringRef::NewFromUtf8(vm_, "abcdefbb", 3);
2986         UNUSED(local);
2987     }
2988     gettimeofday(&g_endTime, nullptr);
2989     TEST_TIME(StringRef_NewFromUtf8_3);
2990 }
2991 
HWTEST_F_L0(JSNApiSplTest,StringRef_NewFromUtf16)2992 HWTEST_F_L0(JSNApiSplTest, StringRef_NewFromUtf16)
2993 {
2994     LocalScope scope(vm_);
2995     CalculateForTime();
2996     const char16_t *utf16 = u"您好,华为!";
2997     gettimeofday(&g_beginTime, nullptr);
2998     for (int i = 0; i < NUM_COUNT; i++) {
2999         Local<StringRef> local = StringRef::NewFromUtf16(vm_, utf16);
3000         UNUSED(local);
3001     }
3002     gettimeofday(&g_endTime, nullptr);
3003     TEST_TIME(StringRef_NewFromUtf16);
3004 }
3005 
HWTEST_F_L0(JSNApiSplTest,StringRef_NewFromUtf16_0)3006 HWTEST_F_L0(JSNApiSplTest, StringRef_NewFromUtf16_0)
3007 {
3008     LocalScope scope(vm_);
3009     CalculateForTime();
3010     const char16_t *utf16 = u"您好,华为!";
3011     gettimeofday(&g_beginTime, nullptr);
3012     for (int i = 0; i < NUM_COUNT; i++) {
3013         Local<StringRef> local = StringRef::NewFromUtf16(vm_, utf16, 0);
3014         UNUSED(local);
3015     }
3016     gettimeofday(&g_endTime, nullptr);
3017     TEST_TIME(StringRef_NewFromUtf16_0);
3018 }
3019 
HWTEST_F_L0(JSNApiSplTest,StringRef_NewFromUtf16_3)3020 HWTEST_F_L0(JSNApiSplTest, StringRef_NewFromUtf16_3)
3021 {
3022     LocalScope scope(vm_);
3023     CalculateForTime();
3024     const char16_t *utf16 = u"您好,华为!";
3025     gettimeofday(&g_beginTime, nullptr);
3026     for (int i = 0; i < NUM_COUNT; i++) {
3027         Local<StringRef> local = StringRef::NewFromUtf16(vm_, utf16, 3);
3028         UNUSED(local);
3029     }
3030     gettimeofday(&g_endTime, nullptr);
3031     TEST_TIME(StringRef_NewFromUtf16_3);
3032 }
3033 
HWTEST_F_L0(JSNApiSplTest,StringRef_ToString)3034 HWTEST_F_L0(JSNApiSplTest, StringRef_ToString)
3035 {
3036     LocalScope scope(vm_);
3037     CalculateForTime();
3038     Local<StringRef> local = StringRef::NewFromUtf8(vm_, "abcdefbb");
3039     gettimeofday(&g_beginTime, nullptr);
3040     for (int i = 0; i < NUM_COUNT; i++) {
3041         std::string str = local->ToString(vm_);
3042         UNUSED(str);
3043     }
3044     gettimeofday(&g_endTime, nullptr);
3045     TEST_TIME(StringRef_ToString);
3046 }
3047 
HWTEST_F_L0(JSNApiSplTest,StringRef_Length)3048 HWTEST_F_L0(JSNApiSplTest, StringRef_Length)
3049 {
3050     LocalScope scope(vm_);
3051     CalculateForTime();
3052     Local<StringRef> local = StringRef::NewFromUtf8(vm_, "abcdefbb");
3053     gettimeofday(&g_beginTime, nullptr);
3054     for (int i = 0; i < NUM_COUNT; i++) {
3055         uint32_t length = local->Length(vm_);
3056         UNUSED(length);
3057     }
3058     gettimeofday(&g_endTime, nullptr);
3059     TEST_TIME(StringRef_Length);
3060 }
3061 
HWTEST_F_L0(JSNApiSplTest,StringRef_Utf8Length)3062 HWTEST_F_L0(JSNApiSplTest, StringRef_Utf8Length)
3063 {
3064     LocalScope scope(vm_);
3065     CalculateForTime();
3066     Local<StringRef> local = StringRef::NewFromUtf8(vm_, "abcdefbb");
3067     gettimeofday(&g_beginTime, nullptr);
3068     for (int i = 0; i < NUM_COUNT; i++) {
3069         uint32_t length = local->Utf8Length(vm_);
3070         UNUSED(length);
3071     }
3072     gettimeofday(&g_endTime, nullptr);
3073     TEST_TIME(StringRef_Utf8Length);
3074 }
3075 
HWTEST_F_L0(JSNApiSplTest,StringRef_WriteUtf8)3076 HWTEST_F_L0(JSNApiSplTest, StringRef_WriteUtf8)
3077 {
3078     LocalScope scope(vm_);
3079     CalculateForTime();
3080     Local<StringRef> local = StringRef::NewFromUtf8(vm_, "abcdefbb");
3081     char cs[16] = {0};
3082     gettimeofday(&g_beginTime, nullptr);
3083     for (int i = 0; i < NUM_COUNT; i++) {
3084         int length = local->WriteUtf8(vm_, cs, 6);
3085         UNUSED(length);
3086     }
3087     gettimeofday(&g_endTime, nullptr);
3088     TEST_TIME(StringRef_WriteUtf8);
3089 }
3090 
HWTEST_F_L0(JSNApiSplTest,StringRef_WriteUtf8_all)3091 HWTEST_F_L0(JSNApiSplTest, StringRef_WriteUtf8_all)
3092 {
3093     LocalScope scope(vm_);
3094     CalculateForTime();
3095     Local<StringRef> local = StringRef::NewFromUtf8(vm_, "abcdefbb");
3096     char cs[16] = {0}; // 16 = The size of the character array
3097     gettimeofday(&g_beginTime, nullptr);
3098     for (int i = 0; i < NUM_COUNT; i++) {
3099         int length = local->WriteUtf8(vm_, cs, local->Length(vm_));
3100         UNUSED(length);
3101     }
3102     gettimeofday(&g_endTime, nullptr);
3103     TEST_TIME(StringRef_WriteUtf8_all);
3104 }
3105 
HWTEST_F_L0(JSNApiSplTest,StringRef_WriteUtf8_0)3106 HWTEST_F_L0(JSNApiSplTest, StringRef_WriteUtf8_0)
3107 {
3108     LocalScope scope(vm_);
3109     CalculateForTime();
3110     Local<StringRef> local = StringRef::NewFromUtf8(vm_, "abcdefbb");
3111     char cs[16] = {0}; // 16 = The size of the character array
3112     gettimeofday(&g_beginTime, nullptr);
3113     for (int i = 0; i < NUM_COUNT; i++) {
3114         int length = local->WriteUtf8(vm_, cs, 0);
3115         UNUSED(length);
3116     }
3117     gettimeofday(&g_endTime, nullptr);
3118     TEST_TIME(StringRef_WriteUtf8_0);
3119 }
3120 
HWTEST_F_L0(JSNApiSplTest,StringRef_WriteUtf8_true)3121 HWTEST_F_L0(JSNApiSplTest, StringRef_WriteUtf8_true)
3122 {
3123     LocalScope scope(vm_);
3124     CalculateForTime();
3125     Local<StringRef> local = StringRef::NewFromUtf8(vm_, "abcdefbb");
3126     char cs[16] = {0}; // 16 =The size of the character array
3127     gettimeofday(&g_beginTime, nullptr);
3128     for (int i = 0; i < NUM_COUNT; i++) {
3129         int length = local->WriteUtf8(vm_, cs, 6, true);
3130         UNUSED(length);
3131     }
3132     gettimeofday(&g_endTime, nullptr);
3133     TEST_TIME(StringRef_WriteUtf8_true);
3134 }
3135 
HWTEST_F_L0(JSNApiSplTest,StringRef_WriteUtf8_all_true)3136 HWTEST_F_L0(JSNApiSplTest, StringRef_WriteUtf8_all_true)
3137 {
3138     LocalScope scope(vm_);
3139     CalculateForTime();
3140     Local<StringRef> local = StringRef::NewFromUtf8(vm_, "abcdefbb");
3141     char cs[16] = {0}; // 16 = The size of the character array
3142     gettimeofday(&g_beginTime, nullptr);
3143     for (int i = 0; i < NUM_COUNT; i++) {
3144         int length = local->WriteUtf8(vm_, cs, local->Length(vm_), true);
3145         UNUSED(length);
3146     }
3147     gettimeofday(&g_endTime, nullptr);
3148     TEST_TIME(StringRef_WriteUtf8_all_true);
3149 }
3150 
HWTEST_F_L0(JSNApiSplTest,StringRef_WriteUtf16)3151 HWTEST_F_L0(JSNApiSplTest, StringRef_WriteUtf16)
3152 {
3153     LocalScope scope(vm_);
3154     CalculateForTime();
3155     Local<StringRef> local = StringRef::NewFromUtf16(vm_, u"您好,华为!");
3156     char16_t cs[16] = {0}; // 16 = The size of the character array
3157     gettimeofday(&g_beginTime, nullptr);
3158     for (int i = 0; i < NUM_COUNT; i++) {
3159         int length = local->WriteUtf16(vm_, cs, 3);
3160         UNUSED(length);
3161     }
3162     gettimeofday(&g_endTime, nullptr);
3163     TEST_TIME(StringRef_WriteUtf16);
3164 }
3165 
HWTEST_F_L0(JSNApiSplTest,StringRef_WriteLatin1)3166 HWTEST_F_L0(JSNApiSplTest, StringRef_WriteLatin1)
3167 {
3168     LocalScope scope(vm_);
3169     CalculateForTime();
3170     Local<StringRef> local = StringRef::NewFromUtf8(vm_, "abcdefbb");
3171     char cs[16] = {0}; // 16 = The size of the character array
3172     gettimeofday(&g_beginTime, nullptr);
3173     for (int i = 0; i < NUM_COUNT; i++) {
3174         int length = local->WriteLatin1(vm_, cs, 8);
3175         UNUSED(length);
3176     }
3177     gettimeofday(&g_endTime, nullptr);
3178     TEST_TIME(StringRef_WriteLatin1);
3179 }
3180 
HWTEST_F_L0(JSNApiSplTest,StringRef_GetNapiWrapperString)3181 HWTEST_F_L0(JSNApiSplTest, StringRef_GetNapiWrapperString)
3182 {
3183     LocalScope scope(vm_);
3184     CalculateForTime();
3185     gettimeofday(&g_beginTime, nullptr);
3186     for (int i = 0; i < NUM_COUNT; i++) {
3187         Local<StringRef> local = StringRef::GetNapiWrapperString(vm_);
3188         UNUSED(local);
3189     }
3190     gettimeofday(&g_endTime, nullptr);
3191     TEST_TIME(StringRef_GetNapiWrapperString);
3192 }
3193 
HWTEST_F_L0(JSNApiSplTest,JSNApi_IsMixedDebugEnabled)3194 HWTEST_F_L0(JSNApiSplTest, JSNApi_IsMixedDebugEnabled)
3195 {
3196     LocalScope scope(vm_);
3197     CalculateForTime();
3198     gettimeofday(&g_beginTime, nullptr);
3199     for (int i = 0; i < NUM_COUNT; i++) {
3200         bool b = JSNApi::IsMixedDebugEnabled(vm_);
3201         UNUSED(b);
3202     }
3203     gettimeofday(&g_endTime, nullptr);
3204     TEST_TIME(JSNApi_IsMixedDebugEnabled);
3205 }
3206 
HWTEST_F_L0(JSNApiSplTest,JSNApi_NotifyNativeCalling_Int)3207 HWTEST_F_L0(JSNApiSplTest, JSNApi_NotifyNativeCalling_Int)
3208 {
3209     LocalScope scope(vm_);
3210     CalculateForTime();
3211     void *par = new int(0);
3212     gettimeofday(&g_beginTime, nullptr);
3213     for (int i = 0; i < NUM_COUNT; i++) {
3214         JSNApi::NotifyNativeCalling(vm_, par);
3215     }
3216     gettimeofday(&g_endTime, nullptr);
3217     TEST_TIME(JSNApi_NotifyNativeCalling_Int);
3218 }
3219 
HWTEST_F_L0(JSNApiSplTest,JSNApi_NotifyNativeCalling_String)3220 HWTEST_F_L0(JSNApiSplTest, JSNApi_NotifyNativeCalling_String)
3221 {
3222     LocalScope scope(vm_);
3223     CalculateForTime();
3224     void *par = new std::string("abc");
3225     gettimeofday(&g_beginTime, nullptr);
3226     for (int i = 0; i < NUM_COUNT; i++) {
3227         JSNApi::NotifyNativeCalling(vm_, par);
3228     }
3229     gettimeofday(&g_endTime, nullptr);
3230     TEST_TIME(JSNApi_NotifyNativeCalling_String);
3231 }
3232 
HWTEST_F_L0(JSNApiSplTest,JSNApi_NotifyNativeCalling_Char)3233 HWTEST_F_L0(JSNApiSplTest, JSNApi_NotifyNativeCalling_Char)
3234 {
3235     LocalScope scope(vm_);
3236     CalculateForTime();
3237     void *par = new char('a');
3238     gettimeofday(&g_beginTime, nullptr);
3239     for (int i = 0; i < NUM_COUNT; i++) {
3240         JSNApi::NotifyNativeCalling(vm_, par);
3241     }
3242     gettimeofday(&g_endTime, nullptr);
3243     TEST_TIME(JSNApi_NotifyNativeCalling_Char);
3244 }
3245 
HWTEST_F_L0(JSNApiSplTest,JSNApi_NotifyNativeCalling_Long)3246 HWTEST_F_L0(JSNApiSplTest, JSNApi_NotifyNativeCalling_Long)
3247 {
3248     LocalScope scope(vm_);
3249     CalculateForTime();
3250     void *par = new long(123456); // 123456 = random number
3251     gettimeofday(&g_beginTime, nullptr);
3252     for (int i = 0; i < NUM_COUNT; i++) {
3253         JSNApi::NotifyNativeCalling(vm_, par);
3254     }
3255     gettimeofday(&g_endTime, nullptr);
3256     TEST_TIME(JSNApi_NotifyNativeCalling_Long);
3257 }
3258 
HWTEST_F_L0(JSNApiSplTest,JSNApi_NotifyNativeCalling_Nullptr)3259 HWTEST_F_L0(JSNApiSplTest, JSNApi_NotifyNativeCalling_Nullptr)
3260 {
3261     LocalScope scope(vm_);
3262     CalculateForTime();
3263     void *par = nullptr;
3264     gettimeofday(&g_beginTime, nullptr);
3265     for (int i = 0; i < NUM_COUNT; i++) {
3266         JSNApi::NotifyNativeCalling(vm_, par);
3267     }
3268     gettimeofday(&g_endTime, nullptr);
3269     TEST_TIME(JSNApi_NotifyNativeCalling_Nullptr);
3270 }
3271 
HWTEST_F_L0(JSNApiSplTest,JSNApi_SerializeValue_Bool)3272 HWTEST_F_L0(JSNApiSplTest, JSNApi_SerializeValue_Bool)
3273 {
3274     LocalScope scope(vm_);
3275     CalculateForTime();
3276     Local<JSValueRef> value = BooleanRef::New(vm_, true);
3277     Local<JSValueRef> transfer = JSValueRef::Undefined(vm_);
3278     gettimeofday(&g_beginTime, nullptr);
3279     for (int i = 0; i < NUM_COUNT; i++) {
3280         void *ptr = JSNApi::SerializeValue(vm_, value, transfer, JSValueRef::Undefined(vm_));
3281         UNUSED(ptr);
3282     }
3283     gettimeofday(&g_endTime, nullptr);
3284     TEST_TIME(JSNApi_SerializeValue_Bool);
3285 }
3286 
HWTEST_F_L0(JSNApiSplTest,JSNApi_SerializeValue_Int)3287 HWTEST_F_L0(JSNApiSplTest, JSNApi_SerializeValue_Int)
3288 {
3289     LocalScope scope(vm_);
3290     CalculateForTime();
3291     int num = 123; // 123 = random number
3292     Local<JSValueRef> value = IntegerRef::New(vm_, num);
3293     Local<JSValueRef> transfer = JSValueRef::Undefined(vm_);
3294     gettimeofday(&g_beginTime, nullptr);
3295     for (int i = 0; i < NUM_COUNT; i++) {
3296         void *ptr = JSNApi::SerializeValue(vm_, value, transfer, JSValueRef::Undefined(vm_));
3297         UNUSED(ptr);
3298     }
3299     gettimeofday(&g_endTime, nullptr);
3300     TEST_TIME(JSNApi_SerializeValue_Int);
3301 }
3302 
HWTEST_F_L0(JSNApiSplTest,JSNApi_SerializeValue_String)3303 HWTEST_F_L0(JSNApiSplTest, JSNApi_SerializeValue_String)
3304 {
3305     LocalScope scope(vm_);
3306     CalculateForTime();
3307     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "abcdefbb");
3308     Local<JSValueRef> transfer = JSValueRef::Undefined(vm_);
3309     gettimeofday(&g_beginTime, nullptr);
3310     for (int i = 0; i < NUM_COUNT; i++) {
3311         void *ptr = JSNApi::SerializeValue(vm_, value, transfer, JSValueRef::Undefined(vm_));
3312         UNUSED(ptr);
3313     }
3314     gettimeofday(&g_endTime, nullptr);
3315     TEST_TIME(JSNApi_SerializeValue_String);
3316 }
3317 
HWTEST_F_L0(JSNApiSplTest,JSNApi_SerializeValue_String2)3318 HWTEST_F_L0(JSNApiSplTest, JSNApi_SerializeValue_String2)
3319 {
3320     LocalScope scope(vm_);
3321     CalculateForTime();
3322     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "abcdefbb");
3323     gettimeofday(&g_beginTime, nullptr);
3324     for (int i = 0; i < NUM_COUNT; i++) {
3325         void *ptr = JSNApi::SerializeValue(vm_, value, JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_), true);
3326         UNUSED(ptr);
3327     }
3328     gettimeofday(&g_endTime, nullptr);
3329     TEST_TIME(JSNApi_SerializeValue_String2);
3330 }
3331 
HWTEST_F_L0(JSNApiSplTest,JSNApi_SerializeValue_String3)3332 HWTEST_F_L0(JSNApiSplTest, JSNApi_SerializeValue_String3)
3333 {
3334     LocalScope scope(vm_);
3335     CalculateForTime();
3336     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "abcdefbb");
3337     Local<JSValueRef> transfer = JSValueRef::Undefined(vm_);
3338     gettimeofday(&g_beginTime, nullptr);
3339     for (int i = 0; i < NUM_COUNT; i++) {
3340         void *ptr = JSNApi::SerializeValue(vm_, value, transfer, JSValueRef::Undefined(vm_));
3341         UNUSED(ptr);
3342     }
3343     gettimeofday(&g_endTime, nullptr);
3344     TEST_TIME(JSNApi_SerializeValue_String3);
3345 }
3346 
HWTEST_F_L0(JSNApiSplTest,JSNApi_SerializeValue_String_Bool)3347 HWTEST_F_L0(JSNApiSplTest, JSNApi_SerializeValue_String_Bool)
3348 {
3349     LocalScope scope(vm_);
3350     CalculateForTime();
3351     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "abcdefbb");
3352     Local<JSValueRef> transfer = JSValueRef::Undefined(vm_);
3353     gettimeofday(&g_beginTime, nullptr);
3354     for (int i = 0; i < NUM_COUNT; i++) {
3355         void *ptr = JSNApi::SerializeValue(vm_, value, transfer, JSValueRef::Undefined(vm_));
3356         UNUSED(ptr);
3357     }
3358     gettimeofday(&g_endTime, nullptr);
3359     TEST_TIME(JSNApi_SerializeValue_String_Bool);
3360 }
3361 
HWTEST_F_L0(JSNApiSplTest,JSNApi_DeserializeValue_String)3362 HWTEST_F_L0(JSNApiSplTest, JSNApi_DeserializeValue_String)
3363 {
3364     LocalScope scope(vm_);
3365     CalculateForTime();
3366     EcmaVM *vm2 = JSNApi::CreateJSVM(RuntimeOption());
3367     gettimeofday(&g_beginTime, nullptr);
3368     for (int i = 0; i < NUM_COUNT; i++) {
3369         void *recoder = JSNApi::SerializeValue(vm_, StringRef::NewFromUtf8(vm_, "abcdefbb"), JSValueRef::Undefined(vm_),
3370             JSValueRef::Undefined(vm_));
3371         void *hint = nullptr;
3372         Local<JSValueRef> local = JSNApi::DeserializeValue(vm2, recoder, hint);
3373         UNUSED(local);
3374     }
3375     gettimeofday(&g_endTime, nullptr);
3376     JSNApi::DestroyJSVM(vm2);
3377     TEST_TIME(JSNApi_DeserializeValue_String);
3378 }
3379 
HWTEST_F_L0(JSNApiSplTest,JSNApi_DeserializeValue_Bool)3380 HWTEST_F_L0(JSNApiSplTest, JSNApi_DeserializeValue_Bool)
3381 {
3382     LocalScope scope(vm_);
3383     CalculateForTime();
3384     EcmaVM *vm2 = JSNApi::CreateJSVM(RuntimeOption());
3385     gettimeofday(&g_beginTime, nullptr);
3386     for (int i = 0; i < NUM_COUNT; i++) {
3387         void *recoder = JSNApi::SerializeValue(vm_, BooleanRef::New(vm_, true), JSValueRef::Undefined(vm_),
3388             JSValueRef::Undefined(vm_));
3389         void *hint = nullptr;
3390         Local<JSValueRef> local = JSNApi::DeserializeValue(vm2, recoder, hint);
3391         UNUSED(local);
3392     }
3393     gettimeofday(&g_endTime, nullptr);
3394     JSNApi::DestroyJSVM(vm2);
3395     TEST_TIME(JSNApi_DeserializeValue_Bool);
3396 }
3397 
HWTEST_F_L0(JSNApiSplTest,JSNApi_DeserializeValue_Int)3398 HWTEST_F_L0(JSNApiSplTest, JSNApi_DeserializeValue_Int)
3399 {
3400     LocalScope scope(vm_);
3401     CalculateForTime();
3402     EcmaVM *vm2 = JSNApi::CreateJSVM(RuntimeOption());
3403     gettimeofday(&g_beginTime, nullptr);
3404     for (int i = 0; i < NUM_COUNT; i++) {
3405         void *recoder = JSNApi::SerializeValue(vm_, IntegerRef::New(vm_, 123), JSValueRef::Undefined(vm_),
3406             JSValueRef::Undefined(vm_));
3407         void *hint = nullptr;
3408         Local<JSValueRef> local = JSNApi::DeserializeValue(vm2, recoder, hint);
3409         UNUSED(local);
3410     }
3411     gettimeofday(&g_endTime, nullptr);
3412     JSNApi::DestroyJSVM(vm2);
3413     TEST_TIME(JSNApi_DeserializeValue_Int);
3414 }
3415 
HWTEST_F_L0(JSNApiSplTest,JSNApi_DeserializeValue_Undefined)3416 HWTEST_F_L0(JSNApiSplTest, JSNApi_DeserializeValue_Undefined)
3417 {
3418     LocalScope scope(vm_);
3419     CalculateForTime();
3420     EcmaVM *vm2 = JSNApi::CreateJSVM(RuntimeOption());
3421     gettimeofday(&g_beginTime, nullptr);
3422     for (int i = 0; i < NUM_COUNT; i++) {
3423         void *recoder = JSNApi::SerializeValue(vm_, JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_),
3424             JSValueRef::Undefined(vm_));
3425         void *hint = nullptr;
3426         Local<JSValueRef> local = JSNApi::DeserializeValue(vm2, recoder, hint);
3427         UNUSED(local);
3428     }
3429     gettimeofday(&g_endTime, nullptr);
3430     JSNApi::DestroyJSVM(vm2);
3431     TEST_TIME(JSNApi_DeserializeValue_Undefined);
3432 }
3433 
HWTEST_F_L0(JSNApiSplTest,JSNApi_DeserializeValue_Null)3434 HWTEST_F_L0(JSNApiSplTest, JSNApi_DeserializeValue_Null)
3435 {
3436     LocalScope scope(vm_);
3437     CalculateForTime();
3438     EcmaVM *vm2 = JSNApi::CreateJSVM(RuntimeOption());
3439     gettimeofday(&g_beginTime, nullptr);
3440     for (int i = 0; i < NUM_COUNT; i++) {
3441         void *recoder =
3442             JSNApi::SerializeValue(vm_, JSValueRef::Null(vm_), JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_));
3443         void *hint = nullptr;
3444         Local<JSValueRef> local = JSNApi::DeserializeValue(vm2, recoder, hint);
3445         UNUSED(local);
3446     }
3447     gettimeofday(&g_endTime, nullptr);
3448     JSNApi::DestroyJSVM(vm2);
3449     TEST_TIME(JSNApi_DeserializeValue_Null);
3450 }
3451 
HWTEST_F_L0(JSNApiSplTest,JSNApi_DeleteSerializationData_String)3452 HWTEST_F_L0(JSNApiSplTest, JSNApi_DeleteSerializationData_String)
3453 {
3454     LocalScope scope(vm_);
3455     CalculateForTime();
3456     gettimeofday(&g_beginTime, nullptr);
3457     for (int i = 0; i < NUM_COUNT; i++) {
3458         void *data = JSNApi::SerializeValue(vm_, StringRef::NewFromUtf8(vm_, "abcdefbb"),
3459             StringRef::NewFromUtf8(vm_, "abcdefbb"), JSValueRef::Undefined(vm_));
3460         JSNApi::DeleteSerializationData(data);
3461     }
3462     gettimeofday(&g_endTime, nullptr);
3463     TEST_TIME(JSNApi_DeleteSerializationData_String);
3464 }
3465 
HWTEST_F_L0(JSNApiSplTest,JSNApi_DeleteSerializationData_Bool)3466 HWTEST_F_L0(JSNApiSplTest, JSNApi_DeleteSerializationData_Bool)
3467 {
3468     LocalScope scope(vm_);
3469     CalculateForTime();
3470     gettimeofday(&g_beginTime, nullptr);
3471     for (int i = 0; i < NUM_COUNT; i++) {
3472         void *data = JSNApi::SerializeValue(vm_, BooleanRef::New(vm_, true), JSValueRef::Undefined(vm_),
3473             JSValueRef::Undefined(vm_));
3474         JSNApi::DeleteSerializationData(data);
3475     }
3476     gettimeofday(&g_endTime, nullptr);
3477     TEST_TIME(JSNApi_DeleteSerializationData_Bool);
3478 }
3479 
HWTEST_F_L0(JSNApiSplTest,JSNApi_DeleteSerializationData_Int)3480 HWTEST_F_L0(JSNApiSplTest, JSNApi_DeleteSerializationData_Int)
3481 {
3482     LocalScope scope(vm_);
3483     CalculateForTime();
3484     gettimeofday(&g_beginTime, nullptr);
3485     for (int i = 0; i < NUM_COUNT; i++) {
3486         void *data = JSNApi::SerializeValue(vm_, BooleanRef::New(vm_, true), JSValueRef::Undefined(vm_),
3487             JSValueRef::Undefined(vm_));
3488         JSNApi::DeleteSerializationData(data);
3489     }
3490     gettimeofday(&g_endTime, nullptr);
3491     TEST_TIME(JSNApi_DeleteSerializationData_Int);
3492 }
3493 
HWTEST_F_L0(JSNApiSplTest,JSNApi_DeleteSerializationData_Undefined)3494 HWTEST_F_L0(JSNApiSplTest, JSNApi_DeleteSerializationData_Undefined)
3495 {
3496     LocalScope scope(vm_);
3497     CalculateForTime();
3498     gettimeofday(&g_beginTime, nullptr);
3499     for (int i = 0; i < NUM_COUNT; i++) {
3500         void *data = JSNApi::SerializeValue(vm_, JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_),
3501             JSValueRef::Undefined(vm_));
3502         JSNApi::DeleteSerializationData(data);
3503     }
3504     gettimeofday(&g_endTime, nullptr);
3505     TEST_TIME(JSNApi_DeleteSerializationData_Undefined);
3506 }
3507 
HWTEST_F_L0(JSNApiSplTest,JSNApi_DeleteSerializationData_Null)3508 HWTEST_F_L0(JSNApiSplTest, JSNApi_DeleteSerializationData_Null)
3509 {
3510     LocalScope scope(vm_);
3511     CalculateForTime();
3512     gettimeofday(&g_beginTime, nullptr);
3513     for (int i = 0; i < NUM_COUNT; i++) {
3514         void *data =
3515             JSNApi::SerializeValue(vm_, JSValueRef::Null(vm_), JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_));
3516         JSNApi::DeleteSerializationData(data);
3517     }
3518     gettimeofday(&g_endTime, nullptr);
3519     TEST_TIME(JSNApi_DeleteSerializationData_Null);
3520 }
3521 
HWTEST_F_L0(JSNApiSplTest,JSNApi_SetHostPromiseRejectionTracker)3522 HWTEST_F_L0(JSNApiSplTest, JSNApi_SetHostPromiseRejectionTracker)
3523 {
3524     LocalScope scope(vm_);
3525     CalculateForTime();
3526     void *data = reinterpret_cast<void *>(builtins::BuiltinsFunction::FunctionPrototypeInvokeSelf);
3527     gettimeofday(&g_beginTime, nullptr);
3528     for (int i = 0; i < NUM_COUNT; i++) {
3529         JSNApi::SetHostPromiseRejectionTracker(vm_, data, data);
3530     }
3531     gettimeofday(&g_endTime, nullptr);
3532     TEST_TIME(JSNApi_SetHostPromiseRejectionTracker);
3533 }
3534 
HWTEST_F_L0(JSNApiSplTest,JSNApi_SetHostResolveBufferTracker)3535 HWTEST_F_L0(JSNApiSplTest, JSNApi_SetHostResolveBufferTracker)
3536 {
3537     LocalScope scope(vm_);
3538     CalculateForTime();
3539     std::function<bool(std::string dirPath, uint8_t * *buff, size_t * buffSize, std::string &errorMsg)> cb =
3540         [](const std::string &inputPath, uint8_t **buff, size_t *buffSize, std::string &errorMsg) -> bool {
3541         if (inputPath.empty() || buff == nullptr || buffSize == nullptr) {
3542             return false;
3543         }
3544         return true;
3545     };
3546 
3547     gettimeofday(&g_beginTime, nullptr);
3548     for (int i = 0; i < NUM_COUNT; i++) {
3549         JSNApi::SetHostResolveBufferTracker(vm_, cb);
3550     }
3551     gettimeofday(&g_endTime, nullptr);
3552     TEST_TIME(JSNApi_SetHostResolveBufferTracker);
3553 }
3554 
NativePtrGetterCallback(void * info)3555 void *NativePtrGetterCallback(void *info)
3556 {
3557     return info;
3558 }
3559 
HWTEST_F_L0(JSNApiSplTest,JSNApi_SetNativePtrGetter)3560 HWTEST_F_L0(JSNApiSplTest, JSNApi_SetNativePtrGetter)
3561 {
3562     LocalScope scope(vm_);
3563     CalculateForTime();
3564     void *cb = reinterpret_cast<void *>(NativePtrGetterCallback);
3565     gettimeofday(&g_beginTime, nullptr);
3566     for (int i = 0; i < NUM_COUNT; i++) {
3567         JSNApi::SetNativePtrGetter(vm_, cb);
3568     }
3569     gettimeofday(&g_endTime, nullptr);
3570     TEST_TIME(JSNApi_SetNativePtrGetter);
3571 }
3572 
HostEnqueueJobCallback(JsiRuntimeCallInfo * callBackFunc)3573 Local<JSValueRef> HostEnqueueJobCallback([[maybe_unused]] JsiRuntimeCallInfo *callBackFunc)
3574 {
3575     Local<JSValueRef> local;
3576     return local;
3577 }
3578 
HWTEST_F_L0(JSNApiSplTest,JSNApi_SetHostEnqueueJob)3579 HWTEST_F_L0(JSNApiSplTest, JSNApi_SetHostEnqueueJob)
3580 {
3581     LocalScope scope(vm_);
3582     CalculateForTime();
3583     Local<JSValueRef> cb = FunctionRef::New(vm_, HostEnqueueJobCallback);
3584     gettimeofday(&g_beginTime, nullptr);
3585     for (int i = 0; i < NUM_COUNT; i++) {
3586         JSNApi::SetHostEnqueueJob(vm_, cb);
3587     }
3588     gettimeofday(&g_endTime, nullptr);
3589     TEST_TIME(JSNApi_SetHostEnqueueJob);
3590 }
3591 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsMapIterator_True)3592 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsMapIterator_True)
3593 {
3594     LocalScope scope(vm_);
3595     CalculateForTime();
3596     JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
3597     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
3598     JSHandle<JSTaggedValue> builtinsMapFunc = env->GetBuiltinsMapFunction();
3599     JSHandle<JSMap> jsMap(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(builtinsMapFunc), builtinsMapFunc));
3600     JSHandle<JSTaggedValue> linkedHashMap(LinkedHashMap::Create(thread_));
3601     jsMap->SetLinkedMap(thread_, linkedHashMap);
3602     JSHandle<JSTaggedValue> mapIteratorVal =
3603         JSMapIterator::CreateMapIterator(thread_, JSHandle<JSTaggedValue>::Cast(jsMap), IterationKind::KEY);
3604     Local<MapIteratorRef> object = JSNApiHelper::ToLocal<MapIteratorRef>(mapIteratorVal);
3605     gettimeofday(&g_beginTime, nullptr);
3606     for (int i = 0; i < NUM_COUNT; i++) {
3607         ASSERT_TRUE(object->IsMapIterator(vm_));
3608     }
3609     gettimeofday(&g_endTime, nullptr);
3610     TEST_TIME(JSValueRef::IsMapIterator);
3611 }
3612 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsMapIterator_False)3613 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsMapIterator_False)
3614 {
3615     LocalScope scope(vm_);
3616     CalculateForTime();
3617     int num = 10; // 10 = random number
3618     Local<JSValueRef> object = IntegerRef::New(vm_, num);
3619     gettimeofday(&g_beginTime, nullptr);
3620     for (int i = 0; i < NUM_COUNT; i++) {
3621         ASSERT_FALSE(object->IsMapIterator(vm_));
3622     }
3623     gettimeofday(&g_endTime, nullptr);
3624     TEST_TIME(JSValueRef::IsMapIterator);
3625 }
3626 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsUint8ClampedArray_True)3627 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsUint8ClampedArray_True)
3628 {
3629     LocalScope scope(vm_);
3630     CalculateForTime();
3631     int32_t length = 4;     // 4 = length
3632     int32_t byteOffset = 0; // 0 = length
3633     Local<ArrayBufferRef> buffer = ArrayBufferRef::New(vm_, length);
3634     Local<Uint8ClampedArrayRef> object = Uint8ClampedArrayRef::New(vm_, buffer, byteOffset, length);
3635     gettimeofday(&g_beginTime, nullptr);
3636     for (int i = 0; i < NUM_COUNT; i++) {
3637         ASSERT_TRUE(object->IsUint8ClampedArray(vm_));
3638     }
3639     gettimeofday(&g_endTime, nullptr);
3640     TEST_TIME(JSValueRef::IsUint8ClampedArray);
3641 }
3642 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsUint8ClampedArray_False)3643 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsUint8ClampedArray_False)
3644 {
3645     LocalScope scope(vm_);
3646     CalculateForTime();
3647     int num = 10; // 10 = random number
3648     Local<JSValueRef> object = IntegerRef::New(vm_, num);
3649     gettimeofday(&g_beginTime, nullptr);
3650     for (int i = 0; i < NUM_COUNT; i++) {
3651         ASSERT_FALSE(object->IsUint8ClampedArray(vm_));
3652     }
3653     gettimeofday(&g_endTime, nullptr);
3654     TEST_TIME(JSValueRef::IsUint8ClampedArray);
3655 }
3656 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsInt16Array_True)3657 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt16Array_True)
3658 {
3659     LocalScope scope(vm_);
3660     CalculateForTime();
3661     const int32_t length = 30; // 30 = length
3662     int32_t byteOffset = 4;    // 4 = offset
3663     int32_t len = 6;           // 6 = length
3664     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
3665     Local<Int16ArrayRef> object = Int16ArrayRef::New(vm_, arrayBuffer, byteOffset, len);
3666     gettimeofday(&g_beginTime, nullptr);
3667     for (int i = 0; i < NUM_COUNT; i++) {
3668         ASSERT_TRUE(object->IsInt16Array(vm_));
3669     }
3670     gettimeofday(&g_endTime, nullptr);
3671     TEST_TIME(JSValueRef::IsInt16Array);
3672 }
3673 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsInt16Array_False)3674 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt16Array_False)
3675 {
3676     LocalScope scope(vm_);
3677     CalculateForTime();
3678     int num = 10; // 10 = random number
3679     Local<JSValueRef> object = IntegerRef::New(vm_, num);
3680     gettimeofday(&g_beginTime, nullptr);
3681     for (int i = 0; i < NUM_COUNT; i++) {
3682         ASSERT_FALSE(object->IsInt16Array(vm_));
3683     }
3684     gettimeofday(&g_endTime, nullptr);
3685     TEST_TIME(JSValueRef::IsInt16Array);
3686 }
3687 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSPrimitiveNumber_True)3688 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPrimitiveNumber_True)
3689 {
3690     LocalScope scope(vm_);
3691     CalculateForTime();
3692     ObjectFactory *factory = vm_->GetFactory();
3693     JSHandle<JSTaggedValue> jsTagValue;
3694     JSHandle<JSPrimitiveRef> jsprimitive = factory->NewJSPrimitiveRef(PrimitiveType::PRIMITIVE_NUMBER, jsTagValue);
3695     JSHandle<JSTaggedValue> jspri = JSHandle<JSTaggedValue>::Cast(jsprimitive);
3696     Local<JSValueRef> object = JSNApiHelper::ToLocal<JSValueRef>(jspri);
3697     gettimeofday(&g_beginTime, nullptr);
3698     for (int i = 0; i < NUM_COUNT; i++) {
3699         object->IsJSPrimitiveNumber(vm_);
3700     }
3701     gettimeofday(&g_endTime, nullptr);
3702     TEST_TIME(JSValueRef::IsJSPrimitiveNumber);
3703 }
3704 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSPrimitiveNumber_False)3705 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPrimitiveNumber_False)
3706 {
3707     LocalScope scope(vm_);
3708     CalculateForTime();
3709     Local<JSValueRef> object = ObjectRef::New(vm_);
3710     gettimeofday(&g_beginTime, nullptr);
3711     for (int i = 0; i < NUM_COUNT; i++) {
3712         ASSERT_FALSE(object->IsJSPrimitiveNumber(vm_));
3713     }
3714     gettimeofday(&g_endTime, nullptr);
3715     TEST_TIME(JSValueRef::IsJSPrimitiveNumber);
3716 }
3717 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSPrimitiveInt_True)3718 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPrimitiveInt_True)
3719 {
3720     LocalScope scope(vm_);
3721     CalculateForTime();
3722     ObjectFactory *factory = vm_->GetFactory();
3723     JSHandle<JSTaggedValue> jsTagValue;
3724     JSHandle<JSPrimitiveRef> jsprimitive = factory->NewJSPrimitiveRef(PrimitiveType::PRIMITIVE_BIGINT, jsTagValue);
3725     JSHandle<JSTaggedValue> jspri = JSHandle<JSTaggedValue>::Cast(jsprimitive);
3726     Local<JSValueRef> object = JSNApiHelper::ToLocal<JSValueRef>(jspri);
3727     gettimeofday(&g_beginTime, nullptr);
3728     for (int i = 0; i < NUM_COUNT; i++) {
3729         object->IsJSPrimitiveInt(vm_);
3730     }
3731     gettimeofday(&g_endTime, nullptr);
3732     TEST_TIME(JSValueRef::IsJSPrimitiveInt);
3733 }
3734 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSPrimitiveBoolean_True)3735 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPrimitiveBoolean_True)
3736 {
3737     LocalScope scope(vm_);
3738     CalculateForTime();
3739     ObjectFactory *factory = vm_->GetFactory();
3740     JSHandle<JSTaggedValue> jsTagValue;
3741     JSHandle<JSPrimitiveRef> jsprimitive = factory->NewJSPrimitiveRef(PrimitiveType::PRIMITIVE_BOOLEAN, jsTagValue);
3742     JSHandle<JSTaggedValue> jspri = JSHandle<JSTaggedValue>::Cast(jsprimitive);
3743     Local<JSValueRef> object = JSNApiHelper::ToLocal<JSValueRef>(jspri);
3744     gettimeofday(&g_beginTime, nullptr);
3745     for (int i = 0; i < NUM_COUNT; i++) {
3746         object->IsJSPrimitiveBoolean(vm_);
3747     }
3748     gettimeofday(&g_endTime, nullptr);
3749     TEST_TIME(JSValueRef::IsJSPrimitiveBoolean);
3750 }
3751 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSPrimitiveBoolean_False)3752 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPrimitiveBoolean_False)
3753 {
3754     LocalScope scope(vm_);
3755     CalculateForTime();
3756     Local<JSValueRef> object = ObjectRef::New(vm_);
3757     gettimeofday(&g_beginTime, nullptr);
3758     for (int i = 0; i < NUM_COUNT; i++) {
3759         ASSERT_FALSE(object->IsJSPrimitiveBoolean(vm_));
3760     }
3761     gettimeofday(&g_endTime, nullptr);
3762     TEST_TIME(JSValueRef::IsJSPrimitiveBoolean);
3763 }
3764 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSCollator_True)3765 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSCollator_True)
3766 {
3767     LocalScope scope(vm_);
3768     CalculateForTime();
3769     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
3770     ObjectFactory *factory = vm_->GetFactory();
3771     JSHandle<JSTaggedValue> ctor = env->GetCollatorFunction();
3772     JSHandle<JSCollator> collator =
3773         JSHandle<JSCollator>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(ctor), ctor));
3774     JSHandle<JSTaggedValue> localeStr = thread_->GlobalConstants()->GetHandledEnUsString();
3775     JSHandle<JSTaggedValue> undefinedHandle(thread_, JSTaggedValue::Undefined());
3776     JSHandle<JSCollator> initCollator = JSCollator::InitializeCollator(thread_, collator, localeStr, undefinedHandle);
3777 
3778     JSHandle<JSTaggedValue> collatorTagHandleVal = JSHandle<JSTaggedValue>::Cast(initCollator);
3779     Local<JSValueRef> object = JSNApiHelper::ToLocal<JSValueRef>(collatorTagHandleVal);
3780     gettimeofday(&g_beginTime, nullptr);
3781     for (int i = 0; i < NUM_COUNT; i++) {
3782         ASSERT_TRUE(object->IsJSCollator(vm_));
3783     }
3784     gettimeofday(&g_endTime, nullptr);
3785     TEST_TIME(JSValueRef::IsJSCollator);
3786 }
3787 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSCollator_False)3788 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSCollator_False)
3789 {
3790     LocalScope scope(vm_);
3791     CalculateForTime();
3792     int num = 10; // 10 = random number
3793     Local<JSValueRef> object = IntegerRef::New(vm_, num);
3794     gettimeofday(&g_beginTime, nullptr);
3795     for (int i = 0; i < NUM_COUNT; i++) {
3796         ASSERT_FALSE(object->IsJSCollator(vm_));
3797     }
3798     gettimeofday(&g_endTime, nullptr);
3799     TEST_TIME(JSValueRef::IsJSCollator);
3800 }
3801 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSPluralRules_True)3802 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPluralRules_True)
3803 {
3804     LocalScope scope(vm_);
3805     CalculateForTime();
3806     ObjectFactory *factory = vm_->GetFactory();
3807     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
3808     JSHandle<JSTaggedValue> optionHandle(thread_, JSTaggedValue::Undefined());
3809     JSHandle<JSTaggedValue> ctor = env->GetPluralRulesFunction();
3810     JSHandle<JSPluralRules> pluralRules =
3811         JSHandle<JSPluralRules>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(ctor), ctor));
3812     JSHandle<JSTaggedValue> localeStr(factory->NewFromASCII("en-GB"));
3813     JSHandle<JSPluralRules> initPluralRules =
3814         JSPluralRules::InitializePluralRules(thread_, pluralRules, localeStr, optionHandle);
3815     JSHandle<JSTaggedValue> tagPlureRules = JSHandle<JSTaggedValue>::Cast(initPluralRules);
3816     Local<JSValueRef> object = JSNApiHelper::ToLocal<JSValueRef>(tagPlureRules);
3817     gettimeofday(&g_beginTime, nullptr);
3818     for (int i = 0; i < NUM_COUNT; i++) {
3819         ASSERT_TRUE(object->IsJSPluralRules(vm_));
3820     }
3821     gettimeofday(&g_endTime, nullptr);
3822     TEST_TIME(JSValueRef::IsJSPluralRules);
3823 }
3824 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSPluralRules_False)3825 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPluralRules_False)
3826 {
3827     LocalScope scope(vm_);
3828     CalculateForTime();
3829     int num = 10; // 10 = random number
3830     Local<JSValueRef> object = IntegerRef::New(vm_, num);
3831     gettimeofday(&g_beginTime, nullptr);
3832     for (int i = 0; i < NUM_COUNT; i++) {
3833         ASSERT_FALSE(object->IsJSPluralRules(vm_));
3834     }
3835     gettimeofday(&g_endTime, nullptr);
3836     TEST_TIME(JSValueRef::IsJSPluralRules);
3837 }
3838 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSListFormat_False)3839 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSListFormat_False)
3840 {
3841     LocalScope scope(vm_);
3842     CalculateForTime();
3843     int num = 10; // 10 = random number
3844     Local<JSValueRef> object = IntegerRef::New(vm_, num);
3845     gettimeofday(&g_beginTime, nullptr);
3846     for (int i = 0; i < NUM_COUNT; i++) {
3847         ASSERT_FALSE(object->IsJSListFormat(vm_));
3848     }
3849     gettimeofday(&g_endTime, nullptr);
3850     TEST_TIME(JSValueRef::IsJSListFormat);
3851 }
3852 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsAsyncGeneratorFunction_True)3853 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsAsyncGeneratorFunction_True)
3854 {
3855     LocalScope scope(vm_);
3856     CalculateForTime();
3857     ObjectFactory *factory = vm_->GetFactory();
3858     MethodLiteral *methodLiteral = nullptr;
3859     JSHandle<Method> method = factory->NewSMethod(methodLiteral);
3860     JSHandle<JSFunction> asyncGeneratorFunction = factory->NewJSAsyncGeneratorFunction(method);
3861     JSHandle<JSTaggedValue> asyncgefu = JSHandle<JSTaggedValue>::Cast(asyncGeneratorFunction);
3862     Local<JSValueRef> object = JSNApiHelper::ToLocal<JSValueRef>(asyncgefu);
3863     gettimeofday(&g_beginTime, nullptr);
3864     for (int i = 0; i < NUM_COUNT; i++) {
3865         ASSERT_TRUE(object->IsAsyncGeneratorFunction(vm_));
3866     }
3867     gettimeofday(&g_endTime, nullptr);
3868     TEST_TIME(JSValueRef::IsAsyncGeneratorFunction);
3869 }
3870 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsAsyncGeneratorFunction_False)3871 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsAsyncGeneratorFunction_False)
3872 {
3873     LocalScope scope(vm_);
3874     CalculateForTime();
3875     int num = 10; // 10 = random number
3876     Local<JSValueRef> object = IntegerRef::New(vm_, num);
3877     gettimeofday(&g_beginTime, nullptr);
3878     for (int i = 0; i < NUM_COUNT; i++) {
3879         ASSERT_FALSE(object->IsAsyncGeneratorFunction(vm_));
3880     }
3881     gettimeofday(&g_endTime, nullptr);
3882     TEST_TIME(JSValueRef::IsAsyncGeneratorFunction);
3883 }
3884 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsLinkedList_True)3885 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsLinkedList_True)
3886 {
3887     LocalScope scope(vm_);
3888     CalculateForTime();
3889     ObjectFactory *factory = vm_->GetFactory();
3890     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
3891     JSHandle<JSTaggedValue> globalObject = env->GetJSGlobalObject();
3892     JSHandle<JSTaggedValue> key(factory->NewFromASCII("ArkPrivate"));
3893     JSHandle<JSTaggedValue> value =
3894         JSObject::GetProperty(thread_, JSHandle<JSTaggedValue>(globalObject), key).GetValue();
3895     auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6);
3896     objCallInfo->SetFunction(JSTaggedValue::Undefined());
3897     objCallInfo->SetThis(value.GetTaggedValue());
3898     objCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int>(containers::ContainerTag::LinkedList)));
3899     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo);
3900     JSHandle<JSTaggedValue> contianer =
3901         JSHandle<JSTaggedValue>(thread_, containers::ContainersPrivate::Load(objCallInfo));
3902     JSHandle<JSAPILinkedList> linkedList =
3903         JSHandle<JSAPILinkedList>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(contianer), contianer));
3904     JSTaggedValue doubleList = TaggedDoubleList::Create(thread_);
3905     linkedList->SetDoubleList(thread_, doubleList);
3906     JSHandle<JSTaggedValue> linkedListTag = JSHandle<JSTaggedValue>::Cast(linkedList);
3907     Local<JSValueRef> object = JSNApiHelper::ToLocal<JSValueRef>(linkedListTag);
3908     gettimeofday(&g_beginTime, nullptr);
3909     for (int i = 0; i < NUM_COUNT; i++) {
3910         ASSERT_TRUE(object->IsLinkedList(vm_));
3911     }
3912     gettimeofday(&g_endTime, nullptr);
3913     TEST_TIME(JSValueRef::IsLinkedList);
3914 }
3915 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsLinkedList_False)3916 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsLinkedList_False)
3917 {
3918     LocalScope scope(vm_);
3919     CalculateForTime();
3920     int num = 10; // 10 = random number
3921     Local<JSValueRef> object = IntegerRef::New(vm_, num);
3922     gettimeofday(&g_beginTime, nullptr);
3923     for (int i = 0; i < NUM_COUNT; i++) {
3924         ASSERT_FALSE(object->IsLinkedList(vm_));
3925     }
3926     gettimeofday(&g_endTime, nullptr);
3927     TEST_TIME(JSValueRef::IsLinkedList);
3928 }
3929 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsLinkedListIterator_True)3930 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsLinkedListIterator_True)
3931 {
3932     LocalScope scope(vm_);
3933     CalculateForTime();
3934     ObjectFactory *factory = vm_->GetFactory();
3935     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
3936     JSHandle<JSTaggedValue> globalObject = env->GetJSGlobalObject();
3937     JSHandle<JSTaggedValue> key(factory->NewFromASCII("ArkPrivate"));
3938     JSHandle<JSTaggedValue> tagvalue =
3939         JSObject::GetProperty(thread_, JSHandle<JSTaggedValue>(globalObject), key).GetValue();
3940     uint32_t argvLength = 6; // 6 = argv length
3941     auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), argvLength);
3942     objCallInfo->SetFunction(JSTaggedValue::Undefined());
3943     objCallInfo->SetThis(tagvalue.GetTaggedValue());
3944     objCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int>(containers::ContainerTag::LinkedList)));
3945     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo);
3946     JSHandle<JSTaggedValue> contianer =
3947         JSHandle<JSTaggedValue>(thread_, containers::ContainersPrivate::Load(objCallInfo));
3948     JSHandle<JSAPILinkedList> linkedList =
3949         JSHandle<JSAPILinkedList>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(contianer), contianer));
3950     JSTaggedValue doubleList = TaggedDoubleList::Create(thread_);
3951     linkedList->SetDoubleList(thread_, doubleList);
3952     uint32_t elementsNum = 256; // 256 = Number of cycles
3953     for (uint32_t i = 0; i < elementsNum; i++) {
3954         JSHandle<JSTaggedValue> taggedvalue(thread_, JSTaggedValue(i));
3955         JSAPILinkedList::Add(thread_, linkedList, taggedvalue);
3956     }
3957     JSHandle<JSTaggedValue> taggedValueHandle(thread_, linkedList.GetTaggedValue());
3958     JSHandle<JSAPILinkedListIterator> linkedListIterator(thread_,
3959         JSAPILinkedListIterator::CreateLinkedListIterator(thread_, taggedValueHandle).GetTaggedValue());
3960     JSHandle<JSTaggedValue> linkedListIteratortag = JSHandle<JSTaggedValue>::Cast(linkedListIterator);
3961     Local<JSValueRef> object = JSNApiHelper::ToLocal<JSValueRef>(linkedListIteratortag);
3962     gettimeofday(&g_beginTime, nullptr);
3963     for (int i = 0; i < NUM_COUNT; i++) {
3964         ASSERT_TRUE(object->IsLinkedListIterator(vm_));
3965     }
3966     gettimeofday(&g_endTime, nullptr);
3967     TEST_TIME(JSValueRef::IsLinkedListIterator);
3968 }
3969 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsLinkedListIterator_False)3970 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsLinkedListIterator_False)
3971 {
3972     LocalScope scope(vm_);
3973     CalculateForTime();
3974     int num = 10; // 10 = random number
3975     Local<JSValueRef> object = IntegerRef::New(vm_, num);
3976     gettimeofday(&g_beginTime, nullptr);
3977     for (int i = 0; i < NUM_COUNT; i++) {
3978         ASSERT_FALSE(object->IsLinkedListIterator(vm_));
3979     }
3980     gettimeofday(&g_endTime, nullptr);
3981     TEST_TIME(JSValueRef::IsLinkedListIterator);
3982 }
3983 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsList_True)3984 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsList_True)
3985 {
3986     LocalScope scope(vm_);
3987     CalculateForTime();
3988     ObjectFactory *factory = vm_->GetFactory();
3989     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
3990     JSHandle<JSTaggedValue> globalObject = env->GetJSGlobalObject();
3991     JSHandle<JSTaggedValue> key(factory->NewFromASCII("ArkPrivate"));
3992     JSHandle<JSTaggedValue> value =
3993         JSObject::GetProperty(thread_, JSHandle<JSTaggedValue>(globalObject), key).GetValue();
3994     uint32_t argvLength = 6; // 6 = argv length
3995     auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), argvLength);
3996     objCallInfo->SetFunction(JSTaggedValue::Undefined());
3997     objCallInfo->SetThis(value.GetTaggedValue());
3998     objCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int>(containers::ContainerTag::List)));
3999     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo);
4000     JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo);
4001     TestHelper::TearDownFrame(thread_, prev);
4002     JSHandle<JSTaggedValue> constructor(thread_, result);
4003     JSHandle<JSAPIList> list(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
4004     JSTaggedValue singleList = TaggedSingleList::Create(thread_);
4005     list->SetSingleList(thread_, singleList);
4006     JSHandle<JSTaggedValue> Listtag = JSHandle<JSTaggedValue>::Cast(list);
4007     Local<JSValueRef> object = JSNApiHelper::ToLocal<JSValueRef>(Listtag);
4008     gettimeofday(&g_beginTime, nullptr);
4009     for (int i = 0; i < NUM_COUNT; i++) {
4010         ASSERT_TRUE(object->IsList(vm_));
4011     }
4012     gettimeofday(&g_endTime, nullptr);
4013     TEST_TIME(JSValueRef::IsList);
4014 }
4015 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsList_False)4016 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsList_False)
4017 {
4018     LocalScope scope(vm_);
4019     CalculateForTime();
4020     int num = 10; // 10 = random number
4021     Local<JSValueRef> object = IntegerRef::New(vm_, num);
4022     for (int i = 0; i < NUM_COUNT; i++) {
4023         ASSERT_FALSE(object->IsList(vm_));
4024     }
4025     gettimeofday(&g_endTime, nullptr);
4026     TEST_TIME(JSValueRef::IsList);
4027 }
4028 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsPlainArray_True)4029 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsPlainArray_True)
4030 {
4031     LocalScope scope(vm_);
4032     CalculateForTime();
4033     ObjectFactory *factory = vm_->GetFactory();
4034     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
4035     JSHandle<JSTaggedValue> globalObject = env->GetJSGlobalObject();
4036     JSHandle<JSTaggedValue> key(factory->NewFromASCII("ArkPrivate"));
4037     JSHandle<JSTaggedValue> value =
4038         JSObject::GetProperty(thread_, JSHandle<JSTaggedValue>(globalObject), key).GetValue();
4039     uint32_t argvLength = 6; // 6 = argv length
4040     auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), argvLength);
4041     objCallInfo->SetFunction(JSTaggedValue::Undefined());
4042     objCallInfo->SetThis(value.GetTaggedValue());
4043     objCallInfo->SetCallArg(0, JSTaggedValue(static_cast<int>(containers::ContainerTag::PlainArray)));
4044     [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo);
4045     JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo);
4046     TestHelper::TearDownFrame(thread_, prev);
4047     JSHandle<JSTaggedValue> constructor(thread_, result);
4048     JSHandle<JSAPIPlainArray> plainArray(
4049         factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
4050     JSHandle<JSTaggedValue> keyArray = JSHandle<JSTaggedValue>(factory->NewTaggedArray(8));
4051     JSHandle<JSTaggedValue> valueArray = JSHandle<JSTaggedValue>(factory->NewTaggedArray(8));
4052     plainArray->SetKeys(thread_, keyArray);
4053     plainArray->SetValues(thread_, valueArray);
4054     JSHandle<JSTaggedValue> plainarraytag = JSHandle<JSTaggedValue>::Cast(plainArray);
4055     Local<JSValueRef> object = JSNApiHelper::ToLocal<JSValueRef>(plainarraytag);
4056     gettimeofday(&g_beginTime, nullptr);
4057     for (int i = 0; i < NUM_COUNT; i++) {
4058         ASSERT_TRUE(object->IsPlainArray(vm_));
4059     }
4060     gettimeofday(&g_endTime, nullptr);
4061     TEST_TIME(JSValueRef::IsPlainArray);
4062 }
4063 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsPlainArray_False)4064 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsPlainArray_False)
4065 {
4066     LocalScope scope(vm_);
4067     CalculateForTime();
4068     int num = 10; // 10 = random number
4069     Local<JSValueRef> object = IntegerRef::New(vm_, num);
4070     gettimeofday(&g_beginTime, nullptr);
4071     for (int i = 0; i < NUM_COUNT; i++) {
4072         ASSERT_FALSE(object->IsPlainArray(vm_));
4073     }
4074     gettimeofday(&g_endTime, nullptr);
4075     TEST_TIME(JSValueRef::IsPlainArray);
4076 }
4077 
HWTEST_F_L0(JSNApiSplTest,DateRef_New)4078 HWTEST_F_L0(JSNApiSplTest, DateRef_New)
4079 {
4080     LocalScope scope(vm_);
4081     CalculateForTime();
4082     double time = 3.14; // 3.14 = random number
4083     gettimeofday(&g_beginTime, nullptr);
4084     for (int i = 0; i < NUM_COUNT; i++) {
4085         DateRef::New(vm_, time);
4086     }
4087     gettimeofday(&g_endTime, nullptr);
4088     TEST_TIME(DateRef::New);
4089 }
4090 
HWTEST_F_L0(JSNApiSplTest,DateRef_ToString)4091 HWTEST_F_L0(JSNApiSplTest, DateRef_ToString)
4092 {
4093     LocalScope scope(vm_);
4094     CalculateForTime();
4095     double time = 3.14; // 3.14 = random number
4096     Local<DateRef> object = DateRef::New(vm_, time);
4097     gettimeofday(&g_beginTime, nullptr);
4098     for (int i = 0; i < NUM_COUNT; i++) {
4099         object->ToString(vm_);
4100     }
4101     gettimeofday(&g_endTime, nullptr);
4102     TEST_TIME(DateRef::ToString);
4103 }
4104 
HWTEST_F_L0(JSNApiSplTest,DateRef_GetTime)4105 HWTEST_F_L0(JSNApiSplTest, DateRef_GetTime)
4106 {
4107     LocalScope scope(vm_);
4108     CalculateForTime();
4109     double time = 3.14; // 3.14 = random number
4110     Local<DateRef> object = DateRef::New(vm_, time);
4111     gettimeofday(&g_beginTime, nullptr);
4112     for (int i = 0; i < NUM_COUNT; i++) {
4113         object->GetTime(vm_);
4114     }
4115     gettimeofday(&g_endTime, nullptr);
4116     TEST_TIME(DateRef::GetTime);
4117 }
4118 
HWTEST_F_L0(JSNApiSplTest,ProxyRef_GetHandler)4119 HWTEST_F_L0(JSNApiSplTest, ProxyRef_GetHandler)
4120 {
4121     LocalScope scope(vm_);
4122     CalculateForTime();
4123     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
4124     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
4125     JSHandle<JSTaggedValue> hclass(thread_, env->GetObjectFunction().GetObject<JSFunction>());
4126     JSHandle<JSTaggedValue> targetHandle(factory->NewJSObjectByConstructor(JSHandle<JSFunction>::Cast(hclass), hclass));
4127     JSHandle<JSTaggedValue> key(factory->NewFromASCII("x"));
4128     JSHandle<JSTaggedValue> value(thread_, JSTaggedValue(1));
4129     JSObject::SetProperty(thread_, targetHandle, key, value);
4130     JSHandle<JSTaggedValue> handlerHandle(
4131         factory->NewJSObjectByConstructor(JSHandle<JSFunction>::Cast(hclass), hclass));
4132     JSHandle<JSProxy> proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle);
4133     JSHandle<JSTaggedValue> proxyTagValue = JSHandle<JSTaggedValue>::Cast(proxyHandle);
4134     Local<ProxyRef> object = JSNApiHelper::ToLocal<ProxyRef>(proxyTagValue);
4135     gettimeofday(&g_beginTime, nullptr);
4136     for (int i = 0; i < NUM_COUNT; i++) {
4137         object->GetHandler(vm_);
4138     }
4139     gettimeofday(&g_endTime, nullptr);
4140     TEST_TIME(ProxyRef::GetHandler);
4141 }
4142 
HWTEST_F_L0(JSNApiSplTest,ProxyRef_GetTarget)4143 HWTEST_F_L0(JSNApiSplTest, ProxyRef_GetTarget)
4144 {
4145     LocalScope scope(vm_);
4146     CalculateForTime();
4147     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
4148     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
4149     JSHandle<JSTaggedValue> hclass(thread_, env->GetObjectFunction().GetObject<JSFunction>());
4150     JSHandle<JSTaggedValue> targetHandle(factory->NewJSObjectByConstructor(JSHandle<JSFunction>::Cast(hclass), hclass));
4151     JSHandle<JSTaggedValue> key(factory->NewFromASCII("x"));
4152     JSHandle<JSTaggedValue> value(thread_, JSTaggedValue(1));
4153     JSObject::SetProperty(thread_, targetHandle, key, value);
4154     JSHandle<JSTaggedValue> handlerHandle(
4155         factory->NewJSObjectByConstructor(JSHandle<JSFunction>::Cast(hclass), hclass));
4156     JSHandle<JSProxy> proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle);
4157     JSHandle<JSTaggedValue> proxyTagValue = JSHandle<JSTaggedValue>::Cast(proxyHandle);
4158     Local<ProxyRef> object = JSNApiHelper::ToLocal<ProxyRef>(proxyTagValue);
4159     gettimeofday(&g_beginTime, nullptr);
4160     for (int i = 0; i < NUM_COUNT; i++) {
4161         object->GetTarget(vm_);
4162     }
4163     gettimeofday(&g_endTime, nullptr);
4164     TEST_TIME(ProxyRef::GetTarget);
4165 }
4166 
HWTEST_F_L0(JSNApiSplTest,ProxyRef_IsRevoked)4167 HWTEST_F_L0(JSNApiSplTest, ProxyRef_IsRevoked)
4168 {
4169     LocalScope scope(vm_);
4170     CalculateForTime();
4171     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
4172     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
4173     JSHandle<JSTaggedValue> hclass(thread_, env->GetObjectFunction().GetObject<JSFunction>());
4174     JSHandle<JSTaggedValue> targetHandle(factory->NewJSObjectByConstructor(JSHandle<JSFunction>::Cast(hclass), hclass));
4175     JSHandle<JSTaggedValue> key(factory->NewFromASCII("x"));
4176     JSHandle<JSTaggedValue> value(thread_, JSTaggedValue(1));
4177     JSObject::SetProperty(thread_, targetHandle, key, value);
4178     JSHandle<JSTaggedValue> handlerHandle(
4179         factory->NewJSObjectByConstructor(JSHandle<JSFunction>::Cast(hclass), hclass));
4180     JSHandle<JSProxy> proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle);
4181     JSHandle<JSTaggedValue> proxyTagValue = JSHandle<JSTaggedValue>::Cast(proxyHandle);
4182     Local<ProxyRef> object = JSNApiHelper::ToLocal<ProxyRef>(proxyTagValue);
4183     gettimeofday(&g_beginTime, nullptr);
4184     for (int i = 0; i < NUM_COUNT; i++) {
4185         object->IsRevoked();
4186     }
4187     gettimeofday(&g_endTime, nullptr);
4188     TEST_TIME(ProxyRef::IsRevoked);
4189 }
4190 
HWTEST_F_L0(JSNApiSplTest,MapRef_GetSize)4191 HWTEST_F_L0(JSNApiSplTest, MapRef_GetSize)
4192 {
4193     LocalScope scope(vm_);
4194     CalculateForTime();
4195     Local<MapRef> object = MapRef::New(vm_);
4196     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4197     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4198     object->Set(vm_, key, value);
4199     gettimeofday(&g_beginTime, nullptr);
4200     for (int i = 0; i < NUM_COUNT; i++) {
4201         object->GetSize(vm_);
4202     }
4203     gettimeofday(&g_endTime, nullptr);
4204     TEST_TIME(MapRef::GetSize);
4205 }
4206 
HWTEST_F_L0(JSNApiSplTest,MapRef_GetTotalElements)4207 HWTEST_F_L0(JSNApiSplTest, MapRef_GetTotalElements)
4208 {
4209     LocalScope scope(vm_);
4210     CalculateForTime();
4211     Local<MapRef> object = MapRef::New(vm_);
4212     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4213     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4214     object->Set(vm_, key, value);
4215     gettimeofday(&g_beginTime, nullptr);
4216     for (int i = 0; i < NUM_COUNT; i++) {
4217         object->GetTotalElements(vm_);
4218     }
4219     gettimeofday(&g_endTime, nullptr);
4220     TEST_TIME(MapRef::GetTotalElements);
4221 }
4222 
HWTEST_F_L0(JSNApiSplTest,MapRef_Get)4223 HWTEST_F_L0(JSNApiSplTest, MapRef_Get)
4224 {
4225     LocalScope scope(vm_);
4226     CalculateForTime();
4227     Local<MapRef> object = MapRef::New(vm_);
4228     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4229     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4230     object->Set(vm_, key, value);
4231     gettimeofday(&g_beginTime, nullptr);
4232     for (int i = 0; i < NUM_COUNT; i++) {
4233         object->Get(vm_, key);
4234     }
4235     gettimeofday(&g_endTime, nullptr);
4236     TEST_TIME(MapRef::Get);
4237 }
4238 
HWTEST_F_L0(JSNApiSplTest,MapRef_GetKey)4239 HWTEST_F_L0(JSNApiSplTest, MapRef_GetKey)
4240 {
4241     LocalScope scope(vm_);
4242     CalculateForTime();
4243     Local<MapRef> object = MapRef::New(vm_);
4244     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4245     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4246     object->Set(vm_, key, value);
4247     gettimeofday(&g_beginTime, nullptr);
4248     for (int i = 0; i < NUM_COUNT; i++) {
4249         object->GetKey(vm_, 0);
4250     }
4251     gettimeofday(&g_endTime, nullptr);
4252     TEST_TIME(MapRef::GetKey);
4253 }
4254 
HWTEST_F_L0(JSNApiSplTest,MapRef_GetValue)4255 HWTEST_F_L0(JSNApiSplTest, MapRef_GetValue)
4256 {
4257     LocalScope scope(vm_);
4258     CalculateForTime();
4259     Local<MapRef> object = MapRef::New(vm_);
4260     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4261     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4262     object->Set(vm_, key, value);
4263     gettimeofday(&g_beginTime, nullptr);
4264     for (int i = 0; i < NUM_COUNT; i++) {
4265         object->GetValue(vm_, 0);
4266     }
4267     gettimeofday(&g_endTime, nullptr);
4268     TEST_TIME(MapRef::GetValue);
4269 }
4270 
HWTEST_F_L0(JSNApiSplTest,MapRef_New)4271 HWTEST_F_L0(JSNApiSplTest, MapRef_New)
4272 {
4273     LocalScope scope(vm_);
4274     CalculateForTime();
4275     gettimeofday(&g_beginTime, nullptr);
4276     for (int i = 0; i < NUM_COUNT; i++) {
4277         MapRef::New(vm_);
4278     }
4279     gettimeofday(&g_endTime, nullptr);
4280     TEST_TIME(MapRef::New);
4281 }
4282 
HWTEST_F_L0(JSNApiSplTest,MapRef_Set)4283 HWTEST_F_L0(JSNApiSplTest, MapRef_Set)
4284 {
4285     LocalScope scope(vm_);
4286     CalculateForTime();
4287     Local<MapRef> object = MapRef::New(vm_);
4288     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4289     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4290     gettimeofday(&g_beginTime, nullptr);
4291     for (int i = 0; i < NUM_COUNT; i++) {
4292         object->Set(vm_, key, value);
4293     }
4294     gettimeofday(&g_endTime, nullptr);
4295     TEST_TIME(MapRef::Set);
4296 }
4297 
HWTEST_F_L0(JSNApiSplTest,WeakMapRef_GetSize)4298 HWTEST_F_L0(JSNApiSplTest, WeakMapRef_GetSize)
4299 {
4300     LocalScope scope(vm_);
4301     CalculateForTime();
4302     Local<WeakMapRef> object = WeakMapRef::New(vm_);
4303     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4304     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4305     object->Set(vm_, key, value);
4306     gettimeofday(&g_beginTime, nullptr);
4307     for (int i = 0; i < NUM_COUNT; i++) {
4308         object->GetSize(vm_);
4309     }
4310     gettimeofday(&g_endTime, nullptr);
4311     TEST_TIME(WeakMapRef::GetSize);
4312 }
4313 
HWTEST_F_L0(JSNApiSplTest,WeakMapRef_GetTotalElements)4314 HWTEST_F_L0(JSNApiSplTest, WeakMapRef_GetTotalElements)
4315 {
4316     LocalScope scope(vm_);
4317     CalculateForTime();
4318     Local<WeakMapRef> object = WeakMapRef::New(vm_);
4319     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4320     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4321     object->Set(vm_, key, value);
4322     gettimeofday(&g_beginTime, nullptr);
4323     for (int i = 0; i < NUM_COUNT; i++) {
4324         object->GetTotalElements(vm_);
4325     }
4326     gettimeofday(&g_endTime, nullptr);
4327     TEST_TIME(WeakMapRef::GetTotalElements);
4328 }
4329 
HWTEST_F_L0(JSNApiSplTest,WeakMapRef_GetKey)4330 HWTEST_F_L0(JSNApiSplTest, WeakMapRef_GetKey)
4331 {
4332     LocalScope scope(vm_);
4333     CalculateForTime();
4334     Local<WeakMapRef> object = WeakMapRef::New(vm_);
4335     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4336     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4337     object->Set(vm_, key, value);
4338     gettimeofday(&g_beginTime, nullptr);
4339     for (int i = 0; i < NUM_COUNT; i++) {
4340         object->GetKey(vm_, 0);
4341     }
4342     gettimeofday(&g_endTime, nullptr);
4343     TEST_TIME(WeakMapRef::GetKey);
4344 }
4345 
HWTEST_F_L0(JSNApiSplTest,WeakMapRef_GetValue)4346 HWTEST_F_L0(JSNApiSplTest, WeakMapRef_GetValue)
4347 {
4348     LocalScope scope(vm_);
4349     CalculateForTime();
4350     Local<WeakMapRef> object = WeakMapRef::New(vm_);
4351     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4352     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4353     object->Set(vm_, key, value);
4354     gettimeofday(&g_beginTime, nullptr);
4355     for (int i = 0; i < NUM_COUNT; i++) {
4356         object->GetValue(vm_, 0);
4357     }
4358     gettimeofday(&g_endTime, nullptr);
4359     TEST_TIME(WeakMapRef::GetValue);
4360 }
4361 
HWTEST_F_L0(JSNApiSplTest,SetRef_GetSize)4362 HWTEST_F_L0(JSNApiSplTest, SetRef_GetSize)
4363 {
4364     LocalScope scope(vm_);
4365     CalculateForTime();
4366     Local<SetRef> object = SetRef::New(vm_);
4367     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4368     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4369     object->Set(vm_, key, value);
4370     gettimeofday(&g_beginTime, nullptr);
4371     for (int i = 0; i < NUM_COUNT; i++) {
4372         object->GetSize(vm_);
4373     }
4374     gettimeofday(&g_endTime, nullptr);
4375     TEST_TIME(SetRef::GetSize);
4376 }
4377 
HWTEST_F_L0(JSNApiSplTest,SetRef_GetTotalElements)4378 HWTEST_F_L0(JSNApiSplTest, SetRef_GetTotalElements)
4379 {
4380     LocalScope scope(vm_);
4381     CalculateForTime();
4382     Local<SetRef> object = SetRef::New(vm_);
4383     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4384     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4385     object->Set(vm_, key, value);
4386     gettimeofday(&g_beginTime, nullptr);
4387     for (int i = 0; i < NUM_COUNT; i++) {
4388         object->GetTotalElements(vm_);
4389     }
4390     gettimeofday(&g_endTime, nullptr);
4391     TEST_TIME(SetRef::GetTotalElements);
4392 }
4393 
HWTEST_F_L0(JSNApiSplTest,SetRef_GetValue)4394 HWTEST_F_L0(JSNApiSplTest, SetRef_GetValue)
4395 {
4396     LocalScope scope(vm_);
4397     CalculateForTime();
4398     Local<SetRef> object = SetRef::New(vm_);
4399     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4400     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4401     object->Set(vm_, key, value);
4402     gettimeofday(&g_beginTime, nullptr);
4403     for (int i = 0; i < NUM_COUNT; i++) {
4404         object->GetValue(vm_, 0);
4405     }
4406     gettimeofday(&g_endTime, nullptr);
4407     TEST_TIME(SetRef::GetValue);
4408 }
4409 
HWTEST_F_L0(JSNApiSplTest,WeakSetRef_GetSize)4410 HWTEST_F_L0(JSNApiSplTest, WeakSetRef_GetSize)
4411 {
4412     LocalScope scope(vm_);
4413     CalculateForTime();
4414     Local<WeakSetRef> object = WeakSetRef::New(vm_);
4415     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4416     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4417     object->Set(vm_, key, value);
4418     gettimeofday(&g_beginTime, nullptr);
4419     for (int i = 0; i < NUM_COUNT; i++) {
4420         object->GetSize(vm_);
4421     }
4422     gettimeofday(&g_endTime, nullptr);
4423     TEST_TIME(WeakSetRef::GetSize);
4424 }
4425 
HWTEST_F_L0(JSNApiSplTest,WeakSetRef_GetTotalElements)4426 HWTEST_F_L0(JSNApiSplTest, WeakSetRef_GetTotalElements)
4427 {
4428     LocalScope scope(vm_);
4429     CalculateForTime();
4430     Local<WeakSetRef> object = WeakSetRef::New(vm_);
4431     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4432     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4433     object->Set(vm_, key, value);
4434     gettimeofday(&g_beginTime, nullptr);
4435     for (int i = 0; i < NUM_COUNT; i++) {
4436         object->GetTotalElements(vm_);
4437     }
4438     gettimeofday(&g_endTime, nullptr);
4439     TEST_TIME(WeakSetRef::GetTotalElements);
4440 }
4441 
HWTEST_F_L0(JSNApiSplTest,WeakSetRef_GetValue)4442 HWTEST_F_L0(JSNApiSplTest, WeakSetRef_GetValue)
4443 {
4444     LocalScope scope(vm_);
4445     CalculateForTime();
4446     Local<WeakSetRef> object = WeakSetRef::New(vm_);
4447     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
4448     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, "TestValue");
4449     object->Set(vm_, key, value);
4450     gettimeofday(&g_beginTime, nullptr);
4451     for (int i = 0; i < NUM_COUNT; i++) {
4452         object->GetValue(vm_, 0);
4453     }
4454     gettimeofday(&g_endTime, nullptr);
4455     TEST_TIME(WeakSetRef::GetValue);
4456 }
4457 
HWTEST_F_L0(JSNApiSplTest,IsWeakSetRef_True)4458 HWTEST_F_L0(JSNApiSplTest, IsWeakSetRef_True)
4459 {
4460     LocalScope scope(vm_);
4461     CalculateForTime();
4462     Local<JSValueRef> weakSet = WeakSetRef::New(vm_);
4463     gettimeofday(&g_beginTime, nullptr);
4464     for (int i = 0; i < NUM_COUNT; i++) {
4465         ASSERT_TRUE(weakSet->IsWeakSet(vm_));
4466     }
4467     gettimeofday(&g_endTime, nullptr);
4468     TEST_TIME(JSValueRef::IsWeakSet);
4469 }
4470 
HWTEST_F_L0(JSNApiSplTest,IsWeakSetRef_False)4471 HWTEST_F_L0(JSNApiSplTest, IsWeakSetRef_False)
4472 {
4473     LocalScope scope(vm_);
4474     CalculateForTime();
4475     Local<JSValueRef> object = ObjectRef::New(vm_);
4476     gettimeofday(&g_beginTime, nullptr);
4477     for (int i = 0; i < NUM_COUNT; i++) {
4478         ASSERT_FALSE(object->IsWeakSet(vm_));
4479     }
4480     gettimeofday(&g_endTime, nullptr);
4481     TEST_TIME(JSValueRef::IsWeakSet);
4482 }
4483 
HWTEST_F_L0(JSNApiSplTest,MapIteratorRef_GetIndex)4484 HWTEST_F_L0(JSNApiSplTest, MapIteratorRef_GetIndex)
4485 {
4486     LocalScope scope(vm_);
4487     CalculateForTime();
4488     JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
4489     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
4490     JSHandle<JSTaggedValue> builtinsMapFunc = env->GetBuiltinsMapFunction();
4491     JSHandle<JSMap> jsMap(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(builtinsMapFunc), builtinsMapFunc));
4492     JSHandle<JSTaggedValue> linkedHashMap(LinkedHashMap::Create(thread_));
4493     jsMap->SetLinkedMap(thread_, linkedHashMap);
4494     JSHandle<JSTaggedValue> mapValue(jsMap);
4495     JSHandle<JSTaggedValue> mapIteratorVal = JSMapIterator::CreateMapIterator(thread_, mapValue, IterationKind::KEY);
4496     JSHandle<JSMapIterator> mapIterator = JSHandle<JSMapIterator>::Cast(mapIteratorVal);
4497     mapIterator->SetNextIndex(1);
4498     Local<MapIteratorRef> object = JSNApiHelper::ToLocal<MapIteratorRef>(mapIteratorVal);
4499     gettimeofday(&g_beginTime, nullptr);
4500     for (int i = 0; i < NUM_COUNT; i++) {
4501         object->GetIndex();
4502     }
4503     gettimeofday(&g_endTime, nullptr);
4504     TEST_TIME(MapIteratorRef::GetIndex);
4505 }
4506 
HWTEST_F_L0(JSNApiSplTest,MapIteratorRef_GetKind)4507 HWTEST_F_L0(JSNApiSplTest, MapIteratorRef_GetKind)
4508 {
4509     LocalScope scope(vm_);
4510     CalculateForTime();
4511     JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
4512     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
4513     JSHandle<JSTaggedValue> builtinsMapFunc = env->GetBuiltinsMapFunction();
4514     JSHandle<JSMap> jsMap(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(builtinsMapFunc), builtinsMapFunc));
4515     JSHandle<JSTaggedValue> linkedHashMap(LinkedHashMap::Create(thread_));
4516     jsMap->SetLinkedMap(thread_, linkedHashMap);
4517     JSHandle<JSTaggedValue> mapValue(jsMap);
4518     JSHandle<JSTaggedValue> mapIteratorVal = JSMapIterator::CreateMapIterator(thread_, mapValue, IterationKind::KEY);
4519     JSHandle<JSMapIterator> mapIterator = JSHandle<JSMapIterator>::Cast(mapIteratorVal);
4520     mapIterator->SetIterationKind(IterationKind::VALUE);
4521     mapIterator->SetIterationKind(IterationKind::KEY_AND_VALUE);
4522     Local<MapIteratorRef> object = JSNApiHelper::ToLocal<MapIteratorRef>(mapIteratorVal);
4523     gettimeofday(&g_beginTime, nullptr);
4524     for (int i = 0; i < NUM_COUNT; i++) {
4525         object->GetKind(vm_);
4526     }
4527     gettimeofday(&g_endTime, nullptr);
4528     TEST_TIME(MapIteratorRef::GetKind);
4529 }
4530 
HWTEST_F_L0(JSNApiSplTest,SetIteratorRef_GetIndex)4531 HWTEST_F_L0(JSNApiSplTest, SetIteratorRef_GetIndex)
4532 {
4533     LocalScope scope(vm_);
4534     CalculateForTime();
4535     JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
4536     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
4537     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsSetFunction();
4538     JSHandle<JSSet> set =
4539         JSHandle<JSSet>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
4540     JSHandle<LinkedHashSet> hashSet = LinkedHashSet::Create(thread_);
4541     set->SetLinkedSet(thread_, hashSet);
4542     JSHandle<JSTaggedValue> setIteratorValue =
4543         JSSetIterator::CreateSetIterator(thread_, JSHandle<JSTaggedValue>(set), IterationKind::KEY);
4544     JSHandle<JSSetIterator> setIterator = JSHandle<JSSetIterator>::Cast(setIteratorValue);
4545     setIterator->SetNextIndex(1);
4546     Local<SetIteratorRef> object = JSNApiHelper::ToLocal<SetIteratorRef>(setIteratorValue);
4547     gettimeofday(&g_beginTime, nullptr);
4548     for (int i = 0; i < NUM_COUNT; i++) {
4549         object->GetIndex();
4550     }
4551     gettimeofday(&g_endTime, nullptr);
4552     TEST_TIME(SetIteratorRef::GetIndex);
4553 }
4554 
HWTEST_F_L0(JSNApiSplTest,SetIteratorRef_GetKind)4555 HWTEST_F_L0(JSNApiSplTest, SetIteratorRef_GetKind)
4556 {
4557     LocalScope scope(vm_);
4558     CalculateForTime();
4559     JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
4560     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
4561     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsSetFunction();
4562     JSHandle<JSSet> set =
4563         JSHandle<JSSet>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
4564     JSHandle<LinkedHashSet> hashSet = LinkedHashSet::Create(thread_);
4565     set->SetLinkedSet(thread_, hashSet);
4566     JSHandle<JSTaggedValue> setIteratorValue =
4567         JSSetIterator::CreateSetIterator(thread_, JSHandle<JSTaggedValue>(set), IterationKind::KEY);
4568     JSHandle<JSSetIterator> setIterator = JSHandle<JSSetIterator>::Cast(setIteratorValue);
4569     setIterator->SetIterationKind(IterationKind::VALUE);
4570     setIterator->SetIterationKind(IterationKind::KEY_AND_VALUE);
4571     Local<SetIteratorRef> object = JSNApiHelper::ToLocal<SetIteratorRef>(setIteratorValue);
4572     gettimeofday(&g_beginTime, nullptr);
4573     for (int i = 0; i < NUM_COUNT; i++) {
4574         object->GetKind(vm_);
4575     }
4576     gettimeofday(&g_endTime, nullptr);
4577     TEST_TIME(SetIteratorRef::GetKind);
4578 }
4579 
HWTEST_F_L0(JSNApiSplTest,GeneratorFunctionRef_IsGenerator)4580 HWTEST_F_L0(JSNApiSplTest, GeneratorFunctionRef_IsGenerator)
4581 {
4582     LocalScope scope(vm_);
4583     CalculateForTime();
4584     JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
4585     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
4586     JSHandle<JSTaggedValue> genFunc = env->GetGeneratorFunctionFunction();
4587     JSHandle<JSGeneratorObject> genObjHandleVal = factory->NewJSGeneratorObject(genFunc);
4588     JSHandle<JSHClass> hclass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
4589     JSHandle<JSFunction> generatorFunc = JSHandle<JSFunction>::Cast(factory->NewJSObject(hclass));
4590     JSFunction::InitializeJSFunction(thread_, generatorFunc, FunctionKind::GENERATOR_FUNCTION);
4591     JSHandle<GeneratorContext> generatorContext = factory->NewGeneratorContext();
4592     generatorContext->SetMethod(thread_, generatorFunc.GetTaggedValue());
4593     JSHandle<JSTaggedValue> generatorContextVal = JSHandle<JSTaggedValue>::Cast(generatorContext);
4594     genObjHandleVal->SetGeneratorContext(thread_, generatorContextVal.GetTaggedValue());
4595     JSHandle<JSTaggedValue> genObjTagHandleVal = JSHandle<JSTaggedValue>::Cast(genObjHandleVal);
4596     Local<GeneratorObjectRef> genObjectRef = JSNApiHelper::ToLocal<GeneratorObjectRef>(genObjTagHandleVal);
4597     Local<GeneratorFunctionRef> object = genObjectRef->GetGeneratorFunction(vm_);
4598     gettimeofday(&g_beginTime, nullptr);
4599     for (int i = 0; i < NUM_COUNT; i++) {
4600         object->IsGenerator(vm_);
4601     }
4602     gettimeofday(&g_endTime, nullptr);
4603     TEST_TIME(GeneratorFunctionRef::IsGenerator);
4604 }
4605 
HWTEST_F_L0(JSNApiSplTest,GeneratorObjectRef_GetGeneratorState)4606 HWTEST_F_L0(JSNApiSplTest, GeneratorObjectRef_GetGeneratorState)
4607 {
4608     LocalScope scope(vm_);
4609     CalculateForTime();
4610     JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
4611     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
4612     JSHandle<JSTaggedValue> genFunc = env->GetGeneratorFunctionFunction();
4613     JSHandle<JSGeneratorObject> genObjHandleVal = factory->NewJSGeneratorObject(genFunc);
4614     JSHandle<JSHClass> hclass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
4615     JSHandle<JSFunction> generatorFunc = JSHandle<JSFunction>::Cast(factory->NewJSObject(hclass));
4616     JSFunction::InitializeJSFunction(thread_, generatorFunc, FunctionKind::GENERATOR_FUNCTION);
4617     JSHandle<GeneratorContext> generatorContext = factory->NewGeneratorContext();
4618     generatorContext->SetMethod(thread_, generatorFunc.GetTaggedValue());
4619     JSHandle<JSTaggedValue> generatorContextVal = JSHandle<JSTaggedValue>::Cast(generatorContext);
4620     genObjHandleVal->SetGeneratorContext(thread_, generatorContextVal.GetTaggedValue());
4621     genObjHandleVal->SetGeneratorState(JSGeneratorState::COMPLETED);
4622     JSHandle<JSTaggedValue> genObjTagHandleVal = JSHandle<JSTaggedValue>::Cast(genObjHandleVal);
4623     Local<GeneratorObjectRef> object = JSNApiHelper::ToLocal<GeneratorObjectRef>(genObjTagHandleVal);
4624     gettimeofday(&g_beginTime, nullptr);
4625     for (int i = 0; i < NUM_COUNT; i++) {
4626         object->GetGeneratorState(vm_);
4627     }
4628     gettimeofday(&g_endTime, nullptr);
4629     TEST_TIME(GeneratorObjectRef::GetGeneratorState);
4630 }
4631 
HWTEST_F_L0(JSNApiSplTest,GeneratorObjectRef_GetGeneratorFunction)4632 HWTEST_F_L0(JSNApiSplTest, GeneratorObjectRef_GetGeneratorFunction)
4633 {
4634     LocalScope scope(vm_);
4635     CalculateForTime();
4636     JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
4637     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
4638     JSHandle<JSTaggedValue> genFunc = env->GetGeneratorFunctionFunction();
4639     JSHandle<JSGeneratorObject> genObjHandleVal = factory->NewJSGeneratorObject(genFunc);
4640     JSHandle<JSHClass> hclass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
4641     JSHandle<JSFunction> generatorFunc = JSHandle<JSFunction>::Cast(factory->NewJSObject(hclass));
4642     JSFunction::InitializeJSFunction(thread_, generatorFunc, FunctionKind::GENERATOR_FUNCTION);
4643     JSHandle<GeneratorContext> generatorContext = factory->NewGeneratorContext();
4644     generatorContext->SetMethod(thread_, generatorFunc.GetTaggedValue());
4645     JSHandle<JSTaggedValue> generatorContextVal = JSHandle<JSTaggedValue>::Cast(generatorContext);
4646     genObjHandleVal->SetGeneratorContext(thread_, generatorContextVal.GetTaggedValue());
4647     genObjHandleVal->SetGeneratorState(JSGeneratorState::COMPLETED);
4648     JSHandle<JSTaggedValue> genObjTagHandleVal = JSHandle<JSTaggedValue>::Cast(genObjHandleVal);
4649     Local<GeneratorObjectRef> object = JSNApiHelper::ToLocal<GeneratorObjectRef>(genObjTagHandleVal);
4650     gettimeofday(&g_beginTime, nullptr);
4651     for (int i = 0; i < NUM_COUNT; i++) {
4652         object->GetGeneratorFunction(vm_);
4653     }
4654     gettimeofday(&g_endTime, nullptr);
4655     TEST_TIME(GeneratorObjectRef::GetGeneratorFunction);
4656 }
4657 
HWTEST_F_L0(JSNApiSplTest,GeneratorObjectRef_GetGeneratorReceiver)4658 HWTEST_F_L0(JSNApiSplTest, GeneratorObjectRef_GetGeneratorReceiver)
4659 {
4660     LocalScope scope(vm_);
4661     CalculateForTime();
4662     JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
4663     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
4664     JSHandle<JSTaggedValue> genFunc = env->GetGeneratorFunctionFunction();
4665     JSHandle<JSGeneratorObject> genObjHandleVal = factory->NewJSGeneratorObject(genFunc);
4666     JSHandle<JSHClass> hclass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
4667     JSHandle<JSFunction> generatorFunc = JSHandle<JSFunction>::Cast(factory->NewJSObject(hclass));
4668     JSFunction::InitializeJSFunction(thread_, generatorFunc, FunctionKind::GENERATOR_FUNCTION);
4669     JSHandle<GeneratorContext> generatorContext = factory->NewGeneratorContext();
4670     generatorContext->SetMethod(thread_, generatorFunc.GetTaggedValue());
4671     JSHandle<JSTaggedValue> generatorContextVal = JSHandle<JSTaggedValue>::Cast(generatorContext);
4672     genObjHandleVal->SetGeneratorContext(thread_, generatorContextVal.GetTaggedValue());
4673     genObjHandleVal->SetGeneratorState(JSGeneratorState::COMPLETED);
4674     JSHandle<JSTaggedValue> genObjTagHandleVal = JSHandle<JSTaggedValue>::Cast(genObjHandleVal);
4675     Local<GeneratorObjectRef> object = JSNApiHelper::ToLocal<GeneratorObjectRef>(genObjTagHandleVal);
4676     gettimeofday(&g_beginTime, nullptr);
4677     for (int i = 0; i < NUM_COUNT; i++) {
4678         object->GetGeneratorReceiver(vm_);
4679     }
4680     gettimeofday(&g_endTime, nullptr);
4681     TEST_TIME(GeneratorObjectRef::GetGeneratorReceiver);
4682 }
4683 
HWTEST_F_L0(JSNApiSplTest,CollatorRef_GetCompareFunction)4684 HWTEST_F_L0(JSNApiSplTest, CollatorRef_GetCompareFunction)
4685 {
4686     LocalScope scope(vm_);
4687     CalculateForTime();
4688     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
4689     ObjectFactory *factory = vm_->GetFactory();
4690     JSHandle<JSTaggedValue> ctor = env->GetCollatorFunction();
4691     JSHandle<JSCollator> collator =
4692         JSHandle<JSCollator>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(ctor), ctor));
4693     JSHandle<JSTaggedValue> localeStr = thread_->GlobalConstants()->GetHandledEnUsString();
4694     JSHandle<JSTaggedValue> undefinedHandle(thread_, JSTaggedValue::Undefined());
4695     JSHandle<JSCollator> initCollator = JSCollator::InitializeCollator(thread_, collator, localeStr, undefinedHandle);
4696     JSHandle<JSTaggedValue> collatorTagHandleVal = JSHandle<JSTaggedValue>::Cast(initCollator);
4697     Local<CollatorRef> object = JSNApiHelper::ToLocal<CollatorRef>(collatorTagHandleVal);
4698     gettimeofday(&g_beginTime, nullptr);
4699     for (int i = 0; i < NUM_COUNT; i++) {
4700         object->GetCompareFunction(vm_);
4701     }
4702     gettimeofday(&g_endTime, nullptr);
4703     TEST_TIME(GeneratorObjectRef::GetCompareFunction);
4704 }
4705 
HWTEST_F_L0(JSNApiSplTest,DataTimeFormatRef_GetFormatFunction)4706 HWTEST_F_L0(JSNApiSplTest, DataTimeFormatRef_GetFormatFunction)
4707 {
4708     LocalScope scope(vm_);
4709     CalculateForTime();
4710     JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
4711     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
4712     JSHandle<JSTaggedValue> localeCtor = env->GetLocaleFunction();
4713     JSHandle<JSLocale> locales =
4714         JSHandle<JSLocale>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(localeCtor), localeCtor));
4715     icu::Locale icuLocale("zh", "Hans", "Cn", "calendar=chinese");
4716     factory->NewJSIntlIcuData(locales, icuLocale, JSLocale::FreeIcuLocale);
4717     JSHandle<JSTaggedValue> objFun = env->GetObjectFunction();
4718     JSHandle<JSObject> options = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(objFun), objFun);
4719     options = JSDateTimeFormat::ToDateTimeOptions(thread_, JSHandle<JSTaggedValue>::Cast(options), RequiredOption::ANY,
4720         DefaultsOption::ALL);
4721     JSHandle<JSTaggedValue> dtfCtor = env->GetDateTimeFormatFunction();
4722     JSHandle<JSDateTimeFormat> dtf =
4723         JSHandle<JSDateTimeFormat>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(dtfCtor), dtfCtor));
4724     dtf = JSDateTimeFormat::InitializeDateTimeFormat(thread_, dtf, JSHandle<JSTaggedValue>::Cast(locales),
4725         JSHandle<JSTaggedValue>::Cast(options));
4726     JSHandle<JSTaggedValue> dtfTagHandleVal = JSHandle<JSTaggedValue>::Cast(dtf);
4727     Local<DataTimeFormatRef> object = JSNApiHelper::ToLocal<DataTimeFormatRef>(dtfTagHandleVal);
4728     gettimeofday(&g_beginTime, nullptr);
4729     for (int i = 0; i < NUM_COUNT; i++) {
4730         object->GetFormatFunction(vm_);
4731     }
4732     gettimeofday(&g_endTime, nullptr);
4733     TEST_TIME(DataTimeFormatRef::GetFormatFunction);
4734 }
4735 
HWTEST_F_L0(JSNApiSplTest,NumberFormatRef_GetFormatFunction)4736 HWTEST_F_L0(JSNApiSplTest, NumberFormatRef_GetFormatFunction)
4737 {
4738     LocalScope scope(vm_);
4739     CalculateForTime();
4740     JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
4741     ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
4742     JSHandle<JSTaggedValue> ctor = env->GetNumberFormatFunction();
4743     JSHandle<JSNumberFormat> numberFormat =
4744         JSHandle<JSNumberFormat>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(ctor), ctor));
4745     EXPECT_TRUE(*numberFormat != nullptr);
4746     JSHandle<JSTaggedValue> locales(factory->NewFromASCII("zh-Hans-CN"));
4747     JSHandle<JSTaggedValue> undefinedOptions(thread_, JSTaggedValue::Undefined());
4748     JSNumberFormat::InitializeNumberFormat(thread_, numberFormat, locales, undefinedOptions);
4749     JSHandle<JSTaggedValue> numberformatTagHandleVal = JSHandle<JSTaggedValue>::Cast(numberFormat);
4750     Local<NumberFormatRef> object = JSNApiHelper::ToLocal<NumberFormatRef>(numberformatTagHandleVal);
4751     gettimeofday(&g_beginTime, nullptr);
4752     for (int i = 0; i < NUM_COUNT; i++) {
4753         object->GetFormatFunction(vm_);
4754     }
4755     gettimeofday(&g_endTime, nullptr);
4756     TEST_TIME(NumberFormatRef::GetFormatFunction);
4757 }
4758 
HWTEST_F_L0(JSNApiSplTest,PromiseRejectInfo_PromiseRejectInfo)4759 HWTEST_F_L0(JSNApiSplTest, PromiseRejectInfo_PromiseRejectInfo)
4760 {
4761     LocalScope scope(vm_);
4762     CalculateForTime();
4763     Local<StringRef> toStringPromise = StringRef::NewFromUtf8(vm_, "-3.14");
4764     Local<JSValueRef> promise(toStringPromise);
4765     Local<StringRef> toStringReason = StringRef::NewFromUtf8(vm_, "123.3");
4766     Local<JSValueRef> reason(toStringReason);
4767     void *data = static_cast<void *>(new std::string("promisereject"));
4768     gettimeofday(&g_beginTime, nullptr);
4769     for (int i = 0; i < NUM_COUNT; i++) {
4770         PromiseRejectInfo promisereject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data);
4771     }
4772     gettimeofday(&g_endTime, nullptr);
4773     TEST_TIME(PromiseRejectInfo::PromiseRejectInfo);
4774 }
4775 
HWTEST_F_L0(JSNApiSplTest,PromiseRejectInfo_GetPromise)4776 HWTEST_F_L0(JSNApiSplTest, PromiseRejectInfo_GetPromise)
4777 {
4778     LocalScope scope(vm_);
4779     CalculateForTime();
4780     Local<StringRef> toStringPromise = StringRef::NewFromUtf8(vm_, "-3.14");
4781     Local<JSValueRef> promise(toStringPromise);
4782     Local<StringRef> toStringReason = StringRef::NewFromUtf8(vm_, "3.14");
4783     Local<JSValueRef> reason(toStringReason);
4784     void *data = static_cast<void *>(new std::string("promisereject"));
4785     PromiseRejectInfo promisereject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data);
4786     gettimeofday(&g_beginTime, nullptr);
4787     for (int i = 0; i < NUM_COUNT; i++) {
4788         promisereject.GetPromise();
4789     }
4790     gettimeofday(&g_endTime, nullptr);
4791     TEST_TIME(PromiseRejectInfo::GetPromise);
4792 }
4793 
HWTEST_F_L0(JSNApiSplTest,PromiseRejectInfo_GetReason)4794 HWTEST_F_L0(JSNApiSplTest, PromiseRejectInfo_GetReason)
4795 {
4796     LocalScope scope(vm_);
4797     CalculateForTime();
4798     Local<StringRef> toStringPromise = StringRef::NewFromUtf8(vm_, "-3.14");
4799     Local<JSValueRef> promise(toStringPromise);
4800     Local<StringRef> toStringReason = StringRef::NewFromUtf8(vm_, "3.14");
4801     Local<JSValueRef> reason(toStringReason);
4802     void *data = static_cast<void *>(new std::string("promisereject"));
4803     PromiseRejectInfo promisereject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data);
4804     gettimeofday(&g_beginTime, nullptr);
4805     for (int i = 0; i < NUM_COUNT; i++) {
4806         promisereject.GetReason();
4807     }
4808     gettimeofday(&g_endTime, nullptr);
4809     TEST_TIME(PromiseRejectInfo::GetReason);
4810 }
4811 
HWTEST_F_L0(JSNApiSplTest,PromiseRejectInfo_GetOperation)4812 HWTEST_F_L0(JSNApiSplTest, PromiseRejectInfo_GetOperation)
4813 {
4814     LocalScope scope(vm_);
4815     CalculateForTime();
4816     Local<StringRef> toStringPromise = StringRef::NewFromUtf8(vm_, "-3.14");
4817     Local<JSValueRef> promise(toStringPromise);
4818     Local<StringRef> toStringReason = StringRef::NewFromUtf8(vm_, "3.14");
4819     Local<JSValueRef> reason(toStringReason);
4820     void *data = static_cast<void *>(new std::string("promisereject"));
4821     PromiseRejectInfo promisereject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data);
4822     gettimeofday(&g_beginTime, nullptr);
4823     for (int i = 0; i < NUM_COUNT; i++) {
4824         promisereject.GetOperation();
4825     }
4826     gettimeofday(&g_endTime, nullptr);
4827     TEST_TIME(PromiseRejectInfo::GetOperation);
4828 }
4829 
HWTEST_F_L0(JSNApiSplTest,PromiseRejectInfo_GetData)4830 HWTEST_F_L0(JSNApiSplTest, PromiseRejectInfo_GetData)
4831 {
4832     LocalScope scope(vm_);
4833     CalculateForTime();
4834     Local<StringRef> toStringPromise = StringRef::NewFromUtf8(vm_, "-3.14");
4835     Local<JSValueRef> promise(toStringPromise);
4836     Local<StringRef> toStringReason = StringRef::NewFromUtf8(vm_, "3.14");
4837     Local<JSValueRef> reason(toStringReason);
4838     void *data = static_cast<void *>(new std::string("promisereject"));
4839     PromiseRejectInfo promisereject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data);
4840     gettimeofday(&g_beginTime, nullptr);
4841     for (int i = 0; i < NUM_COUNT; i++) {
4842         promisereject.GetData();
4843     }
4844     gettimeofday(&g_endTime, nullptr);
4845     TEST_TIME(PromiseRejectInfo::GetData);
4846 }
4847 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_Int32Value)4848 HWTEST_F_L0(JSNApiSplTest, JSValueRef_Int32Value)
4849 {
4850     LocalScope scope(vm_);
4851     CalculateForTime();
4852     int num = 123; // 123 = random number
4853     Local<JSValueRef> res = IntegerRef::New(vm_, num);
4854     gettimeofday(&g_beginTime, nullptr);
4855     for (int i = 0; i < NUM_COUNT; i++) {
4856         res->Int32Value(vm_);
4857     }
4858     gettimeofday(&g_endTime, nullptr);
4859     TEST_TIME(JSValueRef::Int32Value);
4860 }
4861 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToNumber)4862 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToNumber)
4863 {
4864     LocalScope scope(vm_);
4865     CalculateForTime();
4866     Local<StringRef> toString = StringRef::NewFromUtf8(vm_, "-123.3");
4867     Local<JSValueRef> toValue(toString);
4868     gettimeofday(&g_beginTime, nullptr);
4869     for (int i = 0; i < NUM_COUNT; i++) {
4870         toString->ToNumber(vm_);
4871     }
4872     gettimeofday(&g_endTime, nullptr);
4873     TEST_TIME(JSValueRef::ToNumber);
4874 }
4875 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsHole)4876 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsHole)
4877 {
4878     LocalScope scope(vm_);
4879     CalculateForTime();
4880     Local<JSValueRef> res = IntegerRef::New(vm_, 123);
4881     gettimeofday(&g_beginTime, nullptr);
4882     for (int i = 0; i < NUM_COUNT; i++) {
4883         res->IsHole();
4884     }
4885     gettimeofday(&g_endTime, nullptr);
4886     TEST_TIME(JSValueRef::IsHole);
4887 }
4888 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsTrue)4889 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsTrue)
4890 {
4891     LocalScope scope(vm_);
4892     CalculateForTime();
4893     int num = 123; // 123 = random number
4894     Local<JSValueRef> res = IntegerRef::New(vm_, num);
4895     gettimeofday(&g_beginTime, nullptr);
4896     for (int i = 0; i < NUM_COUNT; i++) {
4897         res->IsTrue();
4898     }
4899     gettimeofday(&g_endTime, nullptr);
4900     TEST_TIME(JSValueRef::IsTrue);
4901 }
4902 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsSymbol)4903 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsSymbol)
4904 {
4905     LocalScope scope(vm_);
4906     CalculateForTime();
4907     int num = 123; // 123 = random number
4908     Local<JSValueRef> res = IntegerRef::New(vm_, num);
4909     gettimeofday(&g_beginTime, nullptr);
4910     for (int i = 0; i < NUM_COUNT; i++) {
4911         res->IsSymbol(vm_);
4912     }
4913     gettimeofday(&g_endTime, nullptr);
4914     TEST_TIME(JSValueRef::IsSymbol);
4915 }
4916 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsObject)4917 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsObject)
4918 {
4919     LocalScope scope(vm_);
4920     CalculateForTime();
4921     int num = 123; // 123 = random number
4922     Local<JSValueRef> res = IntegerRef::New(vm_, num);
4923     gettimeofday(&g_beginTime, nullptr);
4924     for (int i = 0; i < NUM_COUNT; i++) {
4925         res->IsObject(vm_);
4926     }
4927     gettimeofday(&g_endTime, nullptr);
4928     TEST_TIME(JSValueRef::IsObject);
4929 }
4930 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsTypedArray)4931 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsTypedArray)
4932 {
4933     LocalScope scope(vm_);
4934     CalculateForTime();
4935     int num = 123; // 123 = random number
4936     Local<JSValueRef> res = IntegerRef::New(vm_, num);
4937     gettimeofday(&g_beginTime, nullptr);
4938     for (int i = 0; i < NUM_COUNT; i++) {
4939         res->IsTypedArray(vm_);
4940     }
4941     gettimeofday(&g_endTime, nullptr);
4942     TEST_TIME(JSValueRef::IsTypedArray);
4943 }
4944 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsNativePointer)4945 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsNativePointer)
4946 {
4947     LocalScope scope(vm_);
4948     CalculateForTime();
4949     int num = 123; // 123 = random number
4950     Local<JSValueRef> res = IntegerRef::New(vm_, num);
4951     gettimeofday(&g_beginTime, nullptr);
4952     for (int i = 0; i < NUM_COUNT; i++) {
4953         res->IsNativePointer(vm_);
4954     }
4955     gettimeofday(&g_endTime, nullptr);
4956     TEST_TIME(JSValueRef::IsNativePointer);
4957 }
4958 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsRegExp)4959 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsRegExp)
4960 {
4961     LocalScope scope(vm_);
4962     CalculateForTime();
4963     int num = 123; // 123 = random number
4964     Local<JSValueRef> res = IntegerRef::New(vm_, num);
4965     gettimeofday(&g_beginTime, nullptr);
4966     for (int i = 0; i < NUM_COUNT; i++) {
4967         res->IsRegExp(vm_);
4968     }
4969     gettimeofday(&g_endTime, nullptr);
4970     TEST_TIME(JSValueRef::IsRegExp);
4971 }
4972 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsArrayIterator)4973 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArrayIterator)
4974 {
4975     LocalScope scope(vm_);
4976     CalculateForTime();
4977     int num = 123; // 123 = random number
4978     Local<JSValueRef> res = IntegerRef::New(vm_, num);
4979     gettimeofday(&g_beginTime, nullptr);
4980     for (int i = 0; i < NUM_COUNT; i++) {
4981         res->IsArrayIterator(vm_);
4982     }
4983     gettimeofday(&g_endTime, nullptr);
4984     TEST_TIME(JSValueRef::IsArrayIterator);
4985 }
4986 
HWTEST_F_L0(JSNApiSplTest,EscapeLocalScope_gz)4987 HWTEST_F_L0(JSNApiSplTest, EscapeLocalScope_gz)
4988 {
4989     LocalScope scope(vm_);
4990     CalculateForTime();
4991     gettimeofday(&g_beginTime, nullptr);
4992     for (int i = 0; i < NUM_COUNT; i++) {
4993         EscapeLocalScope test(vm_);
4994     }
4995     gettimeofday(&g_endTime, nullptr);
4996     TEST_TIME(EscapeLocalScope::EscapeLocalScope);
4997 }
4998 
HWTEST_F_L0(JSNApiSplTest,EscapeLocalScope_Escape)4999 HWTEST_F_L0(JSNApiSplTest, EscapeLocalScope_Escape)
5000 {
5001     LocalScope scope(vm_);
5002     CalculateForTime();
5003     EscapeLocalScope test(vm_);
5004     int num = 3; // 3 = random number
5005     gettimeofday(&g_beginTime, nullptr);
5006     for (int i = 0; i < NUM_COUNT; i++) {
5007         test.Escape(ArrayRef::New(vm_, num));
5008     }
5009     gettimeofday(&g_endTime, nullptr);
5010     TEST_TIME(EscapeLocalScope::Escape);
5011 }
5012 
HWTEST_F_L0(JSNApiSplTest,JSExecutionScope_gz)5013 HWTEST_F_L0(JSNApiSplTest, JSExecutionScope_gz)
5014 {
5015     LocalScope scope(vm_);
5016     CalculateForTime();
5017     gettimeofday(&g_beginTime, nullptr);
5018     for (int i = 0; i < NUM_COUNT; i++) {
5019         JSExecutionScope res(vm_);
5020     }
5021     gettimeofday(&g_endTime, nullptr);
5022     TEST_TIME(JSExecutionScope::JSExecutionScope);
5023 }
5024 
HWTEST_F_L0(JSNApiSplTest,LocalScope_gz)5025 HWTEST_F_L0(JSNApiSplTest, LocalScope_gz)
5026 {
5027     CalculateForTime();
5028     gettimeofday(&g_beginTime, nullptr);
5029     for (int i = 0; i < NUM_COUNT; i++) {
5030         LocalScope scope(vm_);
5031     }
5032     gettimeofday(&g_endTime, nullptr);
5033     TEST_TIME(LocalScope::LocalScope);
5034 }
5035 
HWTEST_F_L0(JSNApiSplTest,PrimitiveRef_GetValue)5036 HWTEST_F_L0(JSNApiSplTest, PrimitiveRef_GetValue)
5037 {
5038     LocalScope scope(vm_);
5039     CalculateForTime();
5040     int num = 0; // 0 = random number
5041     Local<PrimitiveRef> intValue = IntegerRef::New(vm_, num);
5042     gettimeofday(&g_beginTime, nullptr);
5043     for (int i = 0; i < NUM_COUNT; i++) {
5044         intValue->GetValue(vm_);
5045     }
5046     gettimeofday(&g_endTime, nullptr);
5047     TEST_TIME(PrimitiveRef::GetValue);
5048 }
5049 
HWTEST_F_L0(JSNApiSplTest,IntegerRef_New)5050 HWTEST_F_L0(JSNApiSplTest, IntegerRef_New)
5051 {
5052     LocalScope scope(vm_);
5053     CalculateForTime();
5054     gettimeofday(&g_beginTime, nullptr);
5055     for (int i = 0; i < NUM_COUNT; i++) {
5056         IntegerRef::New(vm_, 0);
5057     }
5058     gettimeofday(&g_endTime, nullptr);
5059     TEST_TIME(IntegerRef::New);
5060 }
5061 
HWTEST_F_L0(JSNApiSplTest,IntegerRef_NewFromUnsigned)5062 HWTEST_F_L0(JSNApiSplTest, IntegerRef_NewFromUnsigned)
5063 {
5064     LocalScope scope(vm_);
5065     CalculateForTime();
5066     unsigned int res = 123; // 123 = random number
5067     gettimeofday(&g_beginTime, nullptr);
5068     for (int i = 0; i < NUM_COUNT; i++) {
5069         IntegerRef::NewFromUnsigned(vm_, res);
5070     }
5071     gettimeofday(&g_endTime, nullptr);
5072     TEST_TIME(IntegerRef::NewFromUnsigned);
5073 }
5074 
HWTEST_F_L0(JSNApiSplTest,IntegerRef_Value)5075 HWTEST_F_L0(JSNApiSplTest, IntegerRef_Value)
5076 {
5077     LocalScope scope(vm_);
5078     CalculateForTime();
5079     int num = 0; // 0 = random number
5080     Local<IntegerRef> res = IntegerRef::New(vm_, num);
5081     gettimeofday(&g_beginTime, nullptr);
5082     for (int i = 0; i < NUM_COUNT; i++) {
5083         res->Value();
5084     }
5085     gettimeofday(&g_endTime, nullptr);
5086     TEST_TIME(IntegerRef::Value);
5087 }
5088 
HWTEST_F_L0(JSNApiSplTest,NumberRef_New01)5089 HWTEST_F_L0(JSNApiSplTest, NumberRef_New01)
5090 {
5091     LocalScope scope(vm_);
5092     CalculateForTime();
5093     double res = 64; // 64 = random number
5094     gettimeofday(&g_beginTime, nullptr);
5095     for (int i = 0; i < NUM_COUNT; i++) {
5096         NumberRef::New(vm_, res);
5097     }
5098     gettimeofday(&g_endTime, nullptr);
5099     TEST_TIME(NumberRef::New01);
5100 }
5101 
HWTEST_F_L0(JSNApiSplTest,NumberRef_New02)5102 HWTEST_F_L0(JSNApiSplTest, NumberRef_New02)
5103 {
5104     LocalScope scope(vm_);
5105     CalculateForTime();
5106     int32_t res = 64; // 64 = random number
5107     gettimeofday(&g_beginTime, nullptr);
5108     for (int i = 0; i < NUM_COUNT; i++) {
5109         NumberRef::New(vm_, res);
5110     }
5111     gettimeofday(&g_endTime, nullptr);
5112     TEST_TIME(NumberRef::New02);
5113 }
5114 
HWTEST_F_L0(JSNApiSplTest,NumberRef_New03)5115 HWTEST_F_L0(JSNApiSplTest, NumberRef_New03)
5116 {
5117     LocalScope scope(vm_);
5118     CalculateForTime();
5119     uint32_t res = 64; // 64 = random number
5120     gettimeofday(&g_beginTime, nullptr);
5121     for (int i = 0; i < NUM_COUNT; i++) {
5122         NumberRef::New(vm_, res);
5123     }
5124     gettimeofday(&g_endTime, nullptr);
5125     TEST_TIME(NumberRef::New03);
5126 }
5127 
HWTEST_F_L0(JSNApiSplTest,NumberRef_New04)5128 HWTEST_F_L0(JSNApiSplTest, NumberRef_New04)
5129 {
5130     LocalScope scope(vm_);
5131     CalculateForTime();
5132     int64_t res = 64; // 64 = random number
5133     gettimeofday(&g_beginTime, nullptr);
5134     for (int i = 0; i < NUM_COUNT; i++) {
5135         NumberRef::New(vm_, res);
5136     }
5137     gettimeofday(&g_endTime, nullptr);
5138     TEST_TIME(NumberRef::New04);
5139 }
5140 
HWTEST_F_L0(JSNApiSplTest,NumberRef_Value)5141 HWTEST_F_L0(JSNApiSplTest, NumberRef_Value)
5142 {
5143     LocalScope scope(vm_);
5144     CalculateForTime();
5145     int32_t num = 0; // 0 = random number
5146     Local<NumberRef> res = NumberRef::New(vm_, num);
5147     gettimeofday(&g_beginTime, nullptr);
5148     for (int i = 0; i < NUM_COUNT; i++) {
5149         res->Value();
5150     }
5151     gettimeofday(&g_endTime, nullptr);
5152     TEST_TIME(NumberRef::Value);
5153 }
5154 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_Cast)5155 HWTEST_F_L0(JSNApiSplTest, ObjectRef_Cast)
5156 {
5157     LocalScope scope(vm_);
5158     CalculateForTime();
5159     Local<JSValueRef> value = ObjectRef::New(vm_);
5160     gettimeofday(&g_beginTime, nullptr);
5161     for (int i = 0; i < NUM_COUNT; i++) {
5162         ObjectRef::Cast(*value);
5163     }
5164     gettimeofday(&g_endTime, nullptr);
5165     TEST_TIME(ObjectRef::Cast);
5166 }
5167 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_New)5168 HWTEST_F_L0(JSNApiSplTest, ObjectRef_New)
5169 {
5170     LocalScope scope(vm_);
5171     CalculateForTime();
5172     gettimeofday(&g_beginTime, nullptr);
5173     for (int i = 0; i < NUM_COUNT; i++) {
5174         ObjectRef::New(vm_);
5175     }
5176     gettimeofday(&g_endTime, nullptr);
5177     TEST_TIME(ObjectRef::New);
5178 }
5179 
Detach1()5180 void *Detach1()
5181 {
5182     GTEST_LOG_(INFO) << "detach is running";
5183     return nullptr;
5184 }
5185 
Attach1(void * buffer)5186 void Attach1([[maybe_unused]] void *buffer)
5187 {
5188     GTEST_LOG_(INFO) << "attach is running";
5189 }
5190 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_Set02)5191 HWTEST_F_L0(JSNApiSplTest, ObjectRef_Set02)
5192 {
5193     LocalScope scope(vm_);
5194     CalculateForTime();
5195     Local<FunctionRef> object = ObjectRef::New(vm_);
5196     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
5197     Local<JSValueRef> value = ObjectRef::New(vm_);
5198     gettimeofday(&g_beginTime, nullptr);
5199     for (int i = 0; i < NUM_COUNT; i++) {
5200         object->Set(vm_, key, value);
5201     }
5202     gettimeofday(&g_endTime, nullptr);
5203     TEST_TIME(ObjectRef::Set02);
5204 }
5205 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_Set03)5206 HWTEST_F_L0(JSNApiSplTest, ObjectRef_Set03)
5207 {
5208     LocalScope scope(vm_);
5209     CalculateForTime();
5210     Local<FunctionRef> object = ObjectRef::New(vm_);
5211     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
5212     Local<JSValueRef> value = ObjectRef::New(vm_);
5213     gettimeofday(&g_beginTime, nullptr);
5214     for (int i = 0; i < NUM_COUNT; i++) {
5215         object->Set(vm_, key, value);
5216     }
5217     gettimeofday(&g_endTime, nullptr);
5218     TEST_TIME(ObjectRef::Set03);
5219 }
5220 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_SetAccessorProperty)5221 HWTEST_F_L0(JSNApiSplTest, ObjectRef_SetAccessorProperty)
5222 {
5223     LocalScope scope(vm_);
5224     CalculateForTime();
5225     Local<FunctionRef> object = ObjectRef::New(vm_);
5226     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
5227     Local<FunctionRef> target1 = FunctionRef::New(vm_, nullptr);
5228     Local<FunctionRef> target2 = FunctionRef::New(vm_, nullptr);
5229     gettimeofday(&g_beginTime, nullptr);
5230     for (int i = 0; i < NUM_COUNT; i++) {
5231         object->SetAccessorProperty(vm_, key, target1, target2);
5232     }
5233     gettimeofday(&g_endTime, nullptr);
5234     TEST_TIME(ObjectRef::SetAccessorProperty);
5235 }
5236 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_Get01)5237 HWTEST_F_L0(JSNApiSplTest, ObjectRef_Get01)
5238 {
5239     LocalScope scope(vm_);
5240     CalculateForTime();
5241     Local<FunctionRef> object = ObjectRef::New(vm_);
5242     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
5243     gettimeofday(&g_beginTime, nullptr);
5244     for (int i = 0; i < NUM_COUNT; i++) {
5245         object->Get(vm_, key);
5246     }
5247     gettimeofday(&g_endTime, nullptr);
5248     TEST_TIME(ObjectRef::Get01);
5249 }
5250 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_Get02)5251 HWTEST_F_L0(JSNApiSplTest, ObjectRef_Get02)
5252 {
5253     LocalScope scope(vm_);
5254     CalculateForTime();
5255     Local<FunctionRef> object = ObjectRef::New(vm_);
5256     int32_t key = 123; // 123 = random number
5257     gettimeofday(&g_beginTime, nullptr);
5258     for (int i = 0; i < NUM_COUNT; i++) {
5259         object->Get(vm_, key);
5260     }
5261     gettimeofday(&g_endTime, nullptr);
5262     TEST_TIME(ObjectRef::Get02);
5263 }
5264 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_GetOwnProperty)5265 HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetOwnProperty)
5266 {
5267     LocalScope scope(vm_);
5268     CalculateForTime();
5269     Local<ObjectRef> object = ObjectRef::New(vm_);
5270     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, "TestKey");
5271     Local<JSValueRef> value = ObjectRef::New(vm_);
5272     PropertyAttribute attribute(value, true, true, true);
5273     gettimeofday(&g_beginTime, nullptr);
5274     for (int i = 0; i < NUM_COUNT; i++) {
5275         object->GetOwnProperty(vm_, key, attribute);
5276     }
5277     gettimeofday(&g_endTime, nullptr);
5278     TEST_TIME(ObjectRef::GetOwnProperty);
5279 }
5280 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_GetOwnPropertyNames)5281 HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetOwnPropertyNames)
5282 {
5283     LocalScope scope(vm_);
5284     CalculateForTime();
5285     Local<ObjectRef> object = ObjectRef::New(vm_);
5286     Local<JSValueRef> value = ObjectRef::New(vm_);
5287     PropertyAttribute attribute(value, true, true, true);
5288     gettimeofday(&g_beginTime, nullptr);
5289     for (int i = 0; i < NUM_COUNT; i++) {
5290         object->GetOwnPropertyNames(vm_);
5291     }
5292     gettimeofday(&g_endTime, nullptr);
5293     TEST_TIME(ObjectRef::GetOwnPropertyNames);
5294 }
5295 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_GetAllPropertyNames)5296 HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetAllPropertyNames)
5297 {
5298     LocalScope scope(vm_);
5299     CalculateForTime();
5300     Local<ObjectRef> object = ObjectRef::New(vm_);
5301     uint32_t filter = 123; // 123 = random number
5302     gettimeofday(&g_beginTime, nullptr);
5303     for (int i = 0; i < NUM_COUNT; i++) {
5304         object->GetAllPropertyNames(vm_, filter);
5305     }
5306     gettimeofday(&g_endTime, nullptr);
5307     TEST_TIME(ObjectRef::GetAllPropertyNames);
5308 }
5309 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_GetOwnEnumerablePropertyNames)5310 HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetOwnEnumerablePropertyNames)
5311 {
5312     LocalScope scope(vm_);
5313     CalculateForTime();
5314     Local<ObjectRef> object = ObjectRef::New(vm_);
5315     gettimeofday(&g_beginTime, nullptr);
5316     for (int i = 0; i < NUM_COUNT; i++) {
5317         object->GetOwnEnumerablePropertyNames(vm_);
5318     }
5319     gettimeofday(&g_endTime, nullptr);
5320     TEST_TIME(ObjectRef::GetOwnEnumerablePropertyNames);
5321 }
5322 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_GetPrototype)5323 HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetPrototype)
5324 {
5325     LocalScope scope(vm_);
5326     CalculateForTime();
5327     Local<ObjectRef> object = ObjectRef::New(vm_);
5328     gettimeofday(&g_beginTime, nullptr);
5329     for (int i = 0; i < NUM_COUNT; i++) {
5330         object->GetPrototype(vm_);
5331     }
5332     gettimeofday(&g_endTime, nullptr);
5333     TEST_TIME(ObjectRef::GetPrototype);
5334 }
5335 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_SetPrototype)5336 HWTEST_F_L0(JSNApiSplTest, ObjectRef_SetPrototype)
5337 {
5338     LocalScope scope(vm_);
5339     CalculateForTime();
5340     Local<ObjectRef> object = ObjectRef::New(vm_);
5341     Local<ObjectRef> prototype = object->GetPrototype(vm_);
5342     gettimeofday(&g_beginTime, nullptr);
5343     for (int i = 0; i < NUM_COUNT; i++) {
5344         object->SetPrototype(vm_, prototype);
5345     }
5346     gettimeofday(&g_endTime, nullptr);
5347     TEST_TIME(ObjectRef::SetPrototype);
5348 }
5349 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_Freeze)5350 HWTEST_F_L0(JSNApiSplTest, ObjectRef_Freeze)
5351 {
5352     LocalScope scope(vm_);
5353     CalculateForTime();
5354     Local<ObjectRef> object = ObjectRef::New(vm_);
5355     gettimeofday(&g_beginTime, nullptr);
5356     for (int i = 0; i < NUM_COUNT; i++) {
5357         object->Freeze(vm_);
5358     }
5359     gettimeofday(&g_endTime, nullptr);
5360     TEST_TIME(ObjectRef::Freeze);
5361 }
5362 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_Seal)5363 HWTEST_F_L0(JSNApiSplTest, ObjectRef_Seal)
5364 {
5365     LocalScope scope(vm_);
5366     CalculateForTime();
5367     Local<ObjectRef> object = ObjectRef::New(vm_);
5368     gettimeofday(&g_beginTime, nullptr);
5369     for (int i = 0; i < NUM_COUNT; i++) {
5370         object->Seal(vm_);
5371     }
5372     gettimeofday(&g_endTime, nullptr);
5373     TEST_TIME(ObjectRef::Seal);
5374 }
5375 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_SetNativePointerFieldCount)5376 HWTEST_F_L0(JSNApiSplTest, ObjectRef_SetNativePointerFieldCount)
5377 {
5378     LocalScope scope(vm_);
5379     CalculateForTime();
5380     Local<ObjectRef> object = ObjectRef::New(vm_);
5381     int32_t input = 34; // 34 = random number
5382     gettimeofday(&g_beginTime, nullptr);
5383     for (int i = 0; i < NUM_COUNT; i++) {
5384         object->SetNativePointerFieldCount(vm_, input);
5385     }
5386     gettimeofday(&g_endTime, nullptr);
5387     TEST_TIME(ObjectRef::SetNativePointerFieldCount);
5388 }
5389 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_GetNativePointerFieldCount)5390 HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetNativePointerFieldCount)
5391 {
5392     LocalScope scope(vm_);
5393     CalculateForTime();
5394     Local<ObjectRef> object = ObjectRef::New(vm_);
5395     int32_t input = 34; // 34 = random number
5396     object->SetNativePointerFieldCount(vm_, input);
5397     gettimeofday(&g_beginTime, nullptr);
5398     for (int i = 0; i < NUM_COUNT; i++) {
5399         object->GetNativePointerFieldCount(vm_);
5400     }
5401     gettimeofday(&g_endTime, nullptr);
5402     TEST_TIME(ObjectRef::GetNativePointerFieldCount);
5403 }
5404 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_SetNativePointerField)5405 HWTEST_F_L0(JSNApiSplTest, ObjectRef_SetNativePointerField)
5406 {
5407     LocalScope scope(vm_);
5408     CalculateForTime();
5409     Local<ObjectRef> object = ObjectRef::New(vm_);
5410     NativePointerCallback callBack = nullptr;
5411     void *vp1 = static_cast<void *>(new std::string("test"));
5412     void *vp2 = static_cast<void *>(new std::string("test"));
5413     gettimeofday(&g_beginTime, nullptr);
5414     for (int i = 0; i < NUM_COUNT; i++) {
5415         object->SetNativePointerField(vm_, 33, vp1, callBack, vp2);
5416     }
5417     gettimeofday(&g_endTime, nullptr);
5418     TEST_TIME(ObjectRef::SetNativePointerField);
5419 }
5420 
HWTEST_F_L0(JSNApiSplTest,ObjectRef_GetNativePointerField)5421 HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetNativePointerField)
5422 {
5423     LocalScope scope(vm_);
5424     CalculateForTime();
5425     Local<ObjectRef> object = ObjectRef::New(vm_);
5426     NativePointerCallback callBack = nullptr;
5427     void *vp1 = static_cast<void *>(new std::string("test"));
5428     void *vp2 = static_cast<void *>(new std::string("test"));
5429     object->SetNativePointerField(vm_, 33, vp1, callBack, vp2);
5430     gettimeofday(&g_beginTime, nullptr);
5431     for (int i = 0; i < NUM_COUNT; i++) {
5432         object->GetNativePointerField(vm_, 33);
5433     }
5434     gettimeofday(&g_endTime, nullptr);
5435     TEST_TIME(ObjectRef::GetNativePointerField);
5436 }
5437 
HWTEST_F_L0(JSNApiSplTest,JSNApi_GetGlobalObject)5438 HWTEST_F_L0(JSNApiSplTest, JSNApi_GetGlobalObject)
5439 {
5440     LocalScope scope(vm_);
5441     CalculateForTime();
5442     gettimeofday(&g_beginTime, nullptr);
5443     for (int i = 0; i < NUM_COUNT; i++) {
5444         JSNApi::GetGlobalObject(vm_);
5445     }
5446     gettimeofday(&g_endTime, nullptr);
5447     TEST_TIME(JSNApi::GetGlobalObject);
5448 }
5449 
HWTEST_F_L0(JSNApiSplTest,JSNApi_ExecutePendingJob)5450 HWTEST_F_L0(JSNApiSplTest, JSNApi_ExecutePendingJob)
5451 {
5452     LocalScope scope(vm_);
5453     CalculateForTime();
5454     gettimeofday(&g_beginTime, nullptr);
5455     for (int i = 0; i < NUM_COUNT; i++) {
5456         JSNApi::ExecutePendingJob(vm_);
5457     }
5458     gettimeofday(&g_endTime, nullptr);
5459     TEST_TIME(JSNApi::ExecutePendingJob);
5460 }
5461 
HWTEST_F_L0(JSNApiSplTest,JSNApi_TriggerGC)5462 HWTEST_F_L0(JSNApiSplTest, JSNApi_TriggerGC)
5463 {
5464     LocalScope scope(vm_);
5465     CalculateForTime();
5466     gettimeofday(&g_beginTime, nullptr);
5467     for (int i = 0; i < NUM_COUNT; i++) {
5468         JSNApi::TriggerGC(vm_);
5469     }
5470     gettimeofday(&g_endTime, nullptr);
5471     TEST_TIME(JSNApi::TriggerGC);
5472 }
5473 
HWTEST_F_L0(JSNApiSplTest,JSNApi_ThrowException)5474 HWTEST_F_L0(JSNApiSplTest, JSNApi_ThrowException)
5475 {
5476     LocalScope scope(vm_);
5477     CalculateForTime();
5478     Local<StringRef> message = StringRef::NewFromUtf8(vm_, "ErrorTest");
5479     Local<JSValueRef> error = Exception::Error(vm_, message);
5480     gettimeofday(&g_beginTime, nullptr);
5481     for (int i = 0; i < NUM_COUNT; i++) {
5482         JSNApi::ThrowException(vm_, error);
5483     }
5484     gettimeofday(&g_endTime, nullptr);
5485     TEST_TIME(JSNApi::ThrowException);
5486 }
5487 
HWTEST_F_L0(JSNApiSplTest,JSNApi_GetAndClearUncaughtException)5488 HWTEST_F_L0(JSNApiSplTest, JSNApi_GetAndClearUncaughtException)
5489 {
5490     LocalScope scope(vm_);
5491     CalculateForTime();
5492     gettimeofday(&g_beginTime, nullptr);
5493     for (int i = 0; i < NUM_COUNT; i++) {
5494         JSNApi::GetAndClearUncaughtException(vm_);
5495     }
5496     gettimeofday(&g_endTime, nullptr);
5497     TEST_TIME(JSNApi::GetAndClearUncaughtException);
5498 }
5499 
HWTEST_F_L0(JSNApiSplTest,JSNApi_GetUncaughtException)5500 HWTEST_F_L0(JSNApiSplTest, JSNApi_GetUncaughtException)
5501 {
5502     LocalScope scope(vm_);
5503     CalculateForTime();
5504     gettimeofday(&g_beginTime, nullptr);
5505     for (int i = 0; i < NUM_COUNT; i++) {
5506         JSNApi::GetUncaughtException(vm_);
5507     }
5508     gettimeofday(&g_endTime, nullptr);
5509     TEST_TIME(JSNApi::GetUncaughtException);
5510 }
5511 
HWTEST_F_L0(JSNApiSplTest,JSNApi_HasPendingException)5512 HWTEST_F_L0(JSNApiSplTest, JSNApi_HasPendingException)
5513 {
5514     LocalScope scope(vm_);
5515     CalculateForTime();
5516     gettimeofday(&g_beginTime, nullptr);
5517     for (int i = 0; i < NUM_COUNT; i++) {
5518         JSNApi::HasPendingException(vm_);
5519     }
5520     gettimeofday(&g_endTime, nullptr);
5521     TEST_TIME(JSNApi::HasPendingException);
5522 }
5523 
HWTEST_F_L0(JSNApiSplTest,JSNApi_EnableUserUncaughtErrorHandler)5524 HWTEST_F_L0(JSNApiSplTest, JSNApi_EnableUserUncaughtErrorHandler)
5525 {
5526     LocalScope scope(vm_);
5527     CalculateForTime();
5528     gettimeofday(&g_beginTime, nullptr);
5529     for (int i = 0; i < NUM_COUNT; i++) {
5530         JSNApi::EnableUserUncaughtErrorHandler(vm_);
5531     }
5532     gettimeofday(&g_endTime, nullptr);
5533     TEST_TIME(JSNApi::EnableUserUncaughtErrorHandler);
5534 }
5535 
HWTEST_F_L0(JSNApiSplTest,JSNApi_StartDebugger)5536 HWTEST_F_L0(JSNApiSplTest, JSNApi_StartDebugger)
5537 {
5538     LocalScope scope(vm_);
5539     CalculateForTime();
5540     JSNApi::DebugOption res;
5541     res.libraryPath = "mytests";
5542     res.isDebugMode = true;
5543     gettimeofday(&g_beginTime, nullptr);
5544     for (int i = 0; i < NUM_COUNT; i++) {
5545         JSNApi::StartDebugger(vm_, res);
5546     }
5547     gettimeofday(&g_endTime, nullptr);
5548     TEST_TIME(JSNApi::StartDebugger);
5549 }
5550 
HWTEST_F_L0(JSNApiSplTest,JSNApi_StopDebugger)5551 HWTEST_F_L0(JSNApiSplTest, JSNApi_StopDebugger)
5552 {
5553     LocalScope scope(vm_);
5554     CalculateForTime();
5555     gettimeofday(&g_beginTime, nullptr);
5556     for (int i = 0; i < NUM_COUNT; i++) {
5557         JSNApi::StopDebugger(vm_);
5558     }
5559     gettimeofday(&g_endTime, nullptr);
5560     TEST_TIME(JSNApi::StopDebugger);
5561 }
5562 
HWTEST_F_L0(JSNApiSplTest,JsiRuntimeCallInfo_GetFunctionRef)5563 HWTEST_F_L0(JSNApiSplTest, JsiRuntimeCallInfo_GetFunctionRef)
5564 {
5565     LocalScope scope(vm_);
5566     CalculateForTime();
5567     JsiRuntimeCallInfo object;
5568     gettimeofday(&g_beginTime, nullptr);
5569     for (int i = 0; i < NUM_COUNT; i++) {
5570         object.GetFunctionRef();
5571     }
5572     gettimeofday(&g_endTime, nullptr);
5573     TEST_TIME(JsiRuntimeCallInfo::GetFunctionRef);
5574 }
5575 
HWTEST_F_L0(JSNApiSplTest,JsiRuntimeCallInfo_GetNewTargetRef)5576 HWTEST_F_L0(JSNApiSplTest, JsiRuntimeCallInfo_GetNewTargetRef)
5577 {
5578     LocalScope scope(vm_);
5579     CalculateForTime();
5580     JsiRuntimeCallInfo object;
5581     gettimeofday(&g_beginTime, nullptr);
5582     for (int i = 0; i < NUM_COUNT; i++) {
5583         object.GetNewTargetRef();
5584     }
5585     gettimeofday(&g_endTime, nullptr);
5586     TEST_TIME(JsiRuntimeCallInfo::GetNewTargetRef);
5587 }
5588 
HWTEST_F_L0(JSNApiSplTest,JsiRuntimeCallInfo_GetThisRef)5589 HWTEST_F_L0(JSNApiSplTest, JsiRuntimeCallInfo_GetThisRef)
5590 {
5591     LocalScope scope(vm_);
5592     CalculateForTime();
5593     JsiRuntimeCallInfo object;
5594     gettimeofday(&g_beginTime, nullptr);
5595     for (int i = 0; i < NUM_COUNT; i++) {
5596         object.GetThisRef();
5597     }
5598     gettimeofday(&g_endTime, nullptr);
5599     TEST_TIME(JsiRuntimeCallInfo::GetThisRef);
5600 }
5601 
HWTEST_F_L0(JSNApiSplTest,JsiRuntimeCallInfo_GetCallArgRef)5602 HWTEST_F_L0(JSNApiSplTest, JsiRuntimeCallInfo_GetCallArgRef)
5603 {
5604     LocalScope scope(vm_);
5605     CalculateForTime();
5606     JsiRuntimeCallInfo object;
5607     uint32_t idx = 123;
5608     gettimeofday(&g_beginTime, nullptr);
5609     for (int i = 0; i < NUM_COUNT; i++) {
5610         object.GetCallArgRef(idx);
5611     }
5612     gettimeofday(&g_endTime, nullptr);
5613     TEST_TIME(JsiRuntimeCallInfo::GetCallArgRef);
5614 }
5615 
HWTEST_F_L0(JSNApiSplTest,FunctionCallScope_Gz)5616 HWTEST_F_L0(JSNApiSplTest, FunctionCallScope_Gz)
5617 {
5618     LocalScope scope(vm_);
5619     CalculateForTime();
5620     gettimeofday(&g_beginTime, nullptr);
5621     for (int i = 0; i < NUM_COUNT; i++) {
5622         FunctionCallScope test(vm_);
5623     }
5624     gettimeofday(&g_endTime, nullptr);
5625     TEST_TIME(FunctionCallScope::FunctionCallScope);
5626 }
5627 
HWTEST_F_L0(JSNApiSplTest,IsSetIterator_Ture)5628 HWTEST_F_L0(JSNApiSplTest, IsSetIterator_Ture)
5629 {
5630     LocalScope scope(vm_);
5631     CalculateForTime();
5632     ObjectFactory *factory = vm_->GetFactory();
5633     JSHandle<JSTaggedValue> proto = thread_->GetEcmaVM()->GetGlobalEnv()->GetFunctionPrototype();
5634     JSHandle<JSHClass> setClass = factory->NewEcmaHClass(JSSet::SIZE, JSType::JS_SET, proto);
5635     JSHandle<JSSet> jsSet = JSHandle<JSSet>::Cast(factory->NewJSObjectWithInit(setClass));
5636     JSHandle<LinkedHashSet> linkedSet(LinkedHashSet::Create(thread_));
5637     jsSet->SetLinkedSet(thread_, linkedSet);
5638     JSHandle<JSSetIterator> jsSetIter = factory->NewJSSetIterator(jsSet, IterationKind::KEY);
5639     JSHandle<JSTaggedValue> setiter = JSHandle<JSTaggedValue>::Cast(jsSetIter);
5640     gettimeofday(&g_beginTime, nullptr);
5641     for (int i = 0; i < NUM_COUNT; i++) {
5642         ASSERT_TRUE(JSNApiHelper::ToLocal<JSValueRef>(setiter)->IsSetIterator(vm_));
5643     }
5644     gettimeofday(&g_endTime, nullptr);
5645     TEST_TIME(JSValueRef::IsSetIterator);
5646 }
5647 
HWTEST_F_L0(JSNApiSplTest,IsSetIterator_False)5648 HWTEST_F_L0(JSNApiSplTest, IsSetIterator_False)
5649 {
5650     LocalScope scope(vm_);
5651     CalculateForTime();
5652     Local<JSValueRef> object = ObjectRef::New(vm_);
5653     gettimeofday(&g_beginTime, nullptr);
5654     for (int i = 0; i < NUM_COUNT; i++) {
5655         ASSERT_FALSE(object->IsSetIterator(vm_));
5656     }
5657     gettimeofday(&g_endTime, nullptr);
5658     TEST_TIME(JSValueRef::IsSetIterator);
5659 }
5660 
HWTEST_F_L0(JSNApiSplTest,IsUint16Array_True)5661 HWTEST_F_L0(JSNApiSplTest, IsUint16Array_True)
5662 {
5663     LocalScope scope(vm_);
5664     CalculateForTime();
5665     int32_t num = 30;       // 30 = ArrayBuff length
5666     int32_t byteOffset = 4; // 4 = Offset
5667     int32_t length = 6;     // 6 = length
5668     Local<ArrayBufferRef> buffer = ArrayBufferRef::New(vm_, num);
5669     Local<Uint16ArrayRef> object = Uint16ArrayRef::New(vm_, buffer, byteOffset, length);
5670     gettimeofday(&g_beginTime, nullptr);
5671     for (int i = 0; i < NUM_COUNT; i++) {
5672         ASSERT_TRUE(object->IsUint16Array(vm_));
5673     }
5674     gettimeofday(&g_endTime, nullptr);
5675     TEST_TIME(JSValueRef::IsUint16Array);
5676 }
5677 
HWTEST_F_L0(JSNApiSplTest,IsUint16Array_False)5678 HWTEST_F_L0(JSNApiSplTest, IsUint16Array_False)
5679 {
5680     LocalScope scope(vm_);
5681     CalculateForTime();
5682     Local<JSValueRef> object = ObjectRef::New(vm_);
5683     gettimeofday(&g_beginTime, nullptr);
5684     for (int i = 0; i < NUM_COUNT; i++) {
5685         ASSERT_FALSE(object->IsUint16Array(vm_));
5686     }
5687     gettimeofday(&g_endTime, nullptr);
5688     TEST_TIME(JSValueRef::IsUint16Array);
5689 }
5690 
HWTEST_F_L0(JSNApiSplTest,IsInt32Array_True)5691 HWTEST_F_L0(JSNApiSplTest, IsInt32Array_True)
5692 {
5693     LocalScope scope(vm_);
5694     CalculateForTime();
5695     int32_t num = 30;       // 30 = ArrayBuff length
5696     int32_t byteOffset = 4; // 4 = Offset
5697     int32_t length = 6;     // 6 = length
5698     Local<ArrayBufferRef> buffer = ArrayBufferRef::New(vm_, num);
5699     Local<Int32ArrayRef> object = Int32ArrayRef::New(vm_, buffer, byteOffset, length);
5700     gettimeofday(&g_beginTime, nullptr);
5701     for (int i = 0; i < NUM_COUNT; i++) {
5702         ASSERT_TRUE(object->IsInt32Array(vm_));
5703     }
5704     gettimeofday(&g_endTime, nullptr);
5705     TEST_TIME(JSValueRef::IsInt32Array);
5706 }
5707 
HWTEST_F_L0(JSNApiSplTest,IsInt32Array_False)5708 HWTEST_F_L0(JSNApiSplTest, IsInt32Array_False)
5709 {
5710     LocalScope scope(vm_);
5711     CalculateForTime();
5712     Local<JSValueRef> object = ObjectRef::New(vm_);
5713     gettimeofday(&g_beginTime, nullptr);
5714     for (int i = 0; i < NUM_COUNT; i++) {
5715         ASSERT_FALSE(object->IsInt32Array(vm_));
5716     }
5717     gettimeofday(&g_endTime, nullptr);
5718     TEST_TIME(JSValueRef::IsInt32Array);
5719 }
5720 
HWTEST_F_L0(JSNApiSplTest,IsJSPrimitiveString_False)5721 HWTEST_F_L0(JSNApiSplTest, IsJSPrimitiveString_False)
5722 {
5723     LocalScope scope(vm_);
5724     CalculateForTime();
5725     Local<ObjectRef> object = ObjectRef::New(vm_);
5726     gettimeofday(&g_beginTime, nullptr);
5727     for (int i = 0; i < NUM_COUNT; i++) {
5728         ASSERT_FALSE(object->IsJSPrimitiveString(vm_));
5729     }
5730     gettimeofday(&g_endTime, nullptr);
5731     TEST_TIME(JSValueRef::IsJSPrimitiveString);
5732 }
5733 
HWTEST_F_L0(JSNApiSplTest,IsGeneratorObject_True)5734 HWTEST_F_L0(JSNApiSplTest, IsGeneratorObject_True)
5735 {
5736     LocalScope scope(vm_);
5737     CalculateForTime();
5738     ObjectFactory *factory = vm_->GetFactory();
5739     auto env = vm_->GetGlobalEnv();
5740     JSHandle<JSTaggedValue> genFunc = env->GetGeneratorFunctionFunction();
5741     JSHandle<JSGeneratorObject> genObjHandleVal = factory->NewJSGeneratorObject(genFunc);
5742     JSHandle<JSHClass> hclass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
5743     JSHandle<JSFunction> generatorFunc = JSHandle<JSFunction>::Cast(factory->NewJSObject(hclass));
5744     JSFunction::InitializeJSFunction(thread_, generatorFunc, FunctionKind::GENERATOR_FUNCTION);
5745     JSHandle<GeneratorContext> generatorContext = factory->NewGeneratorContext();
5746     generatorContext->SetMethod(thread_, generatorFunc.GetTaggedValue());
5747     JSHandle<JSTaggedValue> generatorContextVal = JSHandle<JSTaggedValue>::Cast(generatorContext);
5748     genObjHandleVal->SetGeneratorContext(thread_, generatorContextVal.GetTaggedValue());
5749     JSHandle<JSTaggedValue> genObjTagHandleVal = JSHandle<JSTaggedValue>::Cast(genObjHandleVal);
5750     Local<GeneratorObjectRef> genObjectRef = JSNApiHelper::ToLocal<GeneratorObjectRef>(genObjTagHandleVal);
5751     gettimeofday(&g_beginTime, nullptr);
5752     for (int i = 0; i < NUM_COUNT; i++) {
5753         ASSERT_TRUE(genObjectRef->IsGeneratorObject(vm_));
5754     }
5755     gettimeofday(&g_endTime, nullptr);
5756     TEST_TIME(JSValueRef::IsGeneratorObject);
5757 }
5758 
HWTEST_F_L0(JSNApiSplTest,IsGeneratorObject_False)5759 HWTEST_F_L0(JSNApiSplTest, IsGeneratorObject_False)
5760 {
5761     LocalScope scope(vm_);
5762     CalculateForTime();
5763     Local<ObjectRef> object = ObjectRef::New(vm_);
5764     gettimeofday(&g_beginTime, nullptr);
5765     for (int i = 0; i < NUM_COUNT; i++) {
5766         ASSERT_FALSE(object->IsGeneratorObject(vm_));
5767     }
5768     gettimeofday(&g_endTime, nullptr);
5769     TEST_TIME(JSValueRef::IsGeneratorObject);
5770 }
5771 
HWTEST_F_L0(JSNApiSplTest,IsJSPrimitiveSymbol_False)5772 HWTEST_F_L0(JSNApiSplTest, IsJSPrimitiveSymbol_False)
5773 {
5774     LocalScope scope(vm_);
5775     CalculateForTime();
5776     Local<ObjectRef> object = ObjectRef::New(vm_);
5777     gettimeofday(&g_beginTime, nullptr);
5778     for (int i = 0; i < NUM_COUNT; i++) {
5779         ASSERT_FALSE(object->IsJSPrimitiveSymbol(vm_));
5780     }
5781     gettimeofday(&g_endTime, nullptr);
5782     TEST_TIME(JSValueRef::IsJSPrimitiveSymbol);
5783 }
5784 
HWTEST_F_L0(JSNApiSplTest,IsAsyncGeneratorObject_True)5785 HWTEST_F_L0(JSNApiSplTest, IsAsyncGeneratorObject_True)
5786 {
5787     LocalScope scope(vm_);
5788     CalculateForTime();
5789     auto factory = vm_->GetFactory();
5790     auto env = vm_->GetGlobalEnv();
5791     JSHandle<JSAsyncGeneratorObject> asyncGenObj =
5792         factory->NewJSAsyncGeneratorObject(env->GetAsyncGeneratorFunctionFunction());
5793     JSHandle<JSTaggedValue> genObjTagHandleVal = JSHandle<JSTaggedValue>::Cast(asyncGenObj);
5794     Local<GeneratorObjectRef> genObjectRef = JSNApiHelper::ToLocal<GeneratorObjectRef>(genObjTagHandleVal);
5795     gettimeofday(&g_beginTime, nullptr);
5796     for (int i = 0; i < NUM_COUNT; i++) {
5797         ASSERT_TRUE(genObjectRef->IsAsyncGeneratorObject(vm_));
5798     }
5799     gettimeofday(&g_endTime, nullptr);
5800     TEST_TIME(JSValueRef::IsAsyncGeneratorObject);
5801 }
5802 
HWTEST_F_L0(JSNApiSplTest,IsAsyncGeneratorObject_False)5803 HWTEST_F_L0(JSNApiSplTest, IsAsyncGeneratorObject_False)
5804 {
5805     LocalScope scope(vm_);
5806     CalculateForTime();
5807     Local<JSValueRef> object = ObjectRef::New(vm_);
5808     gettimeofday(&g_beginTime, nullptr);
5809     for (int i = 0; i < NUM_COUNT; i++) {
5810         object->IsAsyncGeneratorObject(vm_);
5811     }
5812     gettimeofday(&g_endTime, nullptr);
5813     TEST_TIME(JSValueRef::IsAsyncGeneratorObject);
5814 }
5815 
HWTEST_F_L0(JSNApiSplTest,IsModuleNamespaceObject_True)5816 HWTEST_F_L0(JSNApiSplTest, IsModuleNamespaceObject_True)
5817 {
5818     LocalScope scope(vm_);
5819     CalculateForTime();
5820     ObjectFactory *factory = vm_->GetFactory();
5821     JSHandle<ModuleNamespace> moduleNamespace = factory->NewModuleNamespace();
5822     JSHandle<JSTaggedValue> modname = JSHandle<JSTaggedValue>::Cast(moduleNamespace);
5823     gettimeofday(&g_beginTime, nullptr);
5824     for (int i = 0; i < NUM_COUNT; i++) {
5825         JSNApiHelper::ToLocal<ObjectRef>(modname)->IsModuleNamespaceObject(vm_);
5826     }
5827     gettimeofday(&g_endTime, nullptr);
5828     TEST_TIME(JSValueRef::IsModuleNamespaceObject);
5829 }
5830 
HWTEST_F_L0(JSNApiSplTest,IsModuleNamespaceObject_False)5831 HWTEST_F_L0(JSNApiSplTest, IsModuleNamespaceObject_False)
5832 {
5833     LocalScope scope(vm_);
5834     CalculateForTime();
5835     Local<JSValueRef> object = ObjectRef::New(vm_);
5836     gettimeofday(&g_beginTime, nullptr);
5837     for (int i = 0; i < NUM_COUNT; i++) {
5838         object->IsModuleNamespaceObject(vm_);
5839     }
5840     gettimeofday(&g_endTime, nullptr);
5841     TEST_TIME(JSValueRef::IsModuleNamespaceObject);
5842 }
5843 
HWTEST_F_L0(JSNApiSplTest,IsSharedArrayBuffer_True)5844 HWTEST_F_L0(JSNApiSplTest, IsSharedArrayBuffer_True)
5845 {
5846     LocalScope scope(vm_);
5847     CalculateForTime();
5848     auto *factory = vm_->GetFactory();
5849     int32_t num = 40; // 40 = ArrayBuffer length
5850     JSHandle<JSArrayBuffer> jsArrayBuffer = factory->NewJSSharedArrayBuffer(num);
5851     JSHandle<JSTaggedValue> SAbuffer = JSHandle<JSTaggedValue>::Cast(jsArrayBuffer);
5852     gettimeofday(&g_beginTime, nullptr);
5853     for (int i = 0; i < NUM_COUNT; i++) {
5854         JSNApiHelper::ToLocal<ArrayRef>(SAbuffer)->IsSharedArrayBuffer(vm_);
5855     }
5856     gettimeofday(&g_endTime, nullptr);
5857     TEST_TIME(JSValueRef::IsSharedArrayBuffer);
5858 }
5859 
HWTEST_F_L0(JSNApiSplTest,IsSharedArrayBuffer_False)5860 HWTEST_F_L0(JSNApiSplTest, IsSharedArrayBuffer_False)
5861 {
5862     LocalScope scope(vm_);
5863     CalculateForTime();
5864     Local<JSValueRef> object = ObjectRef::New(vm_);
5865     gettimeofday(&g_beginTime, nullptr);
5866     for (int i = 0; i < NUM_COUNT; i++) {
5867         object->IsSharedArrayBuffer(vm_);
5868     }
5869     gettimeofday(&g_endTime, nullptr);
5870     TEST_TIME(JSValueRef::IsSharedArrayBuffer);
5871 }
5872 
HWTEST_F_L0(JSNApiSplTest,IsStrictEquals_True)5873 HWTEST_F_L0(JSNApiSplTest, IsStrictEquals_True)
5874 {
5875     LocalScope scope(vm_);
5876     CalculateForTime();
5877     Local<ObjectRef> object = ObjectRef::New(vm_);
5878     Local<ObjectRef> object2 = ObjectRef::New(vm_);
5879     gettimeofday(&g_beginTime, nullptr);
5880     for (int i = 0; i < NUM_COUNT; i++) {
5881         object->IsStrictEquals(vm_, object2);
5882     }
5883     gettimeofday(&g_endTime, nullptr);
5884     TEST_TIME(JSValueRef::IsStrictEquals);
5885 }
5886 
HWTEST_F_L0(JSNApiSplTest,IsStrictEquals_False)5887 HWTEST_F_L0(JSNApiSplTest, IsStrictEquals_False)
5888 {
5889     LocalScope scope(vm_);
5890     CalculateForTime();
5891     Local<JSValueRef> object = ObjectRef::New(vm_);
5892     Local<JSValueRef> target1 = StringRef::NewFromUtf8(vm_, "1");
5893     gettimeofday(&g_beginTime, nullptr);
5894     for (int i = 0; i < NUM_COUNT; i++) {
5895         object->IsStrictEquals(vm_, target1);
5896     }
5897     gettimeofday(&g_endTime, nullptr);
5898     TEST_TIME(JSValueRef::IsStrictEquals);
5899 }
5900 
HWTEST_F_L0(JSNApiSplTest,IsQueue_Frue)5901 HWTEST_F_L0(JSNApiSplTest, IsQueue_Frue)
5902 {
5903     LocalScope scope(vm_);
5904     CalculateForTime();
5905     ObjectFactory *factory = vm_->GetFactory();
5906     JSThread *thread = vm_->GetJSThread();
5907     JSHandle<JSTaggedValue> proto = thread->GetEcmaVM()->GetGlobalEnv()->GetFunctionPrototype();
5908     JSHandle<JSHClass> queueClass = factory->NewEcmaHClass(JSAPIQueue::SIZE, JSType::JS_API_QUEUE, proto);
5909     JSHandle<JSAPIQueue> jsQueue = JSHandle<JSAPIQueue>::Cast(factory->NewJSObjectWithInit(queueClass));
5910     JSHandle<TaggedArray> newElements = factory->NewTaggedArray(JSAPIQueue::DEFAULT_CAPACITY_LENGTH);
5911     jsQueue->SetLength(thread, JSTaggedValue(0));
5912     jsQueue->SetFront(0);
5913     jsQueue->SetTail(0);
5914     jsQueue->SetElements(thread, newElements);
5915     JSHandle<JSTaggedValue> Que = JSHandle<JSTaggedValue>::Cast(jsQueue);
5916     gettimeofday(&g_beginTime, nullptr);
5917     for (int i = 0; i < NUM_COUNT; i++) {
5918         JSNApiHelper::ToLocal<ArrayRef>(Que)->IsDeque(vm_);
5919     }
5920     gettimeofday(&g_endTime, nullptr);
5921     TEST_TIME(JSValueRef::IsQueue);
5922 }
5923 
HWTEST_F_L0(JSNApiSplTest,IsQueue_False)5924 HWTEST_F_L0(JSNApiSplTest, IsQueue_False)
5925 {
5926     LocalScope scope(vm_);
5927     CalculateForTime();
5928     Local<JSValueRef> object = ObjectRef::New(vm_);
5929     gettimeofday(&g_beginTime, nullptr);
5930     for (int i = 0; i < NUM_COUNT; i++) {
5931         object->IsQueue(vm_);
5932     }
5933     gettimeofday(&g_endTime, nullptr);
5934     TEST_TIME(JSValueRef::IsQueue);
5935 }
5936 
HWTEST_F_L0(JSNApiSplTest,IsStack_True)5937 HWTEST_F_L0(JSNApiSplTest, IsStack_True)
5938 {
5939     LocalScope scope(vm_);
5940     CalculateForTime();
5941     ObjectFactory *factory = vm_->GetFactory();
5942     JSThread *thread = vm_->GetJSThread();
5943     JSHandle<JSTaggedValue> proto = thread->GetEcmaVM()->GetGlobalEnv()->GetFunctionPrototype();
5944     JSHandle<JSHClass> stackClass = factory->NewEcmaHClass(JSAPIStack::SIZE, JSType::JS_API_STACK, proto);
5945     JSHandle<JSAPIStack> jsStack = JSHandle<JSAPIStack>::Cast(factory->NewJSObjectWithInit(stackClass));
5946     jsStack->SetTop(0);
5947     JSHandle<JSTaggedValue> stcak = JSHandle<JSTaggedValue>::Cast(jsStack);
5948     gettimeofday(&g_beginTime, nullptr);
5949     for (int i = 0; i < NUM_COUNT; i++) {
5950         JSNApiHelper::ToLocal<ArrayRef>(stcak)->IsStack(vm_);
5951     }
5952     gettimeofday(&g_endTime, nullptr);
5953     TEST_TIME(JSValueRef::IsStack);
5954 }
5955 
HWTEST_F_L0(JSNApiSplTest,IsStack_False)5956 HWTEST_F_L0(JSNApiSplTest, IsStack_False)
5957 {
5958     LocalScope scope(vm_);
5959     CalculateForTime();
5960     Local<JSValueRef> object = ObjectRef::New(vm_);
5961     gettimeofday(&g_beginTime, nullptr);
5962     for (int i = 0; i < NUM_COUNT; i++) {
5963         object->IsStack(vm_);
5964     }
5965     gettimeofday(&g_endTime, nullptr);
5966     TEST_TIME(JSValueRef::IsStack);
5967 }
5968 
HWTEST_F_L0(JSNApiSplTest,IsTreeMap_True)5969 HWTEST_F_L0(JSNApiSplTest, IsTreeMap_True)
5970 {
5971     LocalScope scope(vm_);
5972     CalculateForTime();
5973     ObjectFactory *factory = vm_->GetFactory();
5974     JSThread *thread = vm_->GetJSThread();
5975     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
5976     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
5977     JSHandle<JSHClass> mapClass = factory->NewEcmaHClass(JSAPITreeMap::SIZE, JSType::JS_API_TREE_MAP, proto);
5978     JSHandle<JSAPITreeMap> jsTreeMap = JSHandle<JSAPITreeMap>::Cast(factory->NewJSObjectWithInit(mapClass));
5979     JSHandle<TaggedTreeMap> treeMap(thread, TaggedTreeMap::Create(thread));
5980     jsTreeMap->SetTreeMap(thread, treeMap);
5981     JSHandle<JSTaggedValue> treapp = JSHandle<JSTaggedValue>::Cast(jsTreeMap);
5982     gettimeofday(&g_beginTime, nullptr);
5983     for (int i = 0; i < NUM_COUNT; i++) {
5984         JSNApiHelper::ToLocal<ArrayRef>(treapp)->IsTreeMap(vm_);
5985     }
5986     gettimeofday(&g_endTime, nullptr);
5987     TEST_TIME(JSValueRef::IsTreeMap);
5988 }
5989 
HWTEST_F_L0(JSNApiSplTest,IsTreeMap_False)5990 HWTEST_F_L0(JSNApiSplTest, IsTreeMap_False)
5991 {
5992     LocalScope scope(vm_);
5993     CalculateForTime();
5994     Local<JSValueRef> object = ObjectRef::New(vm_);
5995     gettimeofday(&g_beginTime, nullptr);
5996     for (int i = 0; i < NUM_COUNT; i++) {
5997         object->IsTreeMap(vm_);
5998     }
5999     gettimeofday(&g_endTime, nullptr);
6000     TEST_TIME(JSValueRef::IsTreeMap);
6001 }
6002 
HWTEST_F_L0(JSNApiSplTest,IsTreeSet_True)6003 HWTEST_F_L0(JSNApiSplTest, IsTreeSet_True)
6004 {
6005     LocalScope scope(vm_);
6006     CalculateForTime();
6007     ObjectFactory *factory = vm_->GetFactory();
6008     JSThread *thread = vm_->GetJSThread();
6009     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
6010     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
6011     JSHandle<JSHClass> setClass = factory->NewEcmaHClass(JSAPITreeSet::SIZE, JSType::JS_API_TREE_SET, proto);
6012     JSHandle<JSAPITreeSet> jsTreeSet = JSHandle<JSAPITreeSet>::Cast(factory->NewJSObjectWithInit(setClass));
6013     JSHandle<TaggedTreeSet> treeSet(thread, TaggedTreeSet::Create(thread));
6014     jsTreeSet->SetTreeSet(thread, treeSet);
6015     JSHandle<JSTaggedValue> tresett = JSHandle<JSTaggedValue>::Cast(jsTreeSet);
6016     gettimeofday(&g_beginTime, nullptr);
6017     for (int i = 0; i < NUM_COUNT; i++) {
6018         JSNApiHelper::ToLocal<ArrayRef>(tresett)->IsTreeSet(vm_);
6019     }
6020     gettimeofday(&g_endTime, nullptr);
6021     TEST_TIME(JSValueRef::IsTreeSet);
6022 }
6023 
HWTEST_F_L0(JSNApiSplTest,IsTreeSet_False)6024 HWTEST_F_L0(JSNApiSplTest, IsTreeSet_False)
6025 {
6026     LocalScope scope(vm_);
6027     CalculateForTime();
6028     Local<JSValueRef> object = ObjectRef::New(vm_);
6029     gettimeofday(&g_beginTime, nullptr);
6030     for (int i = 0; i < NUM_COUNT; i++) {
6031         object->IsTreeSet(vm_);
6032     }
6033     gettimeofday(&g_endTime, nullptr);
6034     TEST_TIME(JSValueRef::IsTreeSet);
6035 }
6036 
HWTEST_F_L0(JSNApiSplTest,IsVector_True)6037 HWTEST_F_L0(JSNApiSplTest, IsVector_True)
6038 {
6039     LocalScope scope(vm_);
6040     CalculateForTime();
6041     ObjectFactory *factory = vm_->GetFactory();
6042     JSThread *thread = vm_->GetJSThread();
6043     JSHandle<JSTaggedValue> proto = thread->GetEcmaVM()->GetGlobalEnv()->GetFunctionPrototype();
6044     JSHandle<JSHClass> vectorClass = factory->NewEcmaHClass(JSAPIVector::SIZE, JSType::JS_API_VECTOR, proto);
6045     JSHandle<JSAPIVector> jsVector = JSHandle<JSAPIVector>::Cast(factory->NewJSObjectWithInit(vectorClass));
6046     jsVector->SetLength(0);
6047     JSHandle<JSTaggedValue> vectt = JSHandle<JSTaggedValue>::Cast(jsVector);
6048     gettimeofday(&g_beginTime, nullptr);
6049     for (int i = 0; i < NUM_COUNT; i++) {
6050         JSNApiHelper::ToLocal<ArrayRef>(vectt)->IsVector(vm_);
6051     }
6052     gettimeofday(&g_endTime, nullptr);
6053     TEST_TIME(JSValueRef::IsVector);
6054 }
6055 
HWTEST_F_L0(JSNApiSplTest,Parse_False)6056 HWTEST_F_L0(JSNApiSplTest, Parse_False)
6057 {
6058     LocalScope scope(vm_);
6059     CalculateForTime();
6060     const char16_t *utf16 = u"您好,华为!";
6061     Local<StringRef> str = StringRef::NewFromUtf8(vm_, "abc");
6062     Local<StringRef> str2 = StringRef::NewFromUtf16(vm_, utf16);
6063     gettimeofday(&g_beginTime, nullptr);
6064     for (int i = 0; i < NUM_COUNT; i++) {
6065         JSON::Parse(vm_, str);
6066     }
6067     gettimeofday(&g_endTime, nullptr);
6068     TEST_TIME(JSValueRef::Parse);
6069     gettimeofday(&g_beginTime, nullptr);
6070     for (int i = 0; i < NUM_COUNT; i++) {
6071         JSON::Parse(vm_, str2);
6072     }
6073     gettimeofday(&g_endTime, nullptr);
6074     TEST_TIME(JSValueRef::Parse);
6075 }
6076 
HWTEST_F_L0(JSNApiSplTest,Stringify)6077 HWTEST_F_L0(JSNApiSplTest, Stringify)
6078 {
6079     LocalScope scope(vm_);
6080     CalculateForTime();
6081     Local<JSValueRef> object = ObjectRef::New(vm_);
6082     gettimeofday(&g_beginTime, nullptr);
6083     for (int i = 0; i < NUM_COUNT; i++) {
6084         JSON::Stringify(vm_, object);
6085     }
6086     gettimeofday(&g_endTime, nullptr);
6087     TEST_TIME(JSValueRef::Stringify);
6088 }
6089 
HWTEST_F_L0(JSNApiSplTest,Error)6090 HWTEST_F_L0(JSNApiSplTest, Error)
6091 {
6092     LocalScope scope(vm_);
6093     CalculateForTime();
6094     gettimeofday(&g_beginTime, nullptr);
6095     for (int i = 0; i < NUM_COUNT; i++) {
6096         (void)Exception::Error(vm_, StringRef::NewFromUtf8(vm_, "test error"));
6097     }
6098     gettimeofday(&g_endTime, nullptr);
6099     TEST_TIME(JSValueRef::Error);
6100 }
6101 
HWTEST_F_L0(JSNApiSplTest,RangeError)6102 HWTEST_F_L0(JSNApiSplTest, RangeError)
6103 {
6104     LocalScope scope(vm_);
6105     CalculateForTime();
6106     gettimeofday(&g_beginTime, nullptr);
6107     for (int i = 0; i < NUM_COUNT; i++) {
6108         (void)Exception::RangeError(vm_, StringRef::NewFromUtf8(vm_, "test range error"));
6109     }
6110     gettimeofday(&g_endTime, nullptr);
6111     TEST_TIME(JSValueRef::RangeError);
6112 }
6113 
HWTEST_F_L0(JSNApiSplTest,ReferenceError)6114 HWTEST_F_L0(JSNApiSplTest, ReferenceError)
6115 {
6116     LocalScope scope(vm_);
6117     CalculateForTime();
6118     gettimeofday(&g_beginTime, nullptr);
6119     for (int i = 0; i < NUM_COUNT; i++) {
6120         (void)Exception::ReferenceError(vm_, StringRef::NewFromUtf8(vm_, "test reference error"));
6121     }
6122     gettimeofday(&g_endTime, nullptr);
6123     TEST_TIME(JSValueRef::ReferenceError);
6124 }
HWTEST_F_L0(JSNApiSplTest,SyntaxError)6125 HWTEST_F_L0(JSNApiSplTest, SyntaxError)
6126 {
6127     LocalScope scope(vm_);
6128     CalculateForTime();
6129     gettimeofday(&g_beginTime, nullptr);
6130     for (int i = 0; i < NUM_COUNT; i++) {
6131         (void)Exception::SyntaxError(vm_, StringRef::NewFromUtf8(vm_, "test syntax error"));
6132     }
6133     gettimeofday(&g_endTime, nullptr);
6134     TEST_TIME(JSValueRef::SyntaxError);
6135 }
6136 
HWTEST_F_L0(JSNApiSplTest,TypeError)6137 HWTEST_F_L0(JSNApiSplTest, TypeError)
6138 {
6139     LocalScope scope(vm_);
6140     CalculateForTime();
6141     gettimeofday(&g_beginTime, nullptr);
6142     for (int i = 0; i < NUM_COUNT; i++) {
6143         (void)Exception::TypeError(vm_, StringRef::NewFromUtf8(vm_, "test type error"));
6144     }
6145     gettimeofday(&g_endTime, nullptr);
6146     TEST_TIME(JSValueRef::TypeError);
6147 }
6148 
HWTEST_F_L0(JSNApiSplTest,AggregateError)6149 HWTEST_F_L0(JSNApiSplTest, AggregateError)
6150 {
6151     LocalScope scope(vm_);
6152     CalculateForTime();
6153     gettimeofday(&g_beginTime, nullptr);
6154     for (int i = 0; i < NUM_COUNT; i++) {
6155         (void)Exception::AggregateError(vm_, StringRef::NewFromUtf8(vm_, "test aggregate error"));
6156     }
6157     gettimeofday(&g_endTime, nullptr);
6158     TEST_TIME(JSValueRef::AggregateError);
6159 }
6160 
HWTEST_F_L0(JSNApiSplTest,EvalError)6161 HWTEST_F_L0(JSNApiSplTest, EvalError)
6162 {
6163     LocalScope scope(vm_);
6164     CalculateForTime();
6165     gettimeofday(&g_beginTime, nullptr);
6166     for (int i = 0; i < NUM_COUNT; i++) {
6167         (void)Exception::EvalError(vm_, StringRef::NewFromUtf8(vm_, "test eval error"));
6168     }
6169     gettimeofday(&g_endTime, nullptr);
6170     TEST_TIME(JSValueRef::EvalError);
6171 }
6172 
HWTEST_F_L0(JSNApiSplTest,OOMError)6173 HWTEST_F_L0(JSNApiSplTest, OOMError)
6174 {
6175     LocalScope scope(vm_);
6176     CalculateForTime();
6177     gettimeofday(&g_beginTime, nullptr);
6178     for (int i = 0; i < NUM_COUNT; i++) {
6179         (void)Exception::OOMError(vm_, StringRef::NewFromUtf8(vm_, "test out of memory error"));
6180     }
6181     gettimeofday(&g_endTime, nullptr);
6182     TEST_TIME(JSValueRef::OOMError);
6183 }
6184 
HWTEST_F_L0(JSNApiSplTest,CreateEcmaVM)6185 HWTEST_F_L0(JSNApiSplTest, CreateEcmaVM)
6186 {
6187     LocalScope scope(vm_);
6188     CalculateForTime();
6189     JSRuntimeOptions option;
6190     gettimeofday(&g_beginTime, nullptr);
6191     for (int i = 0; i < NUM_COUNT; i++) {
6192         EcmaVM *workerVm = JSNApi::CreateEcmaVM(option);
6193         JSNApi::DestroyJSVM(workerVm);
6194     }
6195     gettimeofday(&g_endTime, nullptr);
6196     TEST_TIME(JSValueRef::CreateEcmaVM);
6197 }
6198 
HWTEST_F_L0(JSNApiSplTest,AddWorker)6199 HWTEST_F_L0(JSNApiSplTest, AddWorker)
6200 {
6201     LocalScope scope(vm_);
6202     CalculateForTime();
6203     JSRuntimeOptions option;
6204     gettimeofday(&g_beginTime, nullptr);
6205     EcmaVM *workerVm = JSNApi::CreateEcmaVM(option);
6206     for (int i = 0; i < NUM_COUNT; i++) {
6207         JSNApi::AddWorker(vm_, workerVm);
6208     }
6209     gettimeofday(&g_endTime, nullptr);
6210     TEST_TIME(JSValueRef::addWorker);
6211     JSNApi::DestroyJSVM(workerVm);
6212 }
6213 
HWTEST_F_L0(JSNApiSplTest,DeleteWorker)6214 HWTEST_F_L0(JSNApiSplTest, DeleteWorker)
6215 {
6216     LocalScope scope(vm_);
6217     CalculateForTime();
6218     JSRuntimeOptions option;
6219     EcmaVM *workerVm = JSNApi::CreateEcmaVM(option);
6220     gettimeofday(&g_beginTime, nullptr);
6221     for (int i = 0; i < NUM_COUNT; i++) {
6222         JSNApi::AddWorker(vm_, workerVm);
6223         JSNApi::DeleteWorker(vm_, workerVm);
6224     }
6225     gettimeofday(&g_endTime, nullptr);
6226     TEST_TIME(JSValueRef::DeleteWorker);
6227     JSNApi::DestroyJSVM(workerVm);
6228 }
6229 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsBundle)6230 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBundle)
6231 {
6232     LocalScope scope(vm_);
6233     CalculateForTime();
6234     gettimeofday(&g_beginTime, nullptr);
6235     for (int i = 0; i < NUM_COUNT; i++) {
6236         JSNApi::IsBundle(vm_);
6237     }
6238     gettimeofday(&g_endTime, nullptr);
6239     TEST_TIME(JSValueRef::IsBundle);
6240 }
6241 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_SetBundle)6242 HWTEST_F_L0(JSNApiSplTest, JSValueRef_SetBundle)
6243 {
6244     LocalScope scope(vm_);
6245     CalculateForTime();
6246     gettimeofday(&g_beginTime, nullptr);
6247     for (int i = 0; i < NUM_COUNT; i++) {
6248         JSNApi::SetBundle(vm_, false);
6249     }
6250     gettimeofday(&g_endTime, nullptr);
6251     TEST_TIME(JSValueRef::SetBundle);
6252 }
6253 
HWTEST_F_L0(JSNApiSplTest,JSNApi_SetAssetPath)6254 HWTEST_F_L0(JSNApiSplTest, JSNApi_SetAssetPath)
6255 {
6256     LocalScope scope(vm_);
6257     CalculateForTime();
6258     std::string str = "/data/storage/el1/bundle/moduleName/ets/modules.abc";
6259     gettimeofday(&g_beginTime, nullptr);
6260     for (int i = 0; i < NUM_COUNT; i++) {
6261         JSNApi::SetAssetPath(vm_, str);
6262     }
6263     gettimeofday(&g_endTime, nullptr);
6264     TEST_TIME(JSValueRef::SetAssetPath);
6265 }
6266 
HWTEST_F_L0(JSNApiSplTest,JSNApi_GetAssetPath)6267 HWTEST_F_L0(JSNApiSplTest, JSNApi_GetAssetPath)
6268 {
6269     LocalScope scope(vm_);
6270     CalculateForTime();
6271     std::string str = "/data/storage/el1/bundle/moduleName/ets/modules.abc";
6272     gettimeofday(&g_beginTime, nullptr);
6273     JSNApi::SetAssetPath(vm_, str);
6274     for (int i = 0; i < NUM_COUNT; i++) {
6275         std::string res = JSNApi::GetAssetPath(vm_);
6276     }
6277     gettimeofday(&g_endTime, nullptr);
6278     TEST_TIME(JSValueRef::GetAssetPath);
6279 }
6280 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_SetBundleName)6281 HWTEST_F_L0(JSNApiSplTest, JSValueRef_SetBundleName)
6282 {
6283     LocalScope scope(vm_);
6284     CalculateForTime();
6285     std::string str = "11";
6286     gettimeofday(&g_beginTime, nullptr);
6287     for (int i = 0; i < NUM_COUNT; i++) {
6288         JSNApi::SetBundleName(vm_, str);
6289     }
6290     gettimeofday(&g_endTime, nullptr);
6291     TEST_TIME(JSValueRef::SetBundleName);
6292 }
6293 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_GetBundleName)6294 HWTEST_F_L0(JSNApiSplTest, JSValueRef_GetBundleName)
6295 {
6296     LocalScope scope(vm_);
6297     CalculateForTime();
6298     std::string str = "11";
6299     JSNApi::SetBundleName(vm_, str);
6300     gettimeofday(&g_beginTime, nullptr);
6301     for (int i = 0; i < NUM_COUNT; i++) {
6302         std::string res = JSNApi::GetBundleName(vm_);
6303     }
6304     gettimeofday(&g_endTime, nullptr);
6305     TEST_TIME(JSValueRef::GetBundleName);
6306 }
6307 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_GetModuleName)6308 HWTEST_F_L0(JSNApiSplTest, JSValueRef_GetModuleName)
6309 {
6310     LocalScope scope(vm_);
6311     CalculateForTime();
6312     std::string str = "11";
6313     gettimeofday(&g_beginTime, nullptr);
6314     for (int i = 0; i < NUM_COUNT; i++) {
6315         JSNApi::SetModuleName(vm_, str);
6316     }
6317     gettimeofday(&g_endTime, nullptr);
6318     TEST_TIME(JSValueRef::SetModuleName);
6319 }
6320 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_SetModuleName)6321 HWTEST_F_L0(JSNApiSplTest, JSValueRef_SetModuleName)
6322 {
6323     LocalScope scope(vm_);
6324     CalculateForTime();
6325     std::string str = "11";
6326     JSNApi::SetModuleName(vm_, str);
6327     gettimeofday(&g_beginTime, nullptr);
6328     for (int i = 0; i < NUM_COUNT; i++) {
6329         std::string res = JSNApi::GetModuleName(vm_);
6330     }
6331     gettimeofday(&g_endTime, nullptr);
6332     TEST_TIME(JSValueRef::GetModuleName);
6333 }
6334 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_SetLoop)6335 HWTEST_F_L0(JSNApiSplTest, JSValueRef_SetLoop)
6336 {
6337     LocalScope scope(vm_);
6338     CalculateForTime();
6339     void *data = reinterpret_cast<void *>(BuiltinsFunction::FunctionPrototypeInvokeSelf);
6340     gettimeofday(&g_beginTime, nullptr);
6341     for (int i = 0; i < NUM_COUNT; i++) {
6342         JSNApi::SetLoop(vm_, data);
6343     }
6344     gettimeofday(&g_endTime, nullptr);
6345     TEST_TIME(JSValueRef::SetLoop);
6346 }
6347 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_InitForConcurrentFunction)6348 HWTEST_F_L0(JSNApiSplTest, JSValueRef_InitForConcurrentFunction)
6349 {
6350     LocalScope scope(vm_);
6351     CalculateForTime();
6352     NativePointerCallback deleter = nullptr;
6353     void *cb = reinterpret_cast<void *>(BuiltinsFunction::FunctionPrototypeInvokeSelf);
6354     bool callNative = true;
6355     size_t nativeBindingsize = 15;
6356     Local<FunctionRef> res =
6357         FunctionRef::NewClassFunction(vm_, FunCallback, deleter, cb, callNative, nativeBindingsize);
6358     ASSERT_TRUE(res->IsFunction(vm_));
6359     Local<JSValueRef> res1 = res->GetFunctionPrototype(vm_);
6360     void *taskInfo = nullptr;
6361     gettimeofday(&g_beginTime, nullptr);
6362     for (int i = 0; i < NUM_COUNT; i++) {
6363         JSNApi::InitForConcurrentFunction(vm_, res1, taskInfo);
6364     }
6365     gettimeofday(&g_endTime, nullptr);
6366     TEST_TIME(JSValueRef::InitForConcurrentFunction);
6367 }
6368 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_Rethrow)6369 HWTEST_F_L0(JSNApiSplTest, JSValueRef_Rethrow)
6370 {
6371     LocalScope scope(vm_);
6372     CalculateForTime();
6373     gettimeofday(&g_beginTime, nullptr);
6374     for (int i = 0; i < NUM_COUNT; i++) {
6375         TryCatch tryCatch(vm_);
6376         tryCatch.Rethrow();
6377     }
6378     gettimeofday(&g_endTime, nullptr);
6379     TEST_TIME(JSValueRef::Rethrow);
6380 }
6381 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_InitForConcurrentThread)6382 HWTEST_F_L0(JSNApiSplTest, JSValueRef_InitForConcurrentThread)
6383 {
6384     LocalScope scope(vm_);
6385     CalculateForTime();
6386     void *data = reinterpret_cast<void *>(BuiltinsFunction::FunctionPrototypeInvokeSelf);
6387     ConcurrentCallback concurrentCallback_ { nullptr };
6388     gettimeofday(&g_beginTime, nullptr);
6389     for (int i = 0; i < NUM_COUNT; i++) {
6390         JSNApi::InitForConcurrentThread(vm_, concurrentCallback_, data);
6391     }
6392     gettimeofday(&g_endTime, nullptr);
6393     TEST_TIME(JSValueRef::InitForConcurrentThread);
6394 }
6395 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_JsiRuntimeCallInfo)6396 HWTEST_F_L0(JSNApiSplTest, JSValueRef_JsiRuntimeCallInfo)
6397 {
6398     LocalScope scope(vm_);
6399     CalculateForTime();
6400     gettimeofday(&g_beginTime, nullptr);
6401     for (int i = 0; i < NUM_COUNT; i++) {
6402         JsiRuntimeCallInfo();
6403     }
6404     gettimeofday(&g_endTime, nullptr);
6405     TEST_TIME(JSValueRef::JsiRuntimeCallInfo);
6406 }
6407 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_GetThread)6408 HWTEST_F_L0(JSNApiSplTest, JSValueRef_GetThread)
6409 {
6410     LocalScope scope(vm_);
6411     CalculateForTime();
6412     JsiRuntimeCallInfo object;
6413     gettimeofday(&g_beginTime, nullptr);
6414     for (int i = 0; i < NUM_COUNT; i++) {
6415         object.GetThread();
6416     }
6417     gettimeofday(&g_endTime, nullptr);
6418     TEST_TIME(JSValueRef::GetThread);
6419 }
6420 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_GetArgsNumber)6421 HWTEST_F_L0(JSNApiSplTest, JSValueRef_GetArgsNumber)
6422 {
6423     LocalScope scope(vm_);
6424     CalculateForTime();
6425     JsiRuntimeCallInfo object;
6426     gettimeofday(&g_beginTime, nullptr);
6427     for (int i = 0; i < NUM_COUNT; i++) {
6428         object.GetArgsNumber();
6429     }
6430     gettimeofday(&g_endTime, nullptr);
6431     TEST_TIME(JSValueRef::GetArgsNumber);
6432 }
6433 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_HasCaught_True)6434 HWTEST_F_L0(JSNApiSplTest, JSValueRef_HasCaught_True)
6435 {
6436     LocalScope scope(vm_);
6437     CalculateForTime();
6438     Local<StringRef> message = StringRef::NewFromUtf8(vm_, "ErrorTest");
6439     Local<JSValueRef> error = Exception::Error(vm_, message);
6440     JSNApi::ThrowException(vm_, error);
6441     TryCatch tryCatch(vm_);
6442     ASSERT_TRUE(tryCatch.HasCaught());
6443     vm_->GetJSThread()->ClearException();
6444     JSNApi::ThrowException(vm_, error);
6445     gettimeofday(&g_beginTime, nullptr);
6446     for (int i = 0; i < NUM_COUNT; i++) {
6447         tryCatch.HasCaught();
6448     }
6449     gettimeofday(&g_endTime, nullptr);
6450     TEST_TIME(JSValueRef::HasCaught);
6451 }
6452 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_HasCaught_False)6453 HWTEST_F_L0(JSNApiSplTest, JSValueRef_HasCaught_False)
6454 {
6455     LocalScope scope(vm_);
6456     CalculateForTime();
6457     Local<StringRef> message = StringRef::NewFromUtf8(vm_, "ErrorTest");
6458     Local<JSValueRef> error = Exception::Error(vm_, message);
6459     JSNApi::ThrowException(vm_, error);
6460     TryCatch tryCatch(vm_);
6461     tryCatch.GetAndClearException();
6462     gettimeofday(&g_beginTime, nullptr);
6463     for (int i = 0; i < NUM_COUNT; i++) {
6464         tryCatch.HasCaught();
6465     }
6466     gettimeofday(&g_endTime, nullptr);
6467     TEST_TIME(JSValueRef::HasCaught);
6468 }
6469 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_Undefined)6470 HWTEST_F_L0(JSNApiSplTest, JSValueRef_Undefined)
6471 {
6472     LocalScope scope(vm_);
6473     CalculateForTime();
6474     uint32_t inputUnit32 = 32; // 32 = random number
6475     int num = 0;               // 0 = random number
6476     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
6477     bool inputBool = true;
6478     std::string testUtf8 = "Hello world";
6479     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
6480     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
6481     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
6482     Local<BooleanRef> resBool = BooleanRef::New(vm_, inputBool);
6483     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
6484     gettimeofday(&g_beginTime, nullptr);
6485     for (int i = 0; i < NUM_COUNT; i++) {
6486         intValue->Undefined(vm_);
6487     }
6488     gettimeofday(&g_endTime, nullptr);
6489     TEST_TIME(JSValueRef::Undefined::IntegerRef);
6490     gettimeofday(&g_beginTime, nullptr);
6491     for (int i = 0; i < NUM_COUNT; i++) {
6492         resUnit32->Undefined(vm_);
6493     }
6494     gettimeofday(&g_endTime, nullptr);
6495     TEST_TIME(JSValueRef::Undefined::NumberRef);
6496     gettimeofday(&g_beginTime, nullptr);
6497     for (int i = 0; i < NUM_COUNT; i++) {
6498         maxBigintUint64->Undefined(vm_);
6499     }
6500     gettimeofday(&g_endTime, nullptr);
6501     TEST_TIME(JSValueRef::Undefined::BigIntRef);
6502     gettimeofday(&g_beginTime, nullptr);
6503     for (int i = 0; i < NUM_COUNT; i++) {
6504         resBool->Undefined(vm_);
6505     }
6506     gettimeofday(&g_endTime, nullptr);
6507     TEST_TIME(JSValueRef::Undefined::BooleanRef);
6508     gettimeofday(&g_beginTime, nullptr);
6509     for (int i = 0; i < NUM_COUNT; i++) {
6510         stringUtf8->Undefined(vm_);
6511     }
6512     gettimeofday(&g_endTime, nullptr);
6513     TEST_TIME(JSValueRef::Undefined::StringRef);
6514     gettimeofday(&g_beginTime, nullptr);
6515     for (int i = 0; i < NUM_COUNT; i++) {
6516         JSValueRef::Undefined(vm_);
6517     }
6518     gettimeofday(&g_endTime, nullptr);
6519     TEST_TIME(JSValueRef::Undefined);
6520 }
6521 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_Null)6522 HWTEST_F_L0(JSNApiSplTest, JSValueRef_Null)
6523 {
6524     LocalScope scope(vm_);
6525     CalculateForTime();
6526     uint32_t inputUnit32 = 32; // 32 = random number
6527     int num = 0;               // 0 = random number
6528     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
6529     bool inputBool = true;
6530     std::string testUtf8 = "Hello world";
6531     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
6532     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
6533     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
6534     Local<BooleanRef> resBool = BooleanRef::New(vm_, inputBool);
6535     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
6536     gettimeofday(&g_beginTime, nullptr);
6537     for (int i = 0; i < NUM_COUNT; i++) {
6538         intValue->Null(vm_);
6539     }
6540     gettimeofday(&g_endTime, nullptr);
6541     TEST_TIME(JSValueRef::Null::IntegerRef);
6542     gettimeofday(&g_beginTime, nullptr);
6543     for (int i = 0; i < NUM_COUNT; i++) {
6544         resUnit32->Null(vm_);
6545     }
6546     gettimeofday(&g_endTime, nullptr);
6547     TEST_TIME(JSValueRef::Null::NumberRef);
6548     gettimeofday(&g_beginTime, nullptr);
6549     for (int i = 0; i < NUM_COUNT; i++) {
6550         maxBigintUint64->Null(vm_);
6551     }
6552     gettimeofday(&g_endTime, nullptr);
6553     TEST_TIME(JSValueRef::Null::BigIntRef);
6554     gettimeofday(&g_beginTime, nullptr);
6555     for (int i = 0; i < NUM_COUNT; i++) {
6556         resBool->Null(vm_);
6557     }
6558     gettimeofday(&g_endTime, nullptr);
6559     TEST_TIME(JSValueRef::Null::BooleanRef);
6560     gettimeofday(&g_beginTime, nullptr);
6561     for (int i = 0; i < NUM_COUNT; i++) {
6562         stringUtf8->Null(vm_);
6563     }
6564     gettimeofday(&g_endTime, nullptr);
6565     TEST_TIME(JSValueRef::Null::StringRef);
6566     gettimeofday(&g_beginTime, nullptr);
6567     for (int i = 0; i < NUM_COUNT; i++) {
6568         JSValueRef::Null(vm_);
6569     }
6570     gettimeofday(&g_endTime, nullptr);
6571     TEST_TIME(JSValueRef::Null);
6572 }
6573 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_True)6574 HWTEST_F_L0(JSNApiSplTest, JSValueRef_True)
6575 {
6576     LocalScope scope(vm_);
6577     CalculateForTime();
6578     uint32_t inputUnit32 = 32; // 32 = random number
6579     int num = 0;               // 0 = random number
6580     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
6581     bool inputBool = true;
6582     std::string testUtf8 = "Hello world";
6583     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
6584     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
6585     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
6586     Local<BooleanRef> resBool = BooleanRef::New(vm_, inputBool);
6587     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
6588     gettimeofday(&g_beginTime, nullptr);
6589     for (int i = 0; i < NUM_COUNT; i++) {
6590         intValue->True(vm_);
6591     }
6592     gettimeofday(&g_endTime, nullptr);
6593     TEST_TIME(JSValueRef::True::IntegerRef);
6594     gettimeofday(&g_beginTime, nullptr);
6595     for (int i = 0; i < NUM_COUNT; i++) {
6596         resUnit32->True(vm_);
6597     }
6598     gettimeofday(&g_endTime, nullptr);
6599     TEST_TIME(JSValueRef::True::NumberRef);
6600     gettimeofday(&g_beginTime, nullptr);
6601     for (int i = 0; i < NUM_COUNT; i++) {
6602         maxBigintUint64->True(vm_);
6603     }
6604     gettimeofday(&g_endTime, nullptr);
6605     TEST_TIME(JSValueRef::True::BigIntRef);
6606     gettimeofday(&g_beginTime, nullptr);
6607     for (int i = 0; i < NUM_COUNT; i++) {
6608         resBool->True(vm_);
6609     }
6610     gettimeofday(&g_endTime, nullptr);
6611     TEST_TIME(JSValueRef::True::BooleanRef);
6612     gettimeofday(&g_beginTime, nullptr);
6613     for (int i = 0; i < NUM_COUNT; i++) {
6614         stringUtf8->True(vm_);
6615     }
6616     gettimeofday(&g_endTime, nullptr);
6617     TEST_TIME(JSValueRef::True::StringRef);
6618     gettimeofday(&g_beginTime, nullptr);
6619     for (int i = 0; i < NUM_COUNT; i++) {
6620         JSValueRef::True(vm_);
6621     }
6622     gettimeofday(&g_endTime, nullptr);
6623     TEST_TIME(JSValueRef::True);
6624 }
6625 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToBoolean)6626 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToBoolean)
6627 {
6628     LocalScope scope(vm_);
6629     CalculateForTime();
6630     uint32_t inputUnit32 = 32; // 32 = random number
6631     int num = 0;               // 0 = random number
6632     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
6633     bool inputBool = true;
6634     std::string testUtf8 = "Hello world";
6635     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
6636     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
6637     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
6638     Local<BooleanRef> resBool = BooleanRef::New(vm_, inputBool);
6639     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
6640     gettimeofday(&g_beginTime, nullptr);
6641     for (int i = 0; i < NUM_COUNT; i++) {
6642         intValue->ToBoolean(vm_);
6643     }
6644     gettimeofday(&g_endTime, nullptr);
6645     TEST_TIME(JSValueRef::ToBoolean::IntegerRef);
6646     gettimeofday(&g_beginTime, nullptr);
6647     for (int i = 0; i < NUM_COUNT; i++) {
6648         resUnit32->ToBoolean(vm_);
6649     }
6650     gettimeofday(&g_endTime, nullptr);
6651     TEST_TIME(JSValueRef::ToBoolean::NumberRef);
6652     gettimeofday(&g_beginTime, nullptr);
6653     for (int i = 0; i < NUM_COUNT; i++) {
6654         maxBigintUint64->ToBoolean(vm_);
6655     }
6656     gettimeofday(&g_endTime, nullptr);
6657     TEST_TIME(JSValueRef::ToBoolean::BigIntRef);
6658     gettimeofday(&g_beginTime, nullptr);
6659     for (int i = 0; i < NUM_COUNT; i++) {
6660         resBool->ToBoolean(vm_);
6661     }
6662     gettimeofday(&g_endTime, nullptr);
6663     TEST_TIME(JSValueRef::ToBoolean::BooleanRef);
6664     gettimeofday(&g_beginTime, nullptr);
6665     for (int i = 0; i < NUM_COUNT; i++) {
6666         stringUtf8->ToBoolean(vm_);
6667     }
6668     gettimeofday(&g_endTime, nullptr);
6669     TEST_TIME(JSValueRef::ToBoolean::StringRef);
6670 }
6671 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToObject)6672 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject)
6673 {
6674     LocalScope scope(vm_);
6675     CalculateForTime();
6676     uint32_t inputUnit32 = 32; // 32 = random number
6677     int num = 0;               // 0 = random number
6678     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
6679     bool inputBool = true;
6680     std::string testUtf8 = "Hello world";
6681     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
6682     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
6683     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
6684     Local<BooleanRef> resBool = BooleanRef::New(vm_, inputBool);
6685     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
6686     gettimeofday(&g_beginTime, nullptr);
6687     for (int i = 0; i < NUM_COUNT; i++) {
6688         intValue->ToObject(vm_);
6689     }
6690     gettimeofday(&g_endTime, nullptr);
6691     TEST_TIME(JSValueRef::ToObject::IntegerRef);
6692     gettimeofday(&g_beginTime, nullptr);
6693     for (int i = 0; i < NUM_COUNT; i++) {
6694         resUnit32->ToObject(vm_);
6695     }
6696     gettimeofday(&g_endTime, nullptr);
6697     TEST_TIME(JSValueRef::ToObject::NumberRef);
6698     gettimeofday(&g_beginTime, nullptr);
6699     for (int i = 0; i < NUM_COUNT; i++) {
6700         maxBigintUint64->ToObject(vm_);
6701     }
6702     gettimeofday(&g_endTime, nullptr);
6703     TEST_TIME(JSValueRef::ToObject::BigIntRef);
6704     gettimeofday(&g_beginTime, nullptr);
6705     for (int i = 0; i < NUM_COUNT; i++) {
6706         resBool->ToObject(vm_);
6707     }
6708     gettimeofday(&g_endTime, nullptr);
6709     TEST_TIME(JSValueRef::ToObject::BooleanRef);
6710     gettimeofday(&g_beginTime, nullptr);
6711     for (int i = 0; i < NUM_COUNT; i++) {
6712         stringUtf8->ToObject(vm_);
6713     }
6714     gettimeofday(&g_endTime, nullptr);
6715     TEST_TIME(JSValueRef::ToObject::StringRef);
6716 }
6717 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_ToString)6718 HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToString)
6719 {
6720     LocalScope scope(vm_);
6721     CalculateForTime();
6722     uint32_t inputUnit32 = 32; // 32 = random number
6723     int num = 0;               // 0 = random number
6724     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
6725     bool inputBool = true;
6726     std::string testUtf8 = "Hello world";
6727     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
6728     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
6729     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
6730     Local<BooleanRef> resBool = BooleanRef::New(vm_, inputBool);
6731     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
6732     gettimeofday(&g_beginTime, nullptr);
6733     for (int i = 0; i < NUM_COUNT; i++) {
6734         intValue->ToString(vm_);
6735     }
6736     gettimeofday(&g_endTime, nullptr);
6737     TEST_TIME(JSValueRef::ToString::IntegerRef);
6738     gettimeofday(&g_beginTime, nullptr);
6739     for (int i = 0; i < NUM_COUNT; i++) {
6740         resUnit32->ToString(vm_);
6741     }
6742     gettimeofday(&g_endTime, nullptr);
6743     TEST_TIME(JSValueRef::ToString::NumberRef);
6744     gettimeofday(&g_beginTime, nullptr);
6745     for (int i = 0; i < NUM_COUNT; i++) {
6746         maxBigintUint64->ToString(vm_);
6747     }
6748     gettimeofday(&g_endTime, nullptr);
6749     TEST_TIME(JSValueRef::ToString::BigIntRef);
6750     gettimeofday(&g_beginTime, nullptr);
6751     for (int i = 0; i < NUM_COUNT; i++) {
6752         resBool->ToString(vm_);
6753     }
6754     gettimeofday(&g_endTime, nullptr);
6755     TEST_TIME(JSValueRef::ToString::BooleanRef);
6756     Local<JSValueRef> toTarget(stringUtf8);
6757     gettimeofday(&g_beginTime, nullptr);
6758     for (int i = 0; i < NUM_COUNT; i++) {
6759         toTarget->ToString(vm_);
6760     }
6761     gettimeofday(&g_endTime, nullptr);
6762     TEST_TIME(JSValueRef::ToString::StringRef);
6763 }
6764 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsFalse)6765 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsFalse)
6766 {
6767     LocalScope scope(vm_);
6768     CalculateForTime();
6769     uint32_t inputUnit32 = 32; // 32 = random number
6770     int num = 0;               // 0 = random number
6771     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
6772     bool inputBool = false;
6773     std::string testUtf8 = "Hello world";
6774     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
6775     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
6776     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
6777     Local<BooleanRef> resBool = BooleanRef::New(vm_, inputBool);
6778     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
6779     gettimeofday(&g_beginTime, nullptr);
6780     for (int i = 0; i < NUM_COUNT; i++) {
6781         intValue->IsFalse();
6782     }
6783     gettimeofday(&g_endTime, nullptr);
6784     TEST_TIME(JSValueRef::IsFalse::IntegerRef);
6785     gettimeofday(&g_beginTime, nullptr);
6786     for (int i = 0; i < NUM_COUNT; i++) {
6787         resUnit32->IsFalse();
6788     }
6789     gettimeofday(&g_endTime, nullptr);
6790     TEST_TIME(JSValueRef::IsFalse::NumberRef);
6791     gettimeofday(&g_beginTime, nullptr);
6792     for (int i = 0; i < NUM_COUNT; i++) {
6793         maxBigintUint64->IsFalse();
6794     }
6795     gettimeofday(&g_endTime, nullptr);
6796     TEST_TIME(JSValueRef::IsFalse::BigIntRef);
6797     gettimeofday(&g_beginTime, nullptr);
6798     for (int i = 0; i < NUM_COUNT; i++) {
6799         resBool->IsFalse();
6800     }
6801     gettimeofday(&g_endTime, nullptr);
6802     TEST_TIME(JSValueRef::IsFalse::BooleanRef);
6803     gettimeofday(&g_beginTime, nullptr);
6804     for (int i = 0; i < NUM_COUNT; i++) {
6805         stringUtf8->IsFalse();
6806     }
6807     gettimeofday(&g_endTime, nullptr);
6808     TEST_TIME(JSValueRef::IsFalse::StringRef);
6809 }
6810 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsNumber)6811 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsNumber)
6812 {
6813     LocalScope scope(vm_);
6814     CalculateForTime();
6815     uint32_t inputUnit32 = 32; // 32 = random number
6816     int num = 0;               // 0 = random number
6817     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
6818     bool inputBool = true;
6819     std::string testUtf8 = "Hello world";
6820     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
6821     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
6822     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
6823     Local<BooleanRef> resBool = BooleanRef::New(vm_, inputBool);
6824     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
6825     gettimeofday(&g_beginTime, nullptr);
6826     for (int i = 0; i < NUM_COUNT; i++) {
6827         intValue->IsNumber();
6828     }
6829     gettimeofday(&g_endTime, nullptr);
6830     TEST_TIME(JSValueRef::IsNumber::IntegerRef);
6831     gettimeofday(&g_beginTime, nullptr);
6832     for (int i = 0; i < NUM_COUNT; i++) {
6833         resUnit32->IsNumber();
6834     }
6835     gettimeofday(&g_endTime, nullptr);
6836     TEST_TIME(JSValueRef::IsNumber::NumberRef);
6837     gettimeofday(&g_beginTime, nullptr);
6838     for (int i = 0; i < NUM_COUNT; i++) {
6839         maxBigintUint64->IsNumber();
6840     }
6841     gettimeofday(&g_endTime, nullptr);
6842     TEST_TIME(JSValueRef::IsNumber::BigIntRef);
6843     gettimeofday(&g_beginTime, nullptr);
6844     for (int i = 0; i < NUM_COUNT; i++) {
6845         resBool->IsNumber();
6846     }
6847     gettimeofday(&g_endTime, nullptr);
6848     TEST_TIME(JSValueRef::IsNumber::BooleanRef);
6849     gettimeofday(&g_beginTime, nullptr);
6850     for (int i = 0; i < NUM_COUNT; i++) {
6851         stringUtf8->IsNumber();
6852     }
6853     gettimeofday(&g_endTime, nullptr);
6854     TEST_TIME(JSValueRef::IsNumber::StringRef);
6855 }
6856 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsBigInt)6857 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBigInt)
6858 {
6859     LocalScope scope(vm_);
6860     CalculateForTime();
6861     uint32_t inputUnit32 = 32; // 32 = random number
6862     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
6863     int64_t maxInt64 = std::numeric_limits<int64_t>::max();
6864     Local<IntegerRef> intValue = IntegerRef::New(vm_, 2147483646);
6865     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
6866     Local<NumberRef> resUnit64 = NumberRef::New(vm_, maxInt64);
6867     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
6868     Local<BigIntRef> maxBigintInt64 = BigIntRef::New(vm_, maxInt64);
6869     gettimeofday(&g_beginTime, nullptr);
6870     for (int i = 0; i < NUM_COUNT; i++) {
6871         intValue->IsBigInt(vm_);
6872     }
6873     gettimeofday(&g_endTime, nullptr);
6874     TEST_TIME(JSValueRef::IsBigInt::IntegerRef);
6875     gettimeofday(&g_beginTime, nullptr);
6876     for (int i = 0; i < NUM_COUNT; i++) {
6877         resUnit32->IsBigInt(vm_);
6878     }
6879     gettimeofday(&g_endTime, nullptr);
6880     TEST_TIME(JSValueRef::IsBigInt::NumberRef32);
6881     gettimeofday(&g_beginTime, nullptr);
6882     for (int i = 0; i < NUM_COUNT; i++) {
6883         resUnit64->IsBigInt(vm_);
6884     }
6885     gettimeofday(&g_endTime, nullptr);
6886     TEST_TIME(JSValueRef::IsBigInt::NumberRef64);
6887     gettimeofday(&g_beginTime, nullptr);
6888     for (int i = 0; i < NUM_COUNT; i++) {
6889         maxBigintUint64->IsBigInt(vm_);
6890     }
6891     gettimeofday(&g_endTime, nullptr);
6892     TEST_TIME(JSValueRef::IsBigInt::BigIntRefU64);
6893     gettimeofday(&g_beginTime, nullptr);
6894     for (int i = 0; i < NUM_COUNT; i++) {
6895         maxBigintInt64->IsBigInt(vm_);
6896     }
6897     gettimeofday(&g_endTime, nullptr);
6898     TEST_TIME(JSValueRef::IsBigInt::BigIntRefI64);
6899 }
6900 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsBigInt2)6901 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBigInt2)
6902 {
6903     LocalScope scope(vm_);
6904     CalculateForTime();
6905     bool inputBool = true;
6906     std::string testUtf8 = "Hello world";
6907     Local<BooleanRef> resBool = BooleanRef::New(vm_, inputBool);
6908     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
6909     gettimeofday(&g_beginTime, nullptr);
6910     for (int i = 0; i < NUM_COUNT; i++) {
6911         resBool->IsBigInt(vm_);
6912     }
6913     gettimeofday(&g_endTime, nullptr);
6914     TEST_TIME(JSValueRef::IsBigInt::BooleanRef);
6915     gettimeofday(&g_beginTime, nullptr);
6916     for (int i = 0; i < NUM_COUNT; i++) {
6917         stringUtf8->IsBigInt(vm_);
6918     }
6919     gettimeofday(&g_endTime, nullptr);
6920     TEST_TIME(JSValueRef::IsBigInt::StringRef);
6921 }
6922 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsArray)6923 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArray)
6924 {
6925     LocalScope scope(vm_);
6926     CalculateForTime();
6927     uint32_t inputUnit32 = 32; // 32 = random number
6928     int num = 0;               // 0 = random number
6929     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
6930     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
6931     gettimeofday(&g_beginTime, nullptr);
6932     for (int i = 0; i < NUM_COUNT; i++) {
6933         intValue->IsArray(vm_);
6934     }
6935     gettimeofday(&g_endTime, nullptr);
6936     TEST_TIME(JSValueRef::IsArray::IntegerRef);
6937     gettimeofday(&g_beginTime, nullptr);
6938     for (int i = 0; i < NUM_COUNT; i++) {
6939         resUnit32->IsArray(vm_);
6940     }
6941     gettimeofday(&g_endTime, nullptr);
6942     TEST_TIME(JSValueRef::IsArray::NumberRef);
6943 }
6944 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsArray2)6945 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArray2)
6946 {
6947     LocalScope scope(vm_);
6948     CalculateForTime();
6949     int num = 3; // 3 = ArrayBuffer Length
6950     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
6951     std::string testUtf8 = "Hello world";
6952     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
6953     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
6954     Local<ArrayRef> arrayObject = ArrayRef::New(vm_, num);
6955     gettimeofday(&g_beginTime, nullptr);
6956     for (int i = 0; i < NUM_COUNT; i++) {
6957         maxBigintUint64->IsArray(vm_);
6958     }
6959     gettimeofday(&g_endTime, nullptr);
6960     TEST_TIME(JSValueRef::IsArray::BigIntRef);
6961     gettimeofday(&g_beginTime, nullptr);
6962     for (int i = 0; i < NUM_COUNT; i++) {
6963         stringUtf8->IsArray(vm_);
6964     }
6965     gettimeofday(&g_endTime, nullptr);
6966     TEST_TIME(JSValueRef::IsArray::StringRef);
6967     gettimeofday(&g_beginTime, nullptr);
6968     for (int i = 0; i < NUM_COUNT; i++) {
6969         arrayObject->IsArray(vm_);
6970     }
6971     gettimeofday(&g_endTime, nullptr);
6972     TEST_TIME(JSValueRef::IsArray::ArrayRef);
6973 }
6974 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSArray)6975 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSArray)
6976 {
6977     LocalScope scope(vm_);
6978     CalculateForTime();
6979     uint32_t inputUnit32 = 32; // 32 = random number
6980     int num = 0;               // 0 = random number
6981     int length = 3;            // 3 = ArrayBuffer Length
6982     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
6983     std::string testUtf8 = "Hello world";
6984     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
6985     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
6986     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
6987     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
6988     Local<ArrayRef> arrayObject = ArrayRef::New(vm_, length);
6989     gettimeofday(&g_beginTime, nullptr);
6990     for (int i = 0; i < NUM_COUNT; i++) {
6991         intValue->IsJSArray(vm_);
6992     }
6993     gettimeofday(&g_endTime, nullptr);
6994     TEST_TIME(JSValueRef::IsJSArray::IntegerRef);
6995     gettimeofday(&g_beginTime, nullptr);
6996     for (int i = 0; i < NUM_COUNT; i++) {
6997         resUnit32->IsJSArray(vm_);
6998     }
6999     gettimeofday(&g_endTime, nullptr);
7000     TEST_TIME(JSValueRef::IsJSArray::NumberRef);
7001     gettimeofday(&g_beginTime, nullptr);
7002     for (int i = 0; i < NUM_COUNT; i++) {
7003         maxBigintUint64->IsJSArray(vm_);
7004     }
7005     gettimeofday(&g_endTime, nullptr);
7006     TEST_TIME(JSValueRef::IsJSArray::BigIntRef);
7007     gettimeofday(&g_beginTime, nullptr);
7008     for (int i = 0; i < NUM_COUNT; i++) {
7009         stringUtf8->IsJSArray(vm_);
7010     }
7011     gettimeofday(&g_endTime, nullptr);
7012     TEST_TIME(JSValueRef::IsJSArray::StringRef);
7013     gettimeofday(&g_beginTime, nullptr);
7014     for (int i = 0; i < NUM_COUNT; i++) {
7015         arrayObject->IsJSArray(vm_);
7016     }
7017     gettimeofday(&g_endTime, nullptr);
7018     TEST_TIME(JSValueRef::IsJSArray::ArrayRef);
7019 }
7020 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsJSArray2)7021 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSArray2)
7022 {
7023     LocalScope scope(vm_);
7024     CalculateForTime();
7025     JSArray *arr = JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetObject<JSArray>();
7026     JSHandle<JSTaggedValue> obj(thread_, arr);
7027     Local<JSValueRef> JSArrayObject = JSNApiHelper::ToLocal<JSValueRef>(obj);
7028     gettimeofday(&g_beginTime, nullptr);
7029     for (int i = 0; i < NUM_COUNT; i++) {
7030         JSArrayObject->IsJSArray(vm_);
7031     }
7032     gettimeofday(&g_endTime, nullptr);
7033     TEST_TIME(JSValueRef::IsJSArray::JSArrayObject);
7034 }
7035 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsConstructor)7036 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsConstructor)
7037 {
7038     LocalScope scope(vm_);
7039     CalculateForTime();
7040     uint32_t inputUnit32 = 32; // 32 = random number
7041     int num = 0;               // 0 = random number
7042     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
7043     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
7044     gettimeofday(&g_beginTime, nullptr);
7045     for (int i = 0; i < NUM_COUNT; i++) {
7046         intValue->IsConstructor(vm_);
7047     }
7048     gettimeofday(&g_endTime, nullptr);
7049     TEST_TIME(JSValueRef::IsConstructor::IntegerRef);
7050     gettimeofday(&g_beginTime, nullptr);
7051     for (int i = 0; i < NUM_COUNT; i++) {
7052         resUnit32->IsConstructor(vm_);
7053     }
7054     gettimeofday(&g_endTime, nullptr);
7055     TEST_TIME(JSValueRef::IsConstructor::NumberRef);
7056 }
7057 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsConstructor2)7058 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsConstructor2)
7059 {
7060     LocalScope scope(vm_);
7061     CalculateForTime();
7062     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
7063     std::string testUtf8 = "Hello world";
7064     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
7065     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
7066     EcmaVM *ecmaVM = thread_->GetEcmaVM();
7067     JSHandle<GlobalEnv> env = ecmaVM->GetGlobalEnv();
7068     JSHandle<JSFunction> func = thread_->GetEcmaVM()->GetFactory()->NewJSFunction(env, static_cast<void *>(nullptr),
7069         FunctionKind::BASE_CONSTRUCTOR);
7070     JSHandle<JSObject> nullHandle(thread_, JSTaggedValue::Null());
7071     JSHandle<JSObject> obj = JSObject::ObjectCreate(thread_, nullHandle);
7072     JSHandle<JSTaggedValue> objValue(obj);
7073     [[maybe_unused]] bool makeConstructor = JSFunction::MakeConstructor(thread_, func, objValue);
7074     JSHandle<JSTaggedValue> funcHandle(func);
7075     Local<JSValueRef> funConstructor = JSNApiHelper::ToLocal<JSValueRef>(funcHandle);
7076     gettimeofday(&g_beginTime, nullptr);
7077     for (int i = 0; i < NUM_COUNT; i++) {
7078         maxBigintUint64->IsConstructor(vm_);
7079     }
7080     gettimeofday(&g_endTime, nullptr);
7081     TEST_TIME(JSValueRef::IsConstructor::BigIntRef);
7082     gettimeofday(&g_beginTime, nullptr);
7083     for (int i = 0; i < NUM_COUNT; i++) {
7084         stringUtf8->IsConstructor(vm_);
7085     }
7086     gettimeofday(&g_endTime, nullptr);
7087     TEST_TIME(JSValueRef::IsConstructor::StringRef);
7088     gettimeofday(&g_beginTime, nullptr);
7089     for (int i = 0; i < NUM_COUNT; i++) {
7090         funConstructor->IsConstructor(vm_);
7091     }
7092     gettimeofday(&g_endTime, nullptr);
7093     TEST_TIME(JSValueRef::IsConstructor::funConstructor);
7094 }
7095 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsDate)7096 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsDate)
7097 {
7098     LocalScope scope(vm_);
7099     CalculateForTime();
7100     uint32_t inputUnit32 = 32; // 32 = random number
7101     int num = 0;               // 0 = random number
7102     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
7103     std::string testUtf8 = "Hello world";
7104     double timeRef = 1.1; // 1.1 = random number
7105     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
7106     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
7107     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
7108     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
7109     Local<DateRef> dateRef = DateRef::New(vm_, timeRef);
7110     gettimeofday(&g_beginTime, nullptr);
7111     for (int i = 0; i < NUM_COUNT; i++) {
7112         intValue->IsDate(vm_);
7113     }
7114     gettimeofday(&g_endTime, nullptr);
7115     TEST_TIME(JSValueRef::IsDate::IntegerRef);
7116     gettimeofday(&g_beginTime, nullptr);
7117     for (int i = 0; i < NUM_COUNT; i++) {
7118         resUnit32->IsDate(vm_);
7119     }
7120     gettimeofday(&g_endTime, nullptr);
7121     TEST_TIME(JSValueRef::IsDate::NumberRef);
7122     gettimeofday(&g_beginTime, nullptr);
7123     for (int i = 0; i < NUM_COUNT; i++) {
7124         maxBigintUint64->IsDate(vm_);
7125     }
7126     gettimeofday(&g_endTime, nullptr);
7127     TEST_TIME(JSValueRef::IsDate::BigIntRef);
7128     gettimeofday(&g_beginTime, nullptr);
7129     for (int i = 0; i < NUM_COUNT; i++) {
7130         stringUtf8->IsDate(vm_);
7131     }
7132     gettimeofday(&g_endTime, nullptr);
7133     TEST_TIME(JSValueRef::IsDate::StringRef);
7134     gettimeofday(&g_beginTime, nullptr);
7135     for (int i = 0; i < NUM_COUNT; i++) {
7136         dateRef->IsDate(vm_);
7137     }
7138     gettimeofday(&g_endTime, nullptr);
7139     TEST_TIME(JSValueRef::IsDate::DateRef);
7140 }
7141 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsError)7142 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsError)
7143 {
7144     LocalScope scope(vm_);
7145     CalculateForTime();
7146     uint32_t inputUnit32 = 32; // 32 = random number
7147     int num = 0;               // 0 = random number
7148     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
7149     std::string testUtf8 = "Hello world";
7150     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
7151     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
7152     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
7153     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
7154     Local<StringRef> message = StringRef::NewFromUtf8(vm_, "ErrorTest");
7155     Local<JSValueRef> error = Exception::Error(vm_, message);
7156     gettimeofday(&g_beginTime, nullptr);
7157     for (int i = 0; i < NUM_COUNT; i++) {
7158         intValue->IsError(vm_);
7159     }
7160     gettimeofday(&g_endTime, nullptr);
7161     TEST_TIME(JSValueRef::IsError::IntegerRef);
7162     gettimeofday(&g_beginTime, nullptr);
7163     for (int i = 0; i < NUM_COUNT; i++) {
7164         resUnit32->IsError(vm_);
7165     }
7166     gettimeofday(&g_endTime, nullptr);
7167     TEST_TIME(JSValueRef::IsError::NumberRef);
7168     gettimeofday(&g_beginTime, nullptr);
7169     for (int i = 0; i < NUM_COUNT; i++) {
7170         maxBigintUint64->IsError(vm_);
7171     }
7172     gettimeofday(&g_endTime, nullptr);
7173     TEST_TIME(JSValueRef::IsError::BigIntRef);
7174     gettimeofday(&g_beginTime, nullptr);
7175     for (int i = 0; i < NUM_COUNT; i++) {
7176         stringUtf8->IsError(vm_);
7177     }
7178     gettimeofday(&g_endTime, nullptr);
7179     TEST_TIME(JSValueRef::IsError::StringRef);
7180     gettimeofday(&g_beginTime, nullptr);
7181     for (int i = 0; i < NUM_COUNT; i++) {
7182         error->IsError(vm_);
7183     }
7184     gettimeofday(&g_endTime, nullptr);
7185     TEST_TIME(JSValueRef::IsError::Exception::Error);
7186 }
7187 
HWTEST_F_L0(JSNApiSplTest,JSValueRef_IsMap)7188 HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsMap)
7189 {
7190     LocalScope scope(vm_);
7191     CalculateForTime();
7192     uint32_t inputUnit32 = 32; // 32 = random number
7193     int num = 0;               // 0 = random number
7194     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
7195     std::string testUtf8 = "Hello world";
7196     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
7197     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
7198     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
7199     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
7200     Local<MapRef> mapRef = MapRef::New(vm_);
7201     gettimeofday(&g_beginTime, nullptr);
7202     for (int i = 0; i < NUM_COUNT; i++) {
7203         intValue->IsMap(vm_);
7204     }
7205     gettimeofday(&g_endTime, nullptr);
7206     TEST_TIME(JSValueRef::IsMap::IntegerRef);
7207     gettimeofday(&g_beginTime, nullptr);
7208     for (int i = 0; i < NUM_COUNT; i++) {
7209         resUnit32->IsMap(vm_);
7210     }
7211     gettimeofday(&g_endTime, nullptr);
7212     TEST_TIME(JSValueRef::IsMap::NumberRef);
7213     gettimeofday(&g_beginTime, nullptr);
7214     for (int i = 0; i < NUM_COUNT; i++) {
7215         maxBigintUint64->IsMap(vm_);
7216     }
7217     gettimeofday(&g_endTime, nullptr);
7218     TEST_TIME(JSValueRef::IsMap::BigIntRef);
7219     gettimeofday(&g_beginTime, nullptr);
7220     for (int i = 0; i < NUM_COUNT; i++) {
7221         stringUtf8->IsMap(vm_);
7222     }
7223     gettimeofday(&g_endTime, nullptr);
7224     TEST_TIME(JSValueRef::IsMap::StringRef);
7225     gettimeofday(&g_beginTime, nullptr);
7226     for (int i = 0; i < NUM_COUNT; i++) {
7227         mapRef->IsMap(vm_);
7228     }
7229     gettimeofday(&g_endTime, nullptr);
7230     TEST_TIME(JSValueRef::IsMap::MapRef);
7231 }
7232 
HWTEST_F_L0(JSNApiSplTest,Local_operator01)7233 HWTEST_F_L0(JSNApiSplTest, Local_operator01)
7234 {
7235     LocalScope scope(vm_);
7236     CalculateForTime();
7237     uint32_t inputUnit32 = 32; // 32 = random number
7238     int num = 13;              // 13 = random number
7239     int length = 3;            // 3 = ArrayBufer length
7240     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
7241     std::string testUtf8 = "Hello world";
7242     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
7243     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
7244     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
7245     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
7246     Local<ArrayRef> arrayObject = ArrayRef::New(vm_, length);
7247     gettimeofday(&g_beginTime, nullptr);
7248     for (int i = 0; i < NUM_COUNT; i++) {
7249         Local<JSValueRef> integerVaule(intValue);
7250     }
7251     gettimeofday(&g_endTime, nullptr);
7252     TEST_TIME(Local::Operator::IntegerRef);
7253     gettimeofday(&g_beginTime, nullptr);
7254     for (int i = 0; i < NUM_COUNT; i++) {
7255         Local<JSValueRef> NumberVaule(resUnit32);
7256     }
7257     gettimeofday(&g_endTime, nullptr);
7258     TEST_TIME(Local::Operator::NumberRef);
7259     gettimeofday(&g_beginTime, nullptr);
7260     for (int i = 0; i < NUM_COUNT; i++) {
7261         Local<JSValueRef> bigIntVaule(maxBigintUint64);
7262     }
7263     gettimeofday(&g_endTime, nullptr);
7264     TEST_TIME(Local::Operator::BigIntRef);
7265     gettimeofday(&g_beginTime, nullptr);
7266     for (int i = 0; i < NUM_COUNT; i++) {
7267         Local<JSValueRef> stringVaule(stringUtf8);
7268     }
7269     gettimeofday(&g_endTime, nullptr);
7270     TEST_TIME(Local::Operator::StringRef);
7271     gettimeofday(&g_beginTime, nullptr);
7272     for (int i = 0; i < NUM_COUNT; i++) {
7273         Local<JSValueRef> arrayVaule(arrayObject);
7274     }
7275     gettimeofday(&g_endTime, nullptr);
7276     TEST_TIME(Local::Operator::ArrayRef);
7277 }
7278 
HWTEST_F_L0(JSNApiSplTest,Local_operator02)7279 HWTEST_F_L0(JSNApiSplTest, Local_operator02)
7280 {
7281     LocalScope scope(vm_);
7282     CalculateForTime();
7283     uint32_t inputUnit32 = 32; // 32 = random number
7284     int num = 13;              // 13 = random number
7285     int length = 3;            // 3 = ArrayBufer length
7286     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
7287     std::string testUtf8 = "Hello world";
7288     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
7289     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
7290     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
7291     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
7292     Local<ArrayRef> arrayObject = ArrayRef::New(vm_, length);
7293     gettimeofday(&g_beginTime, nullptr);
7294     for (int i = 0; i < NUM_COUNT; i++) {
7295         intValue->IsNull();
7296     }
7297     gettimeofday(&g_endTime, nullptr);
7298     TEST_TIME(Local::Operator2::IntegerRef);
7299     gettimeofday(&g_beginTime, nullptr);
7300     for (int i = 0; i < NUM_COUNT; i++) {
7301         resUnit32->IsNull();
7302     }
7303     gettimeofday(&g_endTime, nullptr);
7304     TEST_TIME(Local::Operator2::NumberRef);
7305     gettimeofday(&g_beginTime, nullptr);
7306     for (int i = 0; i < NUM_COUNT; i++) {
7307         maxBigintUint64->IsNull();
7308     }
7309     gettimeofday(&g_endTime, nullptr);
7310     TEST_TIME(Local::Operator2::BigIntRef);
7311     gettimeofday(&g_beginTime, nullptr);
7312     for (int i = 0; i < NUM_COUNT; i++) {
7313         stringUtf8->IsNull();
7314     }
7315     gettimeofday(&g_endTime, nullptr);
7316     TEST_TIME(Local::Operator2::StringRef);
7317     gettimeofday(&g_beginTime, nullptr);
7318     for (int i = 0; i < NUM_COUNT; i++) {
7319         arrayObject->IsNull();
7320     }
7321     gettimeofday(&g_endTime, nullptr);
7322     TEST_TIME(Local::Operator2::ArrayRef);
7323 }
7324 
HWTEST_F_L0(JSNApiSplTest,Local_IsEmpty)7325 HWTEST_F_L0(JSNApiSplTest, Local_IsEmpty)
7326 {
7327     LocalScope scope(vm_);
7328     CalculateForTime();
7329     uint32_t inputUnit32 = 32; // 32 = random number
7330     int num = 13;              // 13 = random number
7331     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
7332     std::string testUtf8 = "Hello world";
7333     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
7334     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
7335     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
7336     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
7337     Local<JSValueRef> JSvalue;
7338     gettimeofday(&g_beginTime, nullptr);
7339     for (int i = 0; i < NUM_COUNT; i++) {
7340         intValue.IsEmpty();
7341     }
7342     gettimeofday(&g_endTime, nullptr);
7343     TEST_TIME(Local::IsEmpty::IntegerRef);
7344     gettimeofday(&g_beginTime, nullptr);
7345     for (int i = 0; i < NUM_COUNT; i++) {
7346         resUnit32.IsEmpty();
7347     }
7348     gettimeofday(&g_endTime, nullptr);
7349     TEST_TIME(Local::IsEmpty::NumberRef);
7350     gettimeofday(&g_beginTime, nullptr);
7351     for (int i = 0; i < NUM_COUNT; i++) {
7352         maxBigintUint64.IsEmpty();
7353     }
7354     gettimeofday(&g_endTime, nullptr);
7355     TEST_TIME(Local::IsEmpty::BigIntRef);
7356     gettimeofday(&g_beginTime, nullptr);
7357     for (int i = 0; i < NUM_COUNT; i++) {
7358         stringUtf8.IsEmpty();
7359     }
7360     gettimeofday(&g_endTime, nullptr);
7361     TEST_TIME(Local::IsEmpty::StringRef);
7362     gettimeofday(&g_beginTime, nullptr);
7363     for (int i = 0; i < NUM_COUNT; i++) {
7364         JSvalue.IsEmpty();
7365     }
7366     gettimeofday(&g_endTime, nullptr);
7367     TEST_TIME(Local::IsEmpty);
7368 }
7369 
HWTEST_F_L0(JSNApiSplTest,Local_IsNull)7370 HWTEST_F_L0(JSNApiSplTest, Local_IsNull)
7371 {
7372     LocalScope scope(vm_);
7373     CalculateForTime();
7374     int num = 13; // 13 = random number
7375     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
7376     Local<JSValueRef> JSvalue;
7377     gettimeofday(&g_beginTime, nullptr);
7378     for (int i = 0; i < NUM_COUNT; i++) {
7379         intValue.IsNull();
7380     }
7381     gettimeofday(&g_endTime, nullptr);
7382     TEST_TIME(Local::IsNull::IntegerRef);
7383     gettimeofday(&g_beginTime, nullptr);
7384     for (int i = 0; i < NUM_COUNT; i++) {
7385         JSvalue.IsNull();
7386     }
7387     gettimeofday(&g_endTime, nullptr);
7388     TEST_TIME(Local::IsNull);
7389 }
7390 
HWTEST_F_L0(JSNApiSplTest,CopyableGlobal_ToLocal)7391 HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_ToLocal)
7392 {
7393     LocalScope scope(vm_);
7394     CalculateForTime();
7395     int num = 13; // 13 = random number
7396     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
7397     CopyableGlobal<IntegerRef> copyGlobal(vm_, intValue);
7398     gettimeofday(&g_beginTime, nullptr);
7399     for (int i = 0; i < NUM_COUNT; i++) {
7400         copyGlobal.ToLocal();
7401     }
7402     gettimeofday(&g_endTime, nullptr);
7403     TEST_TIME(CopyableGlobal::ToLocal);
7404 }
7405 
HWTEST_F_L0(JSNApiSplTest,CopyableGlobal_Empty)7406 HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_Empty)
7407 {
7408     LocalScope scope(vm_);
7409     CalculateForTime();
7410     int num = 13; // 13 = random number
7411     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
7412     CopyableGlobal<IntegerRef> copyGlobal(vm_, intValue);
7413     EXPECT_FALSE(copyGlobal.IsEmpty());
7414     gettimeofday(&g_beginTime, nullptr);
7415     for (int i = 0; i < NUM_COUNT; i++) {
7416         copyGlobal.Empty();
7417     }
7418     gettimeofday(&g_endTime, nullptr);
7419     TEST_TIME(CopyableGlobal::Empty);
7420     EXPECT_TRUE(copyGlobal.IsEmpty());
7421 }
7422 
HWTEST_F_L0(JSNApiSplTest,CopyableGlobal_operator)7423 HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_operator)
7424 {
7425     LocalScope scope(vm_);
7426     CalculateForTime();
7427     int num = 13; // 13 = random number
7428     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
7429     CopyableGlobal<IntegerRef> copyGlobal(vm_, intValue);
7430     gettimeofday(&g_beginTime, nullptr);
7431     for (int i = 0; i < NUM_COUNT; i++) {
7432         (*copyGlobal)->IsInt();
7433     }
7434     gettimeofday(&g_endTime, nullptr);
7435     TEST_TIME(CopyableGlobal::Operator);
7436     EXPECT_TRUE((*copyGlobal)->IsInt());
7437     gettimeofday(&g_beginTime, nullptr);
7438     for (int i = 0; i < NUM_COUNT; i++) {
7439         copyGlobal->IsInt();
7440     }
7441     gettimeofday(&g_endTime, nullptr);
7442     TEST_TIME(CopyableGlobal::Operator2);
7443     EXPECT_TRUE(copyGlobal->IsInt());
7444 }
7445 
HWTEST_F_L0(JSNApiSplTest,CopyableGlobal_IsEmpty)7446 HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_IsEmpty)
7447 {
7448     LocalScope scope(vm_);
7449     CalculateForTime();
7450     std::string testUtf8 = "Hello world";
7451     int num = 13; // 13 = random number
7452     Local<IntegerRef> intValue = IntegerRef::New(vm_, num);
7453     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
7454     CopyableGlobal<StringRef> copyGlbString(vm_, stringUtf8);
7455     CopyableGlobal<IntegerRef> copyGlobal(vm_, intValue);
7456     gettimeofday(&g_beginTime, nullptr);
7457     for (int i = 0; i < NUM_COUNT; i++) {
7458         copyGlbString.IsEmpty();
7459     }
7460     gettimeofday(&g_endTime, nullptr);
7461     TEST_TIME(CopyableGlobal::IsEmpty::StringRef::first);
7462     gettimeofday(&g_beginTime, nullptr);
7463     for (int i = 0; i < NUM_COUNT; i++) {
7464         copyGlobal.IsEmpty();
7465     }
7466     gettimeofday(&g_endTime, nullptr);
7467     TEST_TIME(CopyableGlobal::IsEmpty::IntegerRef);
7468     copyGlbString.Empty();
7469     gettimeofday(&g_beginTime, nullptr);
7470     for (int i = 0; i < NUM_COUNT; i++) {
7471         copyGlbString.IsEmpty();
7472     }
7473     gettimeofday(&g_endTime, nullptr);
7474     TEST_TIME(CopyableGlobal::IsEmpty::StringRef::Second);
7475 }
7476 
HWTEST_F_L0(JSNApiSplTest,CopyableGlobal_SetWeak_IsWeak_ClearWeak)7477 HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_SetWeak_IsWeak_ClearWeak)
7478 {
7479     LocalScope scope(vm_);
7480     CalculateForTime();
7481     std::string testUtf8 = "Hello world";
7482     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
7483     CopyableGlobal<JSValueRef> copyGlobalback(vm_, stringUtf8);
7484     gettimeofday(&g_beginTime, nullptr);
7485     for (int i = 0; i < NUM_COUNT; i++) {
7486         copyGlobalback.IsWeak();
7487     }
7488     gettimeofday(&g_endTime, nullptr);
7489     TEST_TIME(CopyableGlobal::IsWeak::First);
7490     gettimeofday(&g_beginTime, nullptr);
7491     for (int i = 0; i < NUM_COUNT; i++) {
7492         copyGlobalback.SetWeak();
7493     }
7494     gettimeofday(&g_endTime, nullptr);
7495     TEST_TIME(CopyableGlobal::SetWeak);
7496     gettimeofday(&g_beginTime, nullptr);
7497     for (int i = 0; i < NUM_COUNT; i++) {
7498         copyGlobalback.IsWeak();
7499     }
7500     gettimeofday(&g_endTime, nullptr);
7501     TEST_TIME(CopyableGlobal::IsWeak::Second);
7502     gettimeofday(&g_beginTime, nullptr);
7503     for (int i = 0; i < NUM_COUNT; i++) {
7504         copyGlobalback.ClearWeak();
7505     }
7506     gettimeofday(&g_endTime, nullptr);
7507     TEST_TIME(CopyableGlobal::ClearWeak);
7508     gettimeofday(&g_beginTime, nullptr);
7509     for (int i = 0; i < NUM_COUNT; i++) {
7510         copyGlobalback.IsWeak();
7511     }
7512     gettimeofday(&g_endTime, nullptr);
7513     TEST_TIME(CopyableGlobal::IsWeak::three);
7514 }
7515 
HWTEST_F_L0(JSNApiSplTest,CopyableGlobal_SetWeakCallback)7516 HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_SetWeakCallback)
7517 {
7518     LocalScope scope(vm_);
7519     CalculateForTime();
7520     uint32_t inputUnit32 = 32; // 32 = random number
7521     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
7522     double doubleSize = 1.1; // 1.1 = random number
7523     long longSize = 123456;  // 123456 = random number
7524     std::string testUtf8 = "Hello world";
7525     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
7526     CopyableGlobal<JSValueRef> copyGlobalStr(vm_, stringUtf8);
7527     gettimeofday(&g_beginTime, nullptr);
7528     for (int i = 0; i < NUM_COUNT; i++) {
7529         copyGlobalStr.SetWeakCallback(&inputUnit32, FreeGlobalCallBack<uint32_t>,
7530                 NativeFinalizeCallback<uint32_t>);
7531     }
7532     gettimeofday(&g_endTime, nullptr);
7533     TEST_TIME(CopyableGlobal::SetWeakCallback::Uint32);
7534     gettimeofday(&g_beginTime, nullptr);
7535     for (int i = 0; i < NUM_COUNT; i++) {
7536         copyGlobalStr.SetWeakCallback(&maxUint64, FreeGlobalCallBack<uint64_t>,
7537                 NativeFinalizeCallback<uint64_t>);
7538     }
7539     gettimeofday(&g_endTime, nullptr);
7540     TEST_TIME(CopyableGlobal::SetWeakCallback::Uint64);
7541     gettimeofday(&g_beginTime, nullptr);
7542     for (int i = 0; i < NUM_COUNT; i++) {
7543         copyGlobalStr.SetWeakCallback(&doubleSize, FreeGlobalCallBack<double>,
7544                 NativeFinalizeCallback<double>);
7545     }
7546     gettimeofday(&g_endTime, nullptr);
7547     TEST_TIME(CopyableGlobal::SetWeakCallback::Double);
7548     gettimeofday(&g_beginTime, nullptr);
7549     for (int i = 0; i < NUM_COUNT; i++) {
7550         copyGlobalStr.SetWeakCallback(&longSize, FreeGlobalCallBack<long>,
7551                 NativeFinalizeCallback<long>);
7552     }
7553     gettimeofday(&g_endTime, nullptr);
7554     TEST_TIME(CopyableGlobal::SetWeakCallback::Long);
7555     gettimeofday(&g_beginTime, nullptr);
7556     for (int i = 0; i < NUM_COUNT; i++) {
7557         copyGlobalStr.SetWeakCallback(&testUtf8, FreeGlobalCallBack<std::string>,
7558                 NativeFinalizeCallback<std::string>);
7559     }
7560     gettimeofday(&g_endTime, nullptr);
7561     TEST_TIME(CopyableGlobal::SetWeakCallback::String);
7562 }
7563 
HWTEST_F_L0(JSNApiSplTest,BigIntRef_New)7564 HWTEST_F_L0(JSNApiSplTest, BigIntRef_New)
7565 {
7566     LocalScope scope(vm_);
7567     CalculateForTime();
7568     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
7569     uint64_t minUint64 = std::numeric_limits<uint64_t>::min();
7570     int64_t maxInt64 = std::numeric_limits<int64_t>::max();
7571     int64_t minInt64 = std::numeric_limits<int64_t>::min();
7572     gettimeofday(&g_beginTime, nullptr);
7573     for (int i = 0; i < NUM_COUNT; i++) {
7574         BigIntRef::New(vm_, maxUint64);
7575     }
7576     gettimeofday(&g_endTime, nullptr);
7577     TEST_TIME(BigIntRef::New::Uint64::Max);
7578     gettimeofday(&g_beginTime, nullptr);
7579     for (int i = 0; i < NUM_COUNT; i++) {
7580         BigIntRef::New(vm_, minUint64);
7581     }
7582     gettimeofday(&g_endTime, nullptr);
7583     TEST_TIME(BigIntRef::New::Uint64::Min);
7584     gettimeofday(&g_beginTime, nullptr);
7585     for (int i = 0; i < NUM_COUNT; i++) {
7586         BigIntRef::New(vm_, maxInt64);
7587     }
7588     gettimeofday(&g_endTime, nullptr);
7589     TEST_TIME(BigIntRef::New::Int64::Max);
7590     gettimeofday(&g_beginTime, nullptr);
7591     for (int i = 0; i < NUM_COUNT; i++) {
7592         BigIntRef::New(vm_, minInt64);
7593     }
7594     gettimeofday(&g_endTime, nullptr);
7595     TEST_TIME(BigIntRef::New::Int64::Min);
7596 }
7597 
HWTEST_F_L0(JSNApiSplTest,BigIntRef_CreateBigWords)7598 HWTEST_F_L0(JSNApiSplTest, BigIntRef_CreateBigWords)
7599 {
7600     LocalScope scope(vm_);
7601     CalculateForTime();
7602     bool sign = false;
7603     uint32_t size = 3; // 3 = random number
7604     const uint64_t words[3] = {
7605         std::numeric_limits<uint64_t>::min() - 1,
7606         std::numeric_limits<uint64_t>::min(),
7607         std::numeric_limits<uint64_t>::max(),
7608     };
7609     gettimeofday(&g_beginTime, nullptr);
7610     for (int i = 0; i < NUM_COUNT; i++) {
7611         BigIntRef::CreateBigWords(vm_, sign, size, words);
7612     }
7613     gettimeofday(&g_endTime, nullptr);
7614     TEST_TIME(BigIntRef::CreateBigWords);
7615 }
7616 
HWTEST_F_L0(JSNApiSplTest,BigIntRef_GetWordsArraySize)7617 HWTEST_F_L0(JSNApiSplTest, BigIntRef_GetWordsArraySize)
7618 {
7619     LocalScope scope(vm_);
7620     CalculateForTime();
7621     bool sign = false;
7622     uint32_t size = 3; // 3 = random number
7623     const uint64_t words[3] = {
7624         std::numeric_limits<uint64_t>::min() - 1,
7625         std::numeric_limits<uint64_t>::min(),
7626         std::numeric_limits<uint64_t>::max(),
7627     };
7628     Local<JSValueRef> bigWords = BigIntRef::CreateBigWords(vm_, sign, size, words);
7629     Local<BigIntRef> bigWordsRef(bigWords);
7630     gettimeofday(&g_beginTime, nullptr);
7631     for (int i = 0; i < NUM_COUNT; i++) {
7632         bigWordsRef->GetWordsArraySize(vm_);
7633     }
7634     gettimeofday(&g_endTime, nullptr);
7635     TEST_TIME(BigIntRef::GetWordsArraySize);
7636 }
7637 
HWTEST_F_L0(JSNApiSplTest,BigIntRef_GetWordsArray)7638 HWTEST_F_L0(JSNApiSplTest, BigIntRef_GetWordsArray)
7639 {
7640     LocalScope scope(vm_);
7641     CalculateForTime();
7642     bool sign = false;
7643     uint32_t size = 3; // 3 = random number
7644     const uint64_t words[3] = {
7645         std::numeric_limits<uint64_t>::min() - 1,
7646         std::numeric_limits<uint64_t>::min(),
7647         std::numeric_limits<uint64_t>::max(),
7648     };
7649     Local<JSValueRef> bigWords = BigIntRef::CreateBigWords(vm_, sign, size, words);
7650     Local<BigIntRef> bigWordsRef(bigWords);
7651     bool resultSignBit = true;
7652     uint64_t *resultWords = new uint64_t[3]();
7653     gettimeofday(&g_beginTime, nullptr);
7654     for (int i = 0; i < NUM_COUNT; i++) {
7655         bigWordsRef->GetWordsArray(vm_, &resultSignBit, size, resultWords);
7656     }
7657     gettimeofday(&g_endTime, nullptr);
7658     TEST_TIME(BigIntRef::GetWordsArray::Uint64);
7659 }
7660 
HWTEST_F_L0(JSNApiSplTest,BigIntRef_BigIntToInt64)7661 HWTEST_F_L0(JSNApiSplTest, BigIntRef_BigIntToInt64)
7662 {
7663     LocalScope scope(vm_);
7664     CalculateForTime();
7665     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
7666     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
7667     int64_t toNum;
7668     bool lossless = true;
7669     gettimeofday(&g_beginTime, nullptr);
7670     for (int i = 0; i < NUM_COUNT; i++) {
7671         maxBigintUint64->BigIntToInt64(vm_, &toNum, &lossless);
7672     }
7673     gettimeofday(&g_endTime, nullptr);
7674     TEST_TIME(BigIntRef::BigIntToInt64);
7675 }
7676 
HWTEST_F_L0(JSNApiSplTest,BigIntRef_BigIntToUint64)7677 HWTEST_F_L0(JSNApiSplTest, BigIntRef_BigIntToUint64)
7678 {
7679     LocalScope scope(vm_);
7680     CalculateForTime();
7681     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
7682     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
7683     uint64_t toNum;
7684     bool lossless = true;
7685     gettimeofday(&g_beginTime, nullptr);
7686     for (int i = 0; i < NUM_COUNT; i++) {
7687         maxBigintUint64->BigIntToUint64(vm_, &toNum, &lossless);
7688     }
7689     gettimeofday(&g_endTime, nullptr);
7690     TEST_TIME(BigIntRef::BigIntToUint64);
7691 }
7692 
HWTEST_F_L0(JSNApiSplTest,SymbolRef_New)7693 HWTEST_F_L0(JSNApiSplTest, SymbolRef_New)
7694 {
7695     LocalScope scope(vm_);
7696     CalculateForTime();
7697     std::string testUtf8 = "Hello world";
7698     Local<StringRef> description = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
7699     gettimeofday(&g_beginTime, nullptr);
7700     for (int i = 0; i < NUM_COUNT; i++) {
7701         SymbolRef::New(vm_, description);
7702     }
7703     gettimeofday(&g_endTime, nullptr);
7704     TEST_TIME(SymbolRef::New::StringRef);
7705 }
7706 
HWTEST_F_L0(JSNApiSplTest,SymbolRef_GetDescription)7707 HWTEST_F_L0(JSNApiSplTest, SymbolRef_GetDescription)
7708 {
7709     LocalScope scope(vm_);
7710     CalculateForTime();
7711     std::string testUtf8 = "Hello world";
7712     Local<StringRef> description = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
7713     Local<SymbolRef> symbol = SymbolRef::New(vm_, description);
7714     gettimeofday(&g_beginTime, nullptr);
7715     for (int i = 0; i < NUM_COUNT; i++) {
7716         symbol->GetDescription(vm_);
7717     }
7718     gettimeofday(&g_endTime, nullptr);
7719     TEST_TIME(SymbolRef::GetDescription);
7720 }
7721 
HWTEST_F_L0(JSNApiSplTest,NativePointerRef_New)7722 HWTEST_F_L0(JSNApiSplTest, NativePointerRef_New)
7723 {
7724     LocalScope scope(vm_);
7725     CalculateForTime();
7726     void *vps = static_cast<void *>(new std::string("test"));
7727     void *vpd = new double(123.456);
7728     void *vpc = new char('a');
7729     void *vpl = new long(123456);
7730     void *vpi = new int(123);
7731     gettimeofday(&g_beginTime, nullptr);
7732     for (int i = 0; i < NUM_COUNT; i++) {
7733         NativePointerRef::New(vm_, vps);
7734     }
7735     gettimeofday(&g_endTime, nullptr);
7736     TEST_TIME(NativePointerRef::New::String);
7737     gettimeofday(&g_beginTime, nullptr);
7738     for (int i = 0; i < NUM_COUNT; i++) {
7739         NativePointerRef::New(vm_, vpd);
7740     }
7741     gettimeofday(&g_endTime, nullptr);
7742     TEST_TIME(NativePointerRef::New::Double);
7743     gettimeofday(&g_beginTime, nullptr);
7744     for (int i = 0; i < NUM_COUNT; i++) {
7745         NativePointerRef::New(vm_, vpc);
7746     }
7747     gettimeofday(&g_endTime, nullptr);
7748     TEST_TIME(NativePointerRef::New::Char);
7749     gettimeofday(&g_beginTime, nullptr);
7750     for (int i = 0; i < NUM_COUNT; i++) {
7751         NativePointerRef::New(vm_, vpl);
7752     }
7753     gettimeofday(&g_endTime, nullptr);
7754     TEST_TIME(NativePointerRef::New::Long);
7755     gettimeofday(&g_beginTime, nullptr);
7756     for (int i = 0; i < NUM_COUNT; i++) {
7757         NativePointerRef::New(vm_, vpi);
7758     }
7759     gettimeofday(&g_endTime, nullptr);
7760     TEST_TIME(NativePointerRef::New::Int);
7761 }
7762 
HWTEST_F_L0(JSNApiSplTest,NativePointerRef_New_Fun)7763 HWTEST_F_L0(JSNApiSplTest, NativePointerRef_New_Fun)
7764 {
7765     LocalScope scope(vm_);
7766     CalculateForTime();
7767     NativePointerCallback callBack = nullptr;
7768     void *vps = static_cast<void *>(new std::string("test"));
7769     void *vps1 = static_cast<void *>(new std::string("test"));
7770     void *vpd = new double(123.456);
7771     void *vpd1 = new double(123.456);
7772     void *vpc = new char('a');
7773     void *vpc1 = new char('e');
7774     void *vpl = new long(123456);
7775     void *vpl1 = new long(123456);
7776     void *vpi = new int(123);
7777     void *vpi1 = new int(123);
7778     gettimeofday(&g_beginTime, nullptr);
7779     for (int i = 0; i < NUM_COUNT; i++) {
7780         NativePointerRef::New(vm_, vps, callBack, vps1, 0);
7781     }
7782     gettimeofday(&g_endTime, nullptr);
7783     TEST_TIME(NativePointerRef::New::Fun::String);
7784     gettimeofday(&g_beginTime, nullptr);
7785     for (int i = 0; i < NUM_COUNT; i++) {
7786         NativePointerRef::New(vm_, vpd, callBack, vpd1, 0);
7787     }
7788     gettimeofday(&g_endTime, nullptr);
7789     TEST_TIME(NativePointerRef::New::Fun::Double);
7790     gettimeofday(&g_beginTime, nullptr);
7791     for (int i = 0; i < NUM_COUNT; i++) {
7792         NativePointerRef::New(vm_, vpc, callBack, vpc1, 0);
7793     }
7794     gettimeofday(&g_endTime, nullptr);
7795     TEST_TIME(NativePointerRef::New::Fun::Char);
7796     gettimeofday(&g_beginTime, nullptr);
7797     for (int i = 0; i < NUM_COUNT; i++) {
7798         NativePointerRef::New(vm_, vpl, callBack, vpl1, 0);
7799     }
7800     gettimeofday(&g_endTime, nullptr);
7801     TEST_TIME(NativePointerRef::New::Fun::Long);
7802     gettimeofday(&g_beginTime, nullptr);
7803     for (int i = 0; i < NUM_COUNT; i++) {
7804         NativePointerRef::New(vm_, vpi, callBack, vpi1, 0);
7805     }
7806     gettimeofday(&g_endTime, nullptr);
7807     TEST_TIME(NativePointerRef::New::Fun::Int);
7808 }
7809 
HWTEST_F_L0(JSNApiSplTest,NativePointerRef_Value)7810 HWTEST_F_L0(JSNApiSplTest, NativePointerRef_Value)
7811 {
7812     LocalScope scope(vm_);
7813     CalculateForTime();
7814     void *vps = static_cast<void *>(new std::string("test"));
7815     void *vps1 = static_cast<void *>(new std::string("test"));
7816     void *vpd = new double(123.456);
7817     void *vpd1 = new double(123.456);
7818     void *vpc = new char('a');
7819     void *vpc1 = new char('c');
7820     void *vpl = new long(123456);
7821     void *vpl1 = new long(123456);
7822     void *vpi = new int(123);
7823     void *vpi1 = new int(123);
7824     Local<NativePointerRef> res_vps = NativePointerRef::New(vm_, vps, NativeAreaAllocator::FreeBufferFunc, vps1, 0);
7825     Local<NativePointerRef> res_vpd = NativePointerRef::New(vm_, vpd, NativeAreaAllocator::FreeBufferFunc, vpd1, 0);
7826     Local<NativePointerRef> res_vpc = NativePointerRef::New(vm_, vpc, NativeAreaAllocator::FreeBufferFunc, vpc1, 0);
7827     Local<NativePointerRef> res_vpl = NativePointerRef::New(vm_, vpl, NativeAreaAllocator::FreeBufferFunc, vpl1, 0);
7828     Local<NativePointerRef> res_vpi = NativePointerRef::New(vm_, vpi, NativeAreaAllocator::FreeBufferFunc, vpi1, 0);
7829     gettimeofday(&g_beginTime, nullptr);
7830     for (int i = 0; i < NUM_COUNT; i++) {
7831         res_vps->Value();
7832     }
7833     gettimeofday(&g_endTime, nullptr);
7834     TEST_TIME(NativePointerRef::Value::String);
7835     gettimeofday(&g_beginTime, nullptr);
7836     for (int i = 0; i < NUM_COUNT; i++) {
7837         res_vpd->Value();
7838     }
7839     gettimeofday(&g_endTime, nullptr);
7840     TEST_TIME(NativePointerRef::Value::Double);
7841     gettimeofday(&g_beginTime, nullptr);
7842     for (int i = 0; i < NUM_COUNT; i++) {
7843         res_vpc->Value();
7844     }
7845     gettimeofday(&g_endTime, nullptr);
7846     TEST_TIME(NativePointerRef::Value::Char);
7847     gettimeofday(&g_beginTime, nullptr);
7848     for (int i = 0; i < NUM_COUNT; i++) {
7849         res_vpl->Value();
7850     }
7851     gettimeofday(&g_endTime, nullptr);
7852     TEST_TIME(NativePointerRef::Value::Long);
7853     gettimeofday(&g_beginTime, nullptr);
7854     for (int i = 0; i < NUM_COUNT; i++) {
7855         res_vpi->Value();
7856     }
7857     gettimeofday(&g_endTime, nullptr);
7858     TEST_TIME(NativePointerRef::Value::Int);
7859 }
7860 
HWTEST_F_L0(JSNApiSplTest,FunctionRef_New)7861 HWTEST_F_L0(JSNApiSplTest, FunctionRef_New)
7862 {
7863     LocalScope scope(vm_);
7864     CalculateForTime();
7865     gettimeofday(&g_beginTime, nullptr);
7866     for (int i = 0; i < NUM_COUNT; i++) {
7867         FunctionRef::New(vm_, FunCallback);
7868     }
7869     gettimeofday(&g_endTime, nullptr);
7870     TEST_TIME(FunctionRef::New);
7871 }
7872 
HWTEST_F_L0(JSNApiSplTest,FunctionRef_NewClassFunction)7873 HWTEST_F_L0(JSNApiSplTest, FunctionRef_NewClassFunction)
7874 {
7875     LocalScope scope(vm_);
7876     CalculateForTime();
7877     gettimeofday(&g_beginTime, nullptr);
7878     for (int i = 0; i < NUM_COUNT; i++) {
7879         FunctionRef::NewClassFunction(vm_, FunCallback, nullptr, nullptr);
7880     }
7881     gettimeofday(&g_endTime, nullptr);
7882     TEST_TIME(FunctionRef::NewClassFunction);
7883 }
7884 
HWTEST_F_L0(JSNApiSplTest,FunctionRef_Call)7885 HWTEST_F_L0(JSNApiSplTest, FunctionRef_Call)
7886 {
7887     LocalScope scope(vm_);
7888     CalculateForTime();
7889     uint32_t inputUnit32 = 32; // 32 = random number
7890     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
7891     Local<IntegerRef> intValue = IntegerRef::New(vm_, 0);
7892     Local<JSValueRef> targetBool = BooleanRef::New(vm_, false);
7893     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
7894     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
7895     std::vector<Local<JSValueRef>> argumentsInt;
7896     std::vector<Local<JSValueRef>> argumentsBool;
7897     std::vector<Local<JSValueRef>> argumentsNum;
7898     std::vector<Local<JSValueRef>> argumentsBig;
7899     argumentsInt.emplace_back(intValue);
7900     argumentsBool.emplace_back(targetBool);
7901     argumentsNum.emplace_back(resUnit32);
7902     argumentsBig.emplace_back(maxBigintUint64);
7903     Local<FunctionRef> callback = FunctionRef::New(vm_, FunCallback);
7904     gettimeofday(&g_beginTime, nullptr);
7905     for (int i = 0; i < NUM_COUNT; i++) {
7906         callback->Call(vm_, JSValueRef::Undefined(vm_), argumentsInt.data(), argumentsInt.size());
7907     }
7908     gettimeofday(&g_endTime, nullptr);
7909     TEST_TIME(FunctionRef::Call::IntegerRef);
7910     gettimeofday(&g_beginTime, nullptr);
7911     for (int i = 0; i < NUM_COUNT; i++) {
7912         callback->Call(vm_, JSValueRef::Undefined(vm_), argumentsBool.data(), argumentsBool.size());
7913     }
7914     gettimeofday(&g_endTime, nullptr);
7915     TEST_TIME(FunctionRef::Call::BooleanRef);
7916     gettimeofday(&g_beginTime, nullptr);
7917     for (int i = 0; i < NUM_COUNT; i++) {
7918         callback->Call(vm_, JSValueRef::Undefined(vm_), argumentsNum.data(), argumentsNum.size());
7919     }
7920     gettimeofday(&g_endTime, nullptr);
7921     TEST_TIME(FunctionRef::Call::NumberRef);
7922     gettimeofday(&g_beginTime, nullptr);
7923     for (int i = 0; i < NUM_COUNT; i++) {
7924         callback->Call(vm_, JSValueRef::Undefined(vm_), argumentsBig.data(), argumentsBig.size());
7925     }
7926     gettimeofday(&g_endTime, nullptr);
7927     TEST_TIME(FunctionRef::Call::BigIntRef);
7928 }
7929 
HWTEST_F_L0(JSNApiSplTest,FunctionRef_Call2)7930 HWTEST_F_L0(JSNApiSplTest, FunctionRef_Call2)
7931 {
7932     LocalScope scope(vm_);
7933     CalculateForTime();
7934     std::string testUtf8 = "Hello world";
7935     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
7936     std::vector<Local<JSValueRef>> argumentsStr;
7937     argumentsStr.emplace_back(stringUtf8);
7938     Local<FunctionRef> callback = FunctionRef::New(vm_, FunCallback);
7939     gettimeofday(&g_beginTime, nullptr);
7940     for (int i = 0; i < NUM_COUNT; i++) {
7941         callback->Call(vm_, JSValueRef::Undefined(vm_), argumentsStr.data(), argumentsStr.size());
7942     }
7943     gettimeofday(&g_endTime, nullptr);
7944     TEST_TIME(FunctionRef::Call::StringRef);
7945 }
7946 
HWTEST_F_L0(JSNApiSplTest,FunctionRef_Constructor)7947 HWTEST_F_L0(JSNApiSplTest, FunctionRef_Constructor)
7948 {
7949     LocalScope scope(vm_);
7950     CalculateForTime();
7951     Local<FunctionRef> cls = FunctionRef::NewClassFunction(vm_, FunCallback, nullptr, nullptr);
7952     Local<JSValueRef> argv[1];          // 1 = Array Size
7953     int num = 13;                      // 13 = random number
7954     argv[0] = NumberRef::New(vm_, num); // 0 = The first element
7955     gettimeofday(&g_beginTime, nullptr);
7956     for (int i = 0; i < NUM_COUNT; i++) {
7957         cls->Constructor(vm_, argv, 1);
7958     }
7959     gettimeofday(&g_endTime, nullptr);
7960     TEST_TIME(FunctionRef::Constructor);
7961 }
7962 
HWTEST_F_L0(JSNApiSplTest,FunctionRef_GetFunctionPrototype)7963 HWTEST_F_L0(JSNApiSplTest, FunctionRef_GetFunctionPrototype)
7964 {
7965     LocalScope scope(vm_);
7966     CalculateForTime();
7967     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
7968     JSHandle<JSTaggedValue> set = env->GetBuiltinsSetFunction();
7969     Local<FunctionRef> setLocal = JSNApiHelper::ToLocal<FunctionRef>(set);
7970     gettimeofday(&g_beginTime, nullptr);
7971     for (int i = 0; i < NUM_COUNT; i++) {
7972         [[maybe_unused]] Local<JSValueRef> funcProtoType = setLocal->GetFunctionPrototype(vm_);
7973     }
7974     gettimeofday(&g_endTime, nullptr);
7975     TEST_TIME(FunctionRef::GetFunctionPrototype);
7976 }
7977 
HWTEST_F_L0(JSNApiSplTest,FunctionRef_Inherit)7978 HWTEST_F_L0(JSNApiSplTest, FunctionRef_Inherit)
7979 {
7980     LocalScope scope(vm_);
7981     CalculateForTime();
7982     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
7983     JSHandle<JSTaggedValue> set = env->GetBuiltinsSetFunction();
7984     Local<FunctionRef> setLocal = JSNApiHelper::ToLocal<FunctionRef>(set);
7985     JSHandle<JSTaggedValue> map = env->GetBuiltinsMapFunction();
7986     Local<FunctionRef> mapLocal = JSNApiHelper::ToLocal<FunctionRef>(map);
7987     gettimeofday(&g_beginTime, nullptr);
7988     for (int i = 0; i < NUM_COUNT; i++) {
7989         mapLocal->Inherit(vm_, setLocal);
7990     }
7991     gettimeofday(&g_endTime, nullptr);
7992     TEST_TIME(FunctionRef::Inherit);
7993 }
7994 
HWTEST_F_L0(JSNApiSplTest,FunctionRef_SetName)7995 HWTEST_F_L0(JSNApiSplTest, FunctionRef_SetName)
7996 {
7997     LocalScope scope(vm_);
7998     CalculateForTime();
7999     Local<FunctionRef> res = FunctionRef::NewClassFunction(vm_, FunCallback, nullptr, nullptr);
8000     Local<StringRef> origin = StringRef::NewFromUtf8(vm_, "origin test");
8001     gettimeofday(&g_beginTime, nullptr);
8002     for (int i = 0; i < NUM_COUNT; i++) {
8003         res->SetName(vm_, origin);
8004     }
8005     gettimeofday(&g_endTime, nullptr);
8006     TEST_TIME(FunctionRef::SetName);
8007 }
8008 
HWTEST_F_L0(JSNApiSplTest,FunctionRef_GetName)8009 HWTEST_F_L0(JSNApiSplTest, FunctionRef_GetName)
8010 {
8011     LocalScope scope(vm_);
8012     CalculateForTime();
8013     Local<FunctionRef> res = FunctionRef::NewClassFunction(vm_, FunCallback, nullptr, nullptr);
8014     Local<StringRef> origin = StringRef::NewFromUtf8(vm_, "origin test");
8015     res->SetName(vm_, origin);
8016     gettimeofday(&g_beginTime, nullptr);
8017     for (int i = 0; i < NUM_COUNT; i++) {
8018         res->GetName(vm_);
8019     }
8020     gettimeofday(&g_endTime, nullptr);
8021     TEST_TIME(FunctionRef::GetName);
8022 }
8023 
HWTEST_F_L0(JSNApiSplTest,FunctionRef_IsNative)8024 HWTEST_F_L0(JSNApiSplTest, FunctionRef_IsNative)
8025 {
8026     LocalScope scope(vm_);
8027     CalculateForTime();
8028     Local<FunctionRef> res = FunctionRef::NewClassFunction(vm_, FunCallback, nullptr, nullptr);
8029     gettimeofday(&g_beginTime, nullptr);
8030     for (int i = 0; i < NUM_COUNT; i++) {
8031         res->IsNative(vm_);
8032     }
8033     gettimeofday(&g_endTime, nullptr);
8034     TEST_TIME(FunctionRef::IsNative);
8035 }
8036 
HWTEST_F_L0(JSNApiSplTest,ArrayRef_New)8037 HWTEST_F_L0(JSNApiSplTest, ArrayRef_New)
8038 {
8039     LocalScope scope(vm_);
8040     CalculateForTime();
8041     gettimeofday(&g_beginTime, nullptr);
8042     for (int i = 0; i < NUM_COUNT; i++) {
8043         Local<ArrayRef> arrayObj = ArrayRef::New(vm_, 3);
8044         EXPECT_TRUE(arrayObj->IsArray(vm_));
8045     }
8046     gettimeofday(&g_endTime, nullptr);
8047     TEST_TIME(ArrayRef::New);
8048 }
8049 
HWTEST_F_L0(JSNApiSplTest,ArrayRef_Length)8050 HWTEST_F_L0(JSNApiSplTest, ArrayRef_Length)
8051 {
8052     LocalScope scope(vm_);
8053     CalculateForTime();
8054     Local<ArrayRef> arrayObj = ArrayRef::New(vm_, 3);
8055     gettimeofday(&g_beginTime, nullptr);
8056     for (int i = 0; i < NUM_COUNT; i++) {
8057         arrayObj->Length(vm_);
8058     }
8059     gettimeofday(&g_endTime, nullptr);
8060     TEST_TIME(ArrayRef::Length);
8061 }
8062 
HWTEST_F_L0(JSNApiSplTest,ArrayRef_SetValueAt)8063 HWTEST_F_L0(JSNApiSplTest, ArrayRef_SetValueAt)
8064 {
8065     LocalScope scope(vm_);
8066     CalculateForTime();
8067     Local<ArrayRef> arrayObj = ArrayRef::New(vm_, 1);
8068     uint32_t inputUnit32 = 32;
8069     uint64_t maxUint64 = std::numeric_limits<uint64_t>::max();
8070     std::string testUtf8 = "Hello world";
8071     Local<IntegerRef> intValue = IntegerRef::New(vm_, 0);
8072     Local<JSValueRef> targetBool = BooleanRef::New(vm_, false);
8073     Local<NumberRef> resUnit32 = NumberRef::New(vm_, inputUnit32);
8074     Local<BigIntRef> maxBigintUint64 = BigIntRef::New(vm_, maxUint64);
8075     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
8076     gettimeofday(&g_beginTime, nullptr);
8077     for (int i = 0; i < NUM_COUNT; i++) {
8078         ArrayRef::SetValueAt(vm_, arrayObj, 0, intValue);
8079     }
8080     gettimeofday(&g_endTime, nullptr);
8081     TEST_TIME(ArrayRef::SetValueAt::IntegerRef);
8082     gettimeofday(&g_beginTime, nullptr);
8083     for (int i = 0; i < NUM_COUNT; i++) {
8084         ArrayRef::SetValueAt(vm_, arrayObj, 0, targetBool);
8085     }
8086     gettimeofday(&g_endTime, nullptr);
8087     TEST_TIME(ArrayRef::SetValueAt::BooleanRef);
8088     gettimeofday(&g_beginTime, nullptr);
8089     for (int i = 0; i < NUM_COUNT; i++) {
8090         ArrayRef::SetValueAt(vm_, arrayObj, 0, resUnit32);
8091     }
8092     gettimeofday(&g_endTime, nullptr);
8093     TEST_TIME(ArrayRef::SetValueAt::NumberRef);
8094     gettimeofday(&g_beginTime, nullptr);
8095     for (int i = 0; i < NUM_COUNT; i++) {
8096         ArrayRef::SetValueAt(vm_, arrayObj, 0, maxBigintUint64);
8097     }
8098     gettimeofday(&g_endTime, nullptr);
8099     TEST_TIME(ArrayRef::SetValueAt::BigIntRef);
8100     gettimeofday(&g_beginTime, nullptr);
8101     for (int i = 0; i < NUM_COUNT; i++) {
8102         ArrayRef::SetValueAt(vm_, arrayObj, 0, stringUtf8);
8103     }
8104     gettimeofday(&g_endTime, nullptr);
8105     TEST_TIME(ArrayRef::SetValueAt::StringRef);
8106 }
8107 
HWTEST_F_L0(JSNApiSplTest,ArrayRef_GetValueAt)8108 HWTEST_F_L0(JSNApiSplTest, ArrayRef_GetValueAt)
8109 {
8110     LocalScope scope(vm_);
8111     CalculateForTime();
8112     Local<ArrayRef> arrayObj = ArrayRef::New(vm_, 1);
8113     std::string testUtf8 = "Hello world";
8114     Local<StringRef> stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str());
8115     ArrayRef::SetValueAt(vm_, arrayObj, 0, stringUtf8);
8116     gettimeofday(&g_beginTime, nullptr);
8117     for (int i = 0; i < NUM_COUNT; i++) {
8118         ArrayRef::GetValueAt(vm_, arrayObj, 0);
8119     }
8120     gettimeofday(&g_endTime, nullptr);
8121     TEST_TIME(ArrayRef::GetValueAt::StringRef);
8122 }
8123 
HWTEST_F_L0(JSNApiSplTest,CopyableGlobal_GetEcmaVM)8124 HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_GetEcmaVM)
8125 {
8126     LocalScope scope(vm_);
8127     CalculateForTime();
8128     Local<IntegerRef> intValue = IntegerRef::New(vm_, 13);
8129     CopyableGlobal<IntegerRef> copyGlobal(vm_, intValue);
8130     gettimeofday(&g_beginTime, nullptr);
8131     for (int i = 0; i < NUM_COUNT; i++) {
8132         copyGlobal.GetEcmaVM();
8133     }
8134     gettimeofday(&g_endTime, nullptr);
8135     TEST_TIME(CopyableGlobal::GetEcmaVM);
8136 }
8137 }
8138