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