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