/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include "gtest/gtest.h" #include "ecmascript/base/string_helper.h" #include "ecmascript/builtins/builtins.h" #include "ecmascript/builtins/builtins_function.h" #include "ecmascript/builtins/builtins_locale.h" #include "ecmascript/builtins/builtins_regexp.h" #include "ecmascript/containers/containers_hashset.h" #include "ecmascript/containers/containers_lightweightmap.h" #include "ecmascript/containers/containers_lightweightset.h" #include "ecmascript/containers/containers_private.h" #include "ecmascript/debugger/hot_reload_manager.h" #include "ecmascript/debugger/js_debugger_manager.h" #include "ecmascript/ecma_global_storage.h" #include "ecmascript/ecma_vm.h" #include "ecmascript/global_env.h" #include "ecmascript/js_api/js_api_arraylist.h" #include "ecmascript/js_api/js_api_deque.h" #include "ecmascript/js_api/js_api_hashmap.h" #include "ecmascript/js_api/js_api_linked_list.h" #include "ecmascript/js_api/js_api_linked_list_iterator.h" #include "ecmascript/js_api/js_api_list.h" #include "ecmascript/js_api/js_api_plain_array.h" #include "ecmascript/js_api/js_api_queue.h" #include "ecmascript/js_api/js_api_stack.h" #include "ecmascript/js_api/js_api_tree_map.h" #include "ecmascript/js_api/js_api_tree_set.h" #include "ecmascript/js_api/js_api_vector.h" #include "ecmascript/js_array.h" #include "ecmascript/js_bigint.h" #include "ecmascript/js_collator.h" #include "ecmascript/js_date.h" #include "ecmascript/js_date_time_format.h" #include "ecmascript/js_generator_object.h" #include "ecmascript/js_iterator.h" #include "ecmascript/js_list_format.h" #include "ecmascript/js_locale.h" #include "ecmascript/js_map.h" #include "ecmascript/js_map_iterator.h" #include "ecmascript/js_number_format.h" #include "ecmascript/jspandafile/js_pandafile_manager.h" #include "ecmascript/js_plural_rules.h" #include "ecmascript/js_primitive_ref.h" #include "ecmascript/js_regexp.h" #include "ecmascript/js_runtime_options.h" #include "ecmascript/js_set.h" #include "ecmascript/js_set_iterator.h" #include "ecmascript/js_string_iterator.h" #include "ecmascript/js_tagged_number.h" #include "ecmascript/js_thread.h" #include "ecmascript/linked_hash_table.h" #include "ecmascript/module/js_module_deregister.h" #include "ecmascript/module/js_module_namespace.h" #include "ecmascript/module/js_module_record.h" #include "ecmascript/module/js_module_source_text.h" #include "ecmascript/napi/include/jsnapi.h" #include "ecmascript/napi/jsnapi_helper.h" #include "ecmascript/object_factory.h" #include "ecmascript/tagged_array.h" #include "ecmascript/tagged_hash_array.h" #include "ecmascript/tagged_list.h" #include "ecmascript/tagged_tree.h" #include "ecmascript/tests/test_helper.h" using namespace panda; using namespace panda::ecmascript; static constexpr int NUM_COUNT = 10000; static constexpr int TIME_UNIT = 1000000; time_t g_timeFor = 0; struct timeval g_beginTime; struct timeval g_endTime; time_t g_time1 = 0; time_t g_time2 = 0; time_t g_time = 0; #define TEST_TIME(NAME) \ { \ g_time1 = (g_beginTime.tv_sec * TIME_UNIT) + (g_beginTime.tv_usec); \ g_time2 = (g_endTime.tv_sec * TIME_UNIT) + (g_endTime.tv_usec); \ g_time = g_time2 - g_time1; \ GTEST_LOG_(INFO) << "name =" << #NAME << " = Time =" << int(g_time - g_timeFor); \ } namespace panda::test { using BuiltinsFunction = ecmascript::builtins::BuiltinsFunction; Local FunCallback(JsiRuntimeCallInfo *info) { EscapeLocalScope scope(info->GetVM()); return scope.Escape(ArrayRef::New(info->GetVM(), info->GetArgsNumber())); } class JSNApiSplTest : public testing::Test { public: static void SetUpTestCase(void) { GTEST_LOG_(INFO) << "SetUpTestCase"; } static void TearDownTestCase(void) { GTEST_LOG_(INFO) << "TearDownCase"; } void SetUp() override { RuntimeOption option; option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); vm_ = JSNApi::CreateJSVM(option); ASSERT_TRUE(vm_ != nullptr) << "Cannot create Runtime"; thread_ = vm_->GetJSThread(); vm_->SetEnableForceGC(true); GTEST_LOG_(INFO) << "SetUp"; } void TearDown() override { vm_->SetEnableForceGC(false); JSNApi::DestroyJSVM(vm_); GTEST_LOG_(INFO) << "TearDown"; } protected: JSThread *thread_ = nullptr; EcmaVM *vm_ = nullptr; }; #ifndef UNUSED #define UNUSED(X) (void)(X) #endif template void FreeGlobalCallBack(void *ptr) { T *i = static_cast(ptr); UNUSED(i); } template void NativeFinalizeCallback(void *ptr) { T *i = static_cast(ptr); delete i; } void CalculateForTime() { gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { } gettimeofday(&g_endTime, nullptr); time_t start = (g_beginTime.tv_sec * TIME_UNIT) + (g_beginTime.tv_usec); time_t end = (g_endTime.tv_sec * TIME_UNIT) + (g_endTime.tv_usec); g_timeFor = end - start; GTEST_LOG_(INFO) << "timefor = " << g_timeFor; } static JSTaggedValue JSLocaleCreateWithOptionTest(JSThread *thread) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle newTarget(env->GetLocaleFunction()); JSHandle objFun = env->GetObjectFunction(); JSHandle languageKey = thread->GlobalConstants()->GetHandledLanguageString(); JSHandle regionKey = thread->GlobalConstants()->GetHandledRegionString(); JSHandle scriptKey = thread->GlobalConstants()->GetHandledScriptString(); JSHandle languageValue(factory->NewFromASCII("en")); JSHandle regionValue(factory->NewFromASCII("US")); JSHandle scriptValue(factory->NewFromASCII("Latn")); JSHandle locale(factory->NewFromASCII("en-Latn-US")); JSHandle optionsObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSObject::SetProperty(thread, optionsObj, languageKey, languageValue); JSObject::SetProperty(thread, optionsObj, regionKey, regionValue); JSObject::SetProperty(thread, optionsObj, scriptKey, scriptValue); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*newTarget), 8); ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = ecmascript::builtins::BuiltinsLocale::LocaleConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); return result; } HWTEST_F_L0(JSNApiSplTest, JSValueRef_False) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)JSValueRef::False(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::False); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_NewFromUtf8) { LocalScope scope(vm_); CalculateForTime(); Local obj(StringRef::NewFromUtf8(vm_, "-123.3")); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->ToObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToObject); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_NewFromUtf16) { LocalScope scope(vm_); CalculateForTime(); char16_t data = 0Xdf06; Local obj = StringRef::NewFromUtf16(vm_, &data); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->ToObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToObject); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_NumberRef) { LocalScope scope(vm_); CalculateForTime(); double num = 1.236; Local numberObj(NumberRef::New(vm_, num)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)numberObj->ToObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToObject); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_Int32_Max) { LocalScope scope(vm_); CalculateForTime(); int32_t num = std::numeric_limits::max(); Local obj = NumberRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->ToObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToObject); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_Int32_Min) { LocalScope scope(vm_); CalculateForTime(); int32_t num = std::numeric_limits::min(); Local obj = NumberRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->ToObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToObject); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_Int64_Max) { LocalScope scope(vm_); CalculateForTime(); int64_t num = std::numeric_limits::max(); Local obj = NumberRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->ToObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToObject); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_BigIntRef) { LocalScope scope(vm_); CalculateForTime(); uint64_t num = std::numeric_limits::max(); Local bigIntObj = BigIntRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)bigIntObj->ToObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToObject); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject_SymbolRef) { LocalScope scope(vm_); CalculateForTime(); Local symbolObj(SymbolRef::New(vm_, StringRef::NewFromUtf8(vm_, "-123.3"))); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)symbolObj->ToObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToObject); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt_True) { LocalScope scope(vm_); CalculateForTime(); int32_t num = 10; Local obj(NumberRef::New(vm_, num)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->IsInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsInt); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt_False) { LocalScope scope(vm_); CalculateForTime(); Local obj(StringRef::NewFromUtf8(vm_, "-123.3")); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->IsInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsInt); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt_Int64_Max) { LocalScope scope(vm_); CalculateForTime(); int64_t num = std::numeric_limits::max(); Local obj = NumberRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->IsInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsInt); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt_Double) { LocalScope scope(vm_); CalculateForTime(); double num = 1.235; Local obj = NumberRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->IsInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsInt); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsFunction_True) { LocalScope scope(vm_); CalculateForTime(); Deleter deleter = nullptr; void *cb = reinterpret_cast(BuiltinsFunction::FunctionPrototypeInvokeSelf); bool callNative = true; size_t nativeBindingSize = 15; Local obj(FunctionRef::NewClassFunction(vm_, FunCallback, deleter, cb, callNative, nativeBindingSize)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->IsFunction(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsFunction); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsFunction_False) { LocalScope scope(vm_); CalculateForTime(); double num = 1.235; Local obj = NumberRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->IsInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsFunction); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsSet) { LocalScope scope(vm_); CalculateForTime(); JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle constructor = env->GetBuiltinsSetFunction(); JSHandle set = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); JSHandle hashSet = LinkedHashSet::Create(thread); set->SetLinkedSet(thread, hashSet); JSHandle setTag = JSHandle::Cast(set); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(setTag)->IsSet(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsSet); } HWTEST_F_L0(JSNApiSplTest, BooleanRef_New_True) { LocalScope scope(vm_); CalculateForTime(); int num = -10000; Local obj; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { obj = BooleanRef::New(vm_, num); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BooleanRef::New); } HWTEST_F_L0(JSNApiSplTest, BooleanRef_New_False) { LocalScope scope(vm_); CalculateForTime(); Local obj; bool flag = false; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { obj = BooleanRef::New(vm_, flag); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BooleanRef::New); } HWTEST_F_L0(JSNApiSplTest, BooleanRef_Value_True) { LocalScope scope(vm_); CalculateForTime(); int num = -10000; Local obj(BooleanRef::New(vm_, num)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->Value(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BooleanRef::Value); } HWTEST_F_L0(JSNApiSplTest, BooleanRef_Value_False) { LocalScope scope(vm_); CalculateForTime(); Local obj = BooleanRef::New(vm_, 0); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->Value(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BooleanRef::Value); } HWTEST_F_L0(JSNApiSplTest, IsGeneratorFunction_True) { ObjectFactory *factory = vm_->GetFactory(); auto env = vm_->GetGlobalEnv(); JSHandle genFunc = env->GetGeneratorFunctionFunction(); JSHandle genObjHandleVal = factory->NewJSGeneratorObject(genFunc); JSHandle hclass = JSHandle::Cast(env->GetGeneratorFunctionClass()); JSHandle generatorFunc = JSHandle::Cast(factory->NewJSObject(hclass)); JSFunction::InitializeJSFunction(vm_->GetJSThread(), generatorFunc, FunctionKind::GENERATOR_FUNCTION); JSHandle generatorContext = factory->NewGeneratorContext(); generatorContext->SetMethod(vm_->GetJSThread(), generatorFunc.GetTaggedValue()); JSHandle generatorContextVal = JSHandle::Cast(generatorContext); genObjHandleVal->SetGeneratorContext(vm_->GetJSThread(), generatorContextVal.GetTaggedValue()); JSHandle genObjTagHandleVal = JSHandle::Cast(genObjHandleVal); Local genObjectRef = JSNApiHelper::ToLocal(genObjTagHandleVal); Local genObject = genObjectRef->GetGeneratorFunction(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { genObject->IsGeneratorFunction(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsGeneratorFunction); } HWTEST_F_L0(JSNApiSplTest, IsGeneratorFunction_False) { LocalScope scope(vm_); CalculateForTime(); Local obj = BooleanRef::New(vm_, 0); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { obj->IsGeneratorFunction(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsGeneratorFunction); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArrayBuffer) { static bool isFree = false; struct Data { int32_t length; }; const int32_t length = 15; Data *data = new Data(); data->length = length; Deleter deleter = [](void *buffer, void *data) -> void { delete[] reinterpret_cast(buffer); Data *currentData = reinterpret_cast(data); delete currentData; isFree = true; }; LocalScope scope(vm_); CalculateForTime(); uint8_t *buffer = new uint8_t[length](); Local arrayBuffer = ArrayBufferRef::New(vm_, buffer, length, deleter, data); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)arrayBuffer->IsArrayBuffer(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsArrayBuffer); } HWTEST_F_L0(JSNApiSplTest, BufferRef_New1) { static bool isFree = false; struct Data { int32_t length; }; const int32_t length = 15; Deleter deleter = [](void *buffer, void *data) -> void { delete[] reinterpret_cast(buffer); Data *currentData = reinterpret_cast(data); delete currentData; isFree = true; }; LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { isFree = false; uint8_t *buffer = new uint8_t[length](); Data *data = new Data(); data->length = length; (void)BufferRef::New(vm_, buffer, length, deleter, data); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BufferRef::New); } HWTEST_F_L0(JSNApiSplTest, BufferRef_New2) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)BufferRef::New(vm_, length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BufferRef::New); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBuffer) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local bufferRef = BufferRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)bufferRef->IsBuffer(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsBuffer); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsUint32Array) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 30; Local arrayBuffer = ArrayBufferRef::New(vm_, length); Local typedArray = Uint32ArrayRef::New(vm_, arrayBuffer, 4, 6); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)typedArray->IsUint32Array(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsBuIsUint32Arrayffer); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsFloat32Array) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 30; Local arrayBuffer = ArrayBufferRef::New(vm_, length); Local typedArray = Float32ArrayRef::New(vm_, arrayBuffer, 4, 6); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)typedArray->IsFloat32Array(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsFloat32Array); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsFloat64Array) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 30; Local arrayBuffer = ArrayBufferRef::New(vm_, length); Local floatArray = Float64ArrayRef::New(vm_, arrayBuffer, 4, 6); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)floatArray->IsFloat64Array(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsFloat64Array); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_TypeOf_String) { LocalScope scope(vm_); CalculateForTime(); Local origin = StringRef::NewFromUtf8(vm_, "1"); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)origin->Typeof(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::TypeOf); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_TypeOf_NumberRef) { LocalScope scope(vm_); CalculateForTime(); Local origin = NumberRef::New(vm_, 1); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)origin->Typeof(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::TypeOf); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_InstanceOf) { LocalScope scope(vm_); CalculateForTime(); Local origin = ObjectRef::New(vm_); JSHandle globalEnv = vm_->GetGlobalEnv(); JSHandle constructor(globalEnv->GetObjectFunction()); JSHandle arryListTag = JSHandle::Cast(constructor); Local value = JSNApiHelper::ToLocal(arryListTag); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)origin->InstanceOf(vm_, value); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::InstanceOf); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArrayList) { LocalScope scope(vm_); CalculateForTime(); JSThread *thread = vm_->GetJSThread(); auto factory = thread->GetEcmaVM()->GetFactory(); auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetFunctionPrototype(); JSHandle arrayListClass = factory->NewEcmaHClass(JSAPIArrayList::SIZE, JSType::JS_API_ARRAY_LIST, proto); JSHandle jsArrayList = JSHandle::Cast(factory->NewJSObjectWithInit(arrayListClass)); jsArrayList->SetLength(thread, JSTaggedValue(0)); JSHandle arryListTag = JSHandle::Cast(jsArrayList); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(arryListTag)->IsArrayList(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsArrayList); } HWTEST_F_L0(JSNApiSplTest, PromiseRef_Catch) { LocalScope scope(vm_); CalculateForTime(); Local capability = PromiseCapabilityRef::New(vm_); Local promise = capability->GetPromise(vm_); Local reject = FunctionRef::New(vm_, FunCallback); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)promise->Catch(vm_, reject); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PromiseRef::Catch); } HWTEST_F_L0(JSNApiSplTest, PromiseRef_Finally) { LocalScope scope(vm_); CalculateForTime(); Local capability = PromiseCapabilityRef::New(vm_); Local promise = capability->GetPromise(vm_); Local reject = FunctionRef::New(vm_, FunCallback); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)promise->Finally(vm_, reject); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PromiseRef::Finally); } HWTEST_F_L0(JSNApiSplTest, PromiseRef_Then) { LocalScope scope(vm_); CalculateForTime(); Local capability = PromiseCapabilityRef::New(vm_); Local promise = capability->GetPromise(vm_); Local callback = FunctionRef::New(vm_, FunCallback); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)promise->Then(vm_, callback); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PromiseRef::Then); } HWTEST_F_L0(JSNApiSplTest, PromiseRef_Then1) { LocalScope scope(vm_); CalculateForTime(); Local capability = PromiseCapabilityRef::New(vm_); Local promise = capability->GetPromise(vm_); Local callback = FunctionRef::New(vm_, FunCallback); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)promise->Then(vm_, callback, callback); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PromiseRef::Then); } HWTEST_F_L0(JSNApiSplTest, PromiseCapabilityRef_New) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)PromiseCapabilityRef::New(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PromiseCapabilityRef::New); } HWTEST_F_L0(JSNApiSplTest, PromiseCapabilityRef_GetPromise) { LocalScope scope(vm_); CalculateForTime(); Local capability = PromiseCapabilityRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)capability->GetPromise(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PromiseCapabilityRef::GetPromise); } HWTEST_F_L0(JSNApiSplTest, PromiseCapabilityRef_Resolve) { LocalScope scope(vm_); CalculateForTime(); Local capability = PromiseCapabilityRef::New(vm_); Local promise = capability->GetPromise(vm_); Local resolve = FunctionRef::New(vm_, FunCallback); Local reject = FunctionRef::New(vm_, FunCallback); promise->Then(vm_, resolve, reject); Local value = NumberRef::New(vm_, 300.3); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)capability->Resolve(vm_, value); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PromiseCapabilityRef::Resolve); } HWTEST_F_L0(JSNApiSplTest, PromiseCapabilityRef_Reject) { LocalScope scope(vm_); CalculateForTime(); Local capability = PromiseCapabilityRef::New(vm_); Local promise = capability->GetPromise(vm_); Local resolve = FunctionRef::New(vm_, FunCallback); Local reject = FunctionRef::New(vm_, FunCallback); promise->Then(vm_, resolve, reject); Local value = NumberRef::New(vm_, 300.3); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)capability->Reject(vm_, value); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PromiseCapabilityRef::Reject); } HWTEST_F_L0(JSNApiSplTest, ArrayBufferRef_New) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 30; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)ArrayBufferRef::New(vm_, length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayBufferRef::New); } HWTEST_F_L0(JSNApiSplTest, ArrayBufferRef_New1) { static bool isFree = false; struct Data { int32_t length; }; const int32_t length = 15; Deleter deleter = [](void *buffer, void *data) -> void { delete[] reinterpret_cast(buffer); Data *currentData = reinterpret_cast(data); delete currentData; isFree = true; }; LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { isFree = false; uint8_t *buffer = new uint8_t[length](); Data *data = new Data(); data->length = length; (void)ArrayBufferRef::New(vm_, buffer, length, deleter, data); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayBufferRef::New); } HWTEST_F_L0(JSNApiSplTest, ArrayBufferRef_ByteLength) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 30; Local arrayBuffer = ArrayBufferRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)arrayBuffer->ByteLength(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayBufferRef::ByteLength); } HWTEST_F_L0(JSNApiSplTest, ArrayBufferRef_Detach) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 30; Local arrayBuffer = ArrayBufferRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)arrayBuffer->Detach(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayBufferRef::Detach); } HWTEST_F_L0(JSNApiSplTest, ArrayBufferRef_IsDetach) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 30; Local arrayBuffer = ArrayBufferRef::New(vm_, length); arrayBuffer->Detach(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)arrayBuffer->IsDetach(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayBufferRef::IsDetach); } HWTEST_F_L0(JSNApiSplTest, BufferRef_ByteLength) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 30; Local obj = BufferRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { obj->ByteLength(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayBufferRef::ByteLength); } HWTEST_F_L0(JSNApiSplTest, BufferRef_BufferRef) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 30; Local obj = BufferRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->GetBuffer(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BufferRef::BufferRef); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArgumentsObject) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSHandle obj = factory->NewJSArguments(); JSHandle argumentTag = JSHandle::Cast(obj); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(argumentTag)->IsArgumentsObject(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsArgumentsObject); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsAsyncFunction) { ObjectFactory *factory = vm_->GetFactory(); JSHandle asyncFuncObj = factory->NewJSAsyncFuncObject(); JSHandle argumentTag = JSHandle::Cast(asyncFuncObj); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(argumentTag)->IsAsyncFunction(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsAsyncFunction); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSLocale) { JSThread *thread = vm_->GetJSThread(); JSHandle jsLocale = JSHandle(thread, JSLocaleCreateWithOptionTest(thread)); JSHandle argumentTag = JSHandle::Cast(jsLocale); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(argumentTag)->IsJSLocale(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSLocale); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsDeque) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSThread *thread = vm_->GetJSThread(); JSHandle proto = thread->GetEcmaVM()->GetGlobalEnv()->GetFunctionPrototype(); JSHandle queueClass = factory->NewEcmaHClass(JSAPIDeque::SIZE, JSType::JS_API_DEQUE, proto); JSHandle jsQueue = JSHandle::Cast(factory->NewJSObjectWithInit(queueClass)); JSHandle newElements = factory->NewTaggedArray(JSAPIDeque::DEFAULT_CAPACITY_LENGTH); jsQueue->SetLength(thread, JSTaggedValue(0)); jsQueue->SetFront(0); jsQueue->SetTail(0); jsQueue->SetElements(thread, newElements); JSHandle deQue = JSHandle::Cast(jsQueue); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)JSNApiHelper::ToLocal(deQue)->IsDeque(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsDeque); } HWTEST_F_L0(JSNApiSplTest, DataView_New) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)DataViewRef::New(vm_, arrayBuffer, 5, 7); } gettimeofday(&g_endTime, nullptr); TEST_TIME(DataView::New); } HWTEST_F_L0(JSNApiSplTest, DataView_ByteLength) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); Local dataView = DataViewRef::New(vm_, arrayBuffer, 5, 7); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)dataView->ByteLength(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(DataView::ByteLength); } HWTEST_F_L0(JSNApiSplTest, DataView_ByteOffset) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); Local dataView = DataViewRef::New(vm_, arrayBuffer, 5, 7); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)dataView->ByteOffset(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(DataView::ByteOffset); } HWTEST_F_L0(JSNApiSplTest, DataView_GetArrayBuffer) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); Local dataView = DataViewRef::New(vm_, arrayBuffer, 5, 7); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)dataView->GetArrayBuffer(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(DataView::GetArrayBuffer); } HWTEST_F_L0(JSNApiSplTest, TypedArrayRef_ByteLength) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); Local obj = Int8ArrayRef::New(vm_, arrayBuffer, 5, 6); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->ByteLength(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(TypedArrayRef::ByteLength); } HWTEST_F_L0(JSNApiSplTest, TypedArrayRef_ByteOffset) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); Local obj = Int8ArrayRef::New(vm_, arrayBuffer, 5, 6); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->ByteOffset(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(TypedArrayRef::ByteOffset); } HWTEST_F_L0(JSNApiSplTest, TypedArrayRef_ArrayLength) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); Local obj = Int8ArrayRef::New(vm_, arrayBuffer, 5, 6); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->ArrayLength(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(TypedArrayRef::ArrayLength); } HWTEST_F_L0(JSNApiSplTest, TypedArrayRef_GetArrayBuffer) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); Local obj = Int8ArrayRef::New(vm_, arrayBuffer, 5, 6); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)obj->GetArrayBuffer(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(TypedArrayRef::GetArrayBuffer); } HWTEST_F_L0(JSNApiSplTest, Int8ArrayRef_New) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Int8ArrayRef::New(vm_, arrayBuffer, 5, 6); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Int8ArrayRef::New); } HWTEST_F_L0(JSNApiSplTest, Uint8ArrayRef_New) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Uint8ArrayRef::New(vm_, arrayBuffer, 5, 6); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Uint8ArrayRef::New); } HWTEST_F_L0(JSNApiSplTest, Uint8ClampedArrayRef_New) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Uint8ClampedArrayRef::New(vm_, arrayBuffer, 5, 6); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Uint8ClampedArrayRef::New); } HWTEST_F_L0(JSNApiSplTest, Int16ArrayRef_New) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Int16ArrayRef::New(vm_, arrayBuffer, 5, 6); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Int16ArrayRef::New); } HWTEST_F_L0(JSNApiSplTest, Uint16ArrayRef_New) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Uint16ArrayRef::New(vm_, arrayBuffer, 5, 6); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Uint16ArrayRef::New); } HWTEST_F_L0(JSNApiSplTest, Int32ArrayRef_New) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Int32ArrayRef::New(vm_, arrayBuffer, 5, 6); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Int32ArrayRef::New); } HWTEST_F_L0(JSNApiSplTest, Uint32ArrayRef_New) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 15; Local arrayBuffer = ArrayBufferRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Uint32ArrayRef::New(vm_, arrayBuffer, 5, 6); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Uint32ArrayRef::New); } HWTEST_F_L0(JSNApiSplTest, BufferRef_BufferToStringCallback) { LocalScope scope(vm_); CalculateForTime(); JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); JSHandle arrayBuffer = factory->NewJSArrayBuffer(10); JSHandle arryListTag = JSHandle::Cast(arrayBuffer); EcmaRuntimeCallInfo *objCallInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, arryListTag, undefined, 1); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { BufferRef::BufferToStringCallback(objCallInfo); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BufferRef::BufferToStringCallback); } JSHandle ConstructobjectHashMap(const EcmaVM *vm_) { JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle globalObject = env->GetJSGlobalObject(); JSHandle key(factory->NewFromASCII("ArkPrivate")); JSHandle value = JSObject::GetProperty(thread, JSHandle(globalObject), key).GetValue(); auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::HashMap))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); JSHandle map(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); return map; } JSHandle ConstructobjectHashSet(const EcmaVM *vm_) { JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle globalObject = env->GetJSGlobalObject(); JSHandle key(factory->NewFromASCII("ArkPrivate")); JSHandle value = JSObject::GetProperty(thread, JSHandle(globalObject), key).GetValue(); auto objCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); objCallInfo1->SetFunction(JSTaggedValue::Undefined()); objCallInfo1->SetThis(value.GetTaggedValue()); objCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::HashSet))); [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, objCallInfo1); JSTaggedValue result1 = containers::ContainersPrivate::Load(objCallInfo1); JSHandle newTarget(thread, result1); auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); objCallInfo->SetFunction(newTarget.GetTaggedValue()); objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); objCallInfo->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); JSTaggedValue result = ecmascript::containers::ContainersHashSet::HashSetConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle setHandle(thread, result); return setHandle; } JSHandle ConstructobjectLightWeightMap(const EcmaVM *vm_) { JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle globalObject = env->GetJSGlobalObject(); JSHandle key(factory->NewFromASCII("ArkPrivate")); JSHandle value = JSObject::GetProperty(thread, JSHandle(globalObject), key).GetValue(); auto objCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); objCallInfo1->SetFunction(JSTaggedValue::Undefined()); objCallInfo1->SetThis(value.GetTaggedValue()); objCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::LightWeightMap))); [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, objCallInfo1); JSTaggedValue result1 = ecmascript::containers::ContainersPrivate::Load(objCallInfo1); JSHandle newTarget(thread, result1); auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); objCallInfo->SetFunction(newTarget.GetTaggedValue()); objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); objCallInfo->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); JSTaggedValue result = ecmascript::containers::ContainersLightWeightMap::LightWeightMapConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle mapHandle(thread, result); return mapHandle; } JSHandle ConstructobjectLightWeightSet(const EcmaVM *vm_) { JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle globalObject = env->GetJSGlobalObject(); JSHandle key(factory->NewFromASCII("ArkPrivate")); JSHandle value = JSObject::GetProperty(thread, JSHandle(globalObject), key).GetValue(); auto objCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); objCallInfo1->SetFunction(JSTaggedValue::Undefined()); objCallInfo1->SetThis(value.GetTaggedValue()); objCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::LightWeightSet))); [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, objCallInfo1); JSTaggedValue result1 = ecmascript::containers::ContainersPrivate::Load(objCallInfo1); JSHandle newTarget(thread, result1); auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); objCallInfo->SetFunction(newTarget.GetTaggedValue()); objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); objCallInfo->SetThis(JSTaggedValue::Undefined()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); JSTaggedValue result = ecmascript::containers::ContainersLightWeightSet::LightWeightSetConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle mapHandle(thread, result); return mapHandle; } HWTEST_F_L0(JSNApiSplTest, IsStringIterator) { LocalScope scope(vm_); CalculateForTime(); JSHandle recordName = vm_->GetFactory()->NewFromUtf8("646458"); JSHandle jsStringIter = JSStringIterator::CreateStringIterator(vm_->GetJSThread(), recordName); JSHandle setTag = JSHandle::Cast(jsStringIter); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(setTag)->IsStringIterator(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsStringIterator); GTEST_LOG_(INFO) << std::boolalpha << JSNApiHelper::ToLocal(setTag)->IsStringIterator(); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsUint8Array) { LocalScope scope(vm_); CalculateForTime(); Local buffer = ArrayBufferRef::New(vm_, 5); Local object = Uint8ArrayRef::New(vm_, buffer, 4, 5); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsUint8Array(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsUint8Array); GTEST_LOG_(INFO) << std::boolalpha << object->IsUint8Array(); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt8Array) { LocalScope scope(vm_); CalculateForTime(); Local buffer = ArrayBufferRef::New(vm_, 5); Local object = Int8ArrayRef::New(vm_, buffer, 4, 5); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsInt8Array(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsInt8Array); GTEST_LOG_(INFO) << std::boolalpha << object->IsInt8Array(); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBigInt64Array) { LocalScope scope(vm_); CalculateForTime(); Local buffer = ArrayBufferRef::New(vm_, 5); Local object = BigInt64ArrayRef::New(vm_, buffer, 4, 5); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsBigInt64Array(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsBigInt64Array); GTEST_LOG_(INFO) << std::boolalpha << object->IsBigInt64Array(); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBigUint64Array) { LocalScope scope(vm_); CalculateForTime(); Local buffer = ArrayBufferRef::New(vm_, 5); Local object = BigUint64ArrayRef::New(vm_, buffer, 4, 5); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsBigUint64Array(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsBigUint64Array); GTEST_LOG_(INFO) << std::boolalpha << object->IsBigUint64Array(); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPrimitiveRef) { LocalScope scope(vm_); CalculateForTime(); auto factory = vm_->GetFactory(); int num = 0; Local intValue = IntegerRef::New(vm_, num); EXPECT_EQ(intValue->Value(), num); Local jsValue = intValue->GetValue(vm_); EXPECT_TRUE(*jsValue == nullptr); JSHandle nullHandle(thread_, JSTaggedValue::Null()); JSHandle jsClassHandle = factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_PRIMITIVE_REF, nullHandle); TaggedObject *taggedObject = factory->NewObject(jsClassHandle); JSHandle jsTaggedValue(thread_, JSTaggedValue(taggedObject)); Local jsValueRef = JSNApiHelper::ToLocal(jsTaggedValue); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { jsValueRef->IsJSPrimitiveRef(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSPrimitiveRef); GTEST_LOG_(INFO) << std::boolalpha << jsValueRef->IsJSPrimitiveRef(); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSDateTimeFormat) { LocalScope scope(vm_); CalculateForTime(); auto factory = vm_->GetFactory(); int num = 0; Local intValue = IntegerRef::New(vm_, num); EXPECT_EQ(intValue->Value(), num); Local jsValue = intValue->GetValue(vm_); EXPECT_TRUE(*jsValue == nullptr); JSHandle nullHandle(thread_, JSTaggedValue::Null()); JSHandle jsClassHandle = factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_DATE_TIME_FORMAT, nullHandle); TaggedObject *taggedObject = factory->NewObject(jsClassHandle); JSHandle jsTaggedValue(thread_, JSTaggedValue(taggedObject)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(jsTaggedValue)->IsJSDateTimeFormat(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSDateTimeFormat); GTEST_LOG_(INFO) << std::boolalpha << JSNApiHelper::ToLocal(jsTaggedValue)->IsJSDateTimeFormat(); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSRelativeTimeFormat) { LocalScope scope(vm_); CalculateForTime(); auto factory = vm_->GetFactory(); Local intValue = IntegerRef::New(vm_, 0); EXPECT_EQ(intValue->Value(), 0); Local jsValue = intValue->GetValue(vm_); EXPECT_TRUE(*jsValue == nullptr); JSHandle nullHandle(thread_, JSTaggedValue::Null()); JSHandle jsClassHandle = factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_RELATIVE_TIME_FORMAT, nullHandle); TaggedObject *taggedObject = factory->NewObject(jsClassHandle); JSHandle jsTaggedValue(thread_, JSTaggedValue(taggedObject)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(jsTaggedValue)->IsJSRelativeTimeFormat(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSRelativeTimeFormat); GTEST_LOG_(INFO) << std::boolalpha << JSNApiHelper::ToLocal(jsTaggedValue)->IsJSRelativeTimeFormat(); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSIntl) { LocalScope scope(vm_); CalculateForTime(); auto factory = vm_->GetFactory(); Local intValue = IntegerRef::New(vm_, 0); EXPECT_EQ(intValue->Value(), 0); Local jsValue = intValue->GetValue(vm_); EXPECT_TRUE(*jsValue == nullptr); JSHandle nullHandle(thread_, JSTaggedValue::Null()); JSHandle jsClassHandle = factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_INTL, nullHandle); TaggedObject *taggedObject = factory->NewObject(jsClassHandle); JSHandle jsTaggedValue(thread_, JSTaggedValue(taggedObject)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(jsTaggedValue)->IsJSIntl(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSIntl); GTEST_LOG_(INFO) << std::boolalpha << JSNApiHelper::ToLocal(jsTaggedValue)->IsJSIntl(); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSNumberFormat) { LocalScope scope(vm_); CalculateForTime(); auto factory = vm_->GetFactory(); Local intValue = IntegerRef::New(vm_, 0); EXPECT_EQ(intValue->Value(), 0); Local jsValue = intValue->GetValue(vm_); EXPECT_TRUE(*jsValue == nullptr); JSHandle nullHandle(thread_, JSTaggedValue::Null()); JSHandle jsClassHandle = factory->NewEcmaHClass(JSObject::SIZE, JSType::JS_NUMBER_FORMAT, nullHandle); TaggedObject *taggedObject = factory->NewObject(jsClassHandle); JSHandle jsTaggedValue(thread_, JSTaggedValue(taggedObject)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(jsTaggedValue)->IsJSNumberFormat(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSNumberFormat); GTEST_LOG_(INFO) << std::boolalpha << JSNApiHelper::ToLocal(jsTaggedValue)->IsJSNumberFormat(); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsHashMap) { LocalScope scope(vm_); CalculateForTime(); JSHandle map = ConstructobjectHashMap(vm_); JSHandle jsHashMap = JSHandle::Cast(map); Local tag = JSNApiHelper::ToLocal(jsHashMap); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(tag->IsHashMap()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsHashMap); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsHashSet) { LocalScope scope(vm_); CalculateForTime(); JSHandle setHandle = ConstructobjectHashSet(vm_); JSHandle jsHashMap = JSHandle::Cast(setHandle); Local tag = JSNApiHelper::ToLocal(jsHashMap); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(tag->IsHashSet()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsHashSet); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsLightWeightMap) { LocalScope scope(vm_); CalculateForTime(); JSHandle mapHandle = ConstructobjectLightWeightMap(vm_); JSHandle jsHashMap = JSHandle::Cast(mapHandle); Local tag = JSNApiHelper::ToLocal(jsHashMap); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(tag->IsLightWeightMap()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsLightWeightMap); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsLightWeightSet) { LocalScope scope(vm_); CalculateForTime(); JSHandle mapHandle = ConstructobjectLightWeightSet(vm_); JSHandle jsHashMap = JSHandle::Cast(mapHandle); Local tag = JSNApiHelper::ToLocal(jsHashMap); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(tag->IsLightWeightSet()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsLightWeightSet); } HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_Default) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object(value, true, true, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.Default(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::Default); } HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_PropertyAttribute) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { PropertyAttribute *p = new PropertyAttribute(); delete p; } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::PropertyAttribute); } HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_PropertyAttribute1) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { PropertyAttribute *p = new PropertyAttribute(value, true, true, true); delete p; } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::PropertyAttribute); } HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_IsWritable) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object(value, true, true, true); ASSERT_EQ(true, object.IsWritable()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = object.IsWritable(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::IsWritable); } HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_SetWritable) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object(value, false, true, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.SetWritable(true); bool b = object.IsWritable(); bool b1 = object.HasWritable(); UNUSED(b); UNUSED(b1); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::SetWritable); } HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_IsEnumerable) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object(value, true, true, true); ASSERT_EQ(true, object.IsEnumerable()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = object.IsEnumerable(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::IsEnumerable); } HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_SetEnumerable) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object(value, true, false, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.SetEnumerable(true); bool b = object.IsEnumerable(); bool b1 = object.HasEnumerable(); UNUSED(b); UNUSED(b1); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::SetEnumerable); } HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_IsConfigurable) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object(value, true, true, true); ASSERT_EQ(true, object.IsConfigurable()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = object.IsConfigurable(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::IsConfigurable); } HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_SetConfigurable) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object(value, true, true, false); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.SetConfigurable(true); bool b = object.IsConfigurable(); bool b1 = object.HasConfigurable(); UNUSED(b); UNUSED(b1); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::SetConfigurable); } HWTEST_F_L0(JSNApiSplTest, HasWritable_True) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object(value, true, true, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = object.HasWritable(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::HasWritable); } HWTEST_F_L0(JSNApiSplTest, HasConfigurable_False) { LocalScope scope(vm_); CalculateForTime(); Local obj; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = obj->HasConfigurable(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::HasConfigurable); } HWTEST_F_L0(JSNApiSplTest, HasEnumerable_True) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object(value, true, true, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = object.HasEnumerable(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::HasEnumerable); } HWTEST_F_L0(JSNApiSplTest, GetValue) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object(value, true, true, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.GetValue(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::GetValue); } HWTEST_F_L0(JSNApiSplTest, SetValue) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.SetValue(value); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::SetValue); } HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_HasValue) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object(value, true, true, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)object.HasValue(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::HasValue); } HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_SetGetter) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.SetGetter(value); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::SetGetter); } HWTEST_F_L0(JSNApiSplTest, PropertyAttribute_GetGetter) { LocalScope scope(vm_); CalculateForTime(); Local value = BooleanRef::New(vm_, true); PropertyAttribute object; object.SetGetter(value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)object.GetGetter(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::GetGetter); } HWTEST_F_L0(JSNApiSplTest, HasGetter) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object; object.SetGetter(value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.HasGetter(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::HasGetter); } HWTEST_F_L0(JSNApiSplTest, SetSetter) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.SetSetter(value); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::SetSetter); } HWTEST_F_L0(JSNApiSplTest, GetSetter) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object; object.SetSetter(value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.GetSetter(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::GetSetter); } HWTEST_F_L0(JSNApiSplTest, HasSetter) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); PropertyAttribute object; object.SetGetter(value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.HasSetter(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PropertyAttribute::HasSetter); } HWTEST_F_L0(JSNApiSplTest, Float32ArrayRef_New) { LocalScope scope(vm_); CalculateForTime(); int32_t num = 4; Local buffer = ArrayBufferRef::New(vm_, num); int32_t byteOffset = 4; int32_t length = 20; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Float32ArrayRef::New(vm_, buffer, byteOffset, length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Float32ArrayRef::New); } HWTEST_F_L0(JSNApiSplTest, Float64ArrayRef_New) { LocalScope scope(vm_); CalculateForTime(); int32_t num = 4; Local buffer = ArrayBufferRef::New(vm_, num); int32_t byteOffset = 4; int32_t length = 20; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Float64ArrayRef::New(vm_, buffer, byteOffset, length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Float64ArrayRef::New); } HWTEST_F_L0(JSNApiSplTest, BigInt64ArrayRef_New) { LocalScope scope(vm_); CalculateForTime(); int32_t num = 4; Local buffer = ArrayBufferRef::New(vm_, num); int32_t byteOffset = 4; int32_t length = 20; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { BigInt64ArrayRef::New(vm_, buffer, byteOffset, length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BigInt64ArrayRef::New); } HWTEST_F_L0(JSNApiSplTest, BigUint64ArrayRef_New) { LocalScope scope(vm_); CalculateForTime(); int32_t num = 4; Local buffer = ArrayBufferRef::New(vm_, num); int32_t byteOffset = 4; int32_t length = 20; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { BigUint64ArrayRef::New(vm_, buffer, byteOffset, length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BigUint64ArrayRef::New); } HWTEST_F_L0(JSNApiSplTest, GetOriginalSource) { LocalScope scope(vm_); CalculateForTime(); JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = vm_->GetFactory(); auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetObjectFunctionPrototype(); JSHandle jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto); JSHandle jSRegExp = JSHandle::Cast(factory->NewJSObject(jSRegExpClass)); jSRegExp->SetByteCodeBuffer(thread, JSTaggedValue::Undefined()); jSRegExp->SetOriginalSource(thread, JSTaggedValue::Undefined()); jSRegExp->SetGroupName(thread, JSTaggedValue::Undefined()); jSRegExp->SetOriginalFlags(thread, JSTaggedValue(0)); jSRegExp->SetLength(0); JSHandle jsRegTag = JSHandle::Cast(jSRegExp); Local object = JSNApiHelper::ToLocal(jsRegTag); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetOriginalSource(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(RegExpRef::GetOriginalSource); } HWTEST_F_L0(JSNApiSplTest, GetOriginalFlags) { LocalScope scope(vm_); CalculateForTime(); JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = vm_->GetFactory(); auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetObjectFunctionPrototype(); JSHandle jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto); JSHandle jSRegExp = JSHandle::Cast(factory->NewJSObject(jSRegExpClass)); jSRegExp->SetByteCodeBuffer(thread, JSTaggedValue::Undefined()); jSRegExp->SetOriginalSource(thread, JSTaggedValue::Undefined()); jSRegExp->SetGroupName(thread, JSTaggedValue::Undefined()); jSRegExp->SetOriginalFlags(thread, JSTaggedValue(0)); jSRegExp->SetLength(0); JSHandle jsRegTag = JSHandle::Cast(jSRegExp); Local object = JSNApiHelper::ToLocal(jsRegTag); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetOriginalFlags(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(RegExpRef::GetOriginalFlags); } HWTEST_F_L0(JSNApiSplTest, IsGlobal) { LocalScope scope(vm_); CalculateForTime(); JSThread *thread = vm_->GetJSThread(); auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetObjectFunctionPrototype(); JSHandle globalObject = JSHandle::Cast(proto); JSHandle jsRegTag = JSHandle::Cast(globalObject); Local object = JSNApiHelper::ToLocal(jsRegTag); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsGlobal(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(RegExpRef::IsGlobal); } HWTEST_F_L0(JSNApiSplTest, IsIgnoreCase) { LocalScope scope(vm_); CalculateForTime(); JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = vm_->GetFactory(); auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetObjectFunctionPrototype(); JSHandle jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto); JSHandle jSRegExp = JSHandle::Cast(factory->NewJSObject(jSRegExpClass)); JSHandle jsRegTag = JSHandle::Cast(jSRegExp); Local object = JSNApiHelper::ToLocal(jsRegTag); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsIgnoreCase(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(RegExpRef::IsIgnoreCase); } HWTEST_F_L0(JSNApiSplTest, IsMultiline) { LocalScope scope(vm_); CalculateForTime(); JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = vm_->GetFactory(); auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetObjectFunctionPrototype(); JSHandle jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto); JSHandle jSRegExp = JSHandle::Cast(factory->NewJSObject(jSRegExpClass)); JSHandle jsRegTag = JSHandle::Cast(jSRegExp); Local object = JSNApiHelper::ToLocal(jsRegTag); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsMultiline(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(RegExpRef::IsMultiline); } HWTEST_F_L0(JSNApiSplTest, IsDotAll) { LocalScope scope(vm_); CalculateForTime(); JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = vm_->GetFactory(); auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetObjectFunctionPrototype(); JSHandle jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto); JSHandle jSRegExp = JSHandle::Cast(factory->NewJSObject(jSRegExpClass)); JSHandle jsregtag = JSHandle::Cast(jSRegExp); Local object = JSNApiHelper::ToLocal(jsregtag); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsDotAll(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(RegExpRef::IsDotAll); } HWTEST_F_L0(JSNApiSplTest, IsUtf16) { LocalScope scope(vm_); CalculateForTime(); JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = vm_->GetFactory(); auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetObjectFunctionPrototype(); JSHandle jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto); JSHandle jSRegExp = JSHandle::Cast(factory->NewJSObject(jSRegExpClass)); JSHandle jsregtag = JSHandle::Cast(jSRegExp); Local object = JSNApiHelper::ToLocal(jsregtag); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsUtf16(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(RegExpRef::IsUtf16); } HWTEST_F_L0(JSNApiSplTest, IsStick) { LocalScope scope(vm_); CalculateForTime(); JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = vm_->GetFactory(); auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetObjectFunctionPrototype(); JSHandle jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto); JSHandle jSRegExp = JSHandle::Cast(factory->NewJSObject(jSRegExpClass)); JSHandle jsregtag = JSHandle::Cast(jSRegExp); Local object = JSNApiHelper::ToLocal(jsregtag); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsStick(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(RegExpRef::IsStick); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_BooleaValue_True) { LocalScope scope(vm_); CalculateForTime(); Local tag = JSValueRef::True(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->BooleaValue(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_BooleaValue_true); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_BooleaValue_False) { LocalScope scope(vm_); CalculateForTime(); Local tag = JSValueRef::False(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->BooleaValue(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_BooleaValue_false); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IntegerValue_Int64) { LocalScope scope(vm_); CalculateForTime(); int64_t num = 0xffffffffffff; // 0xffffffffffff = A number exceeding 32 bits Local targetInt = NumberRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { int64_t i64 = targetInt->IntegerValue(vm_); UNUSED(i64); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IntegerValue_Int64); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IntegerValue_Double) { LocalScope scope(vm_); CalculateForTime(); double num = 123.456; // 123.456 = random number Local targetInt = NumberRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { int64_t i64 = targetInt->IntegerValue(vm_); UNUSED(i64); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IntegerValue_Double); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IntegerValue_Int) { LocalScope scope(vm_); CalculateForTime(); int num = 789; // 789 = random number Local targetInt = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { int64_t i64 = targetInt->IntegerValue(vm_); UNUSED(i64); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IntegerValue_Int); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_Uint32Value) { LocalScope scope(vm_); CalculateForTime(); unsigned int num = 456; // 456 = random number Local targetUInt = IntegerRef::NewFromUnsigned(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { uint32_t ui = targetUInt->Uint32Value(vm_); UNUSED(ui); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_Uint32Value); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToNativePointer_String) { LocalScope scope(vm_); CalculateForTime(); void *vp1 = static_cast(new std::string("test1")); Local tag = NativePointerRef::New(vm_, vp1); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local npr = tag->ToNativePointer(vm_); UNUSED(npr); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_ToNativePointer_String); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToNativePointer_Int) { LocalScope scope(vm_); CalculateForTime(); void *vp1 = static_cast(new int(123)); // 123 = random number Local tag = NativePointerRef::New(vm_, vp1); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local npr = tag->ToNativePointer(vm_); UNUSED(npr); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_ToNativePointer_Int); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToNativePointer_Double) { LocalScope scope(vm_); CalculateForTime(); void *vp1 = static_cast(new double(123.456)); // 123.456 = random number Local tag = NativePointerRef::New(vm_, vp1); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local npr = tag->ToNativePointer(vm_); UNUSED(npr); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_ToNativePointer_Double); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToNativePointer_Char) { LocalScope scope(vm_); CalculateForTime(); void *vp1 = static_cast(new char('a')); Local tag = NativePointerRef::New(vm_, vp1); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local npr = tag->ToNativePointer(vm_); UNUSED(npr); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_ToNativePointer_Char); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToNativePointer_Long) { LocalScope scope(vm_); CalculateForTime(); void *vp1 = static_cast(new long(123456)); // 123456 = random number Local tag = NativePointerRef::New(vm_, vp1); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local npr = tag->ToNativePointer(vm_); UNUSED(npr); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_ToNativePointer_Long); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsUndefined_False) { LocalScope scope(vm_); CalculateForTime(); int num = 123; // 123 = random number Local tag = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsUndefined(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsUndefined_False); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsUndefined_True) { LocalScope scope(vm_); CalculateForTime(); Local tag = JSValueRef::Undefined(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsUndefined(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsUndefined_True); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsNull_False) { LocalScope scope(vm_); CalculateForTime(); int num = 123; // 123 = random number Local tag = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsNull(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsNull_False); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsNull_True) { LocalScope scope(vm_); CalculateForTime(); Local tag = JSValueRef::Null(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsNull(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsNull_True); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_WithinInt32_False) { LocalScope scope(vm_); CalculateForTime(); Local tag = StringRef::NewFromUtf8(vm_, "abcd"); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->WithinInt32(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_WithinInt32_False); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_WithinInt32_True) { LocalScope scope(vm_); CalculateForTime(); int num = 456; // 456 = random number Local tag = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->WithinInt32(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_WithinInt32_True); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBoolean_False) { LocalScope scope(vm_); CalculateForTime(); int num = 123; // 123 = random number Local tag = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsBoolean(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsBoolean_False); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBoolean_True) { LocalScope scope(vm_); CalculateForTime(); Local tag = BooleanRef::New(vm_, false); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsBoolean(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsBoolean_True); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsString_False) { LocalScope scope(vm_); CalculateForTime(); Local tag = BooleanRef::New(vm_, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsString(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsString_False); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsString_True) { LocalScope scope(vm_); CalculateForTime(); Local tag = StringRef::NewFromUtf8(vm_, "abc"); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsString(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsString_True); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsProxy_False) { LocalScope scope(vm_); CalculateForTime(); Local tag = BooleanRef::New(vm_, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsProxy(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsProxy_False); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsProxy_True) { LocalScope scope(vm_); CalculateForTime(); Local tag = ProxyRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsProxy(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsProxy_True); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsPromise_False) { LocalScope scope(vm_); CalculateForTime(); Local tag = BooleanRef::New(vm_, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsPromise(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsPromise_False); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsPromise_True) { LocalScope scope(vm_); CalculateForTime(); Local tag = PromiseCapabilityRef::New(vm_)->GetPromise(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsPromise(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsPromise_True); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsDataView_False) { LocalScope scope(vm_); CalculateForTime(); Local tag = BooleanRef::New(vm_, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsDataView(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsDataView_False); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsDataView_True) { LocalScope scope(vm_); CalculateForTime(); int num = 0; // 0 = random number Local tag = DataViewRef::New(vm_, ArrayBufferRef::New(vm_, num), num, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsDataView(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsDataView_True); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsWeakRef_False) { LocalScope scope(vm_); CalculateForTime(); Local tag = BooleanRef::New(vm_, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsWeakRef(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsWeakRef_False); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsWeakMap_False) { LocalScope scope(vm_); CalculateForTime(); Local tag = BooleanRef::New(vm_, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsWeakMap(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsWeakMap_False); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsWeakMap_True) { LocalScope scope(vm_); CalculateForTime(); Local tag = WeakMapRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsWeakMap(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsWeakMap_True); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsWeakSet_False) { LocalScope scope(vm_); CalculateForTime(); Local tag = JSValueRef::Null(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsWeakSet(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsWeakSet_False); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsWeakSet_True) { LocalScope scope(vm_); CalculateForTime(); Local tag = WeakSetRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = tag->IsWeakSet(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef_IsWeakSet_True); } HWTEST_F_L0(JSNApiSplTest, Global_Global) { LocalScope scope(vm_); CalculateForTime(); Global param; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Global global(param); UNUSED(global); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_Global); } HWTEST_F_L0(JSNApiSplTest, Global_OperatorEqual) { LocalScope scope(vm_); CalculateForTime(); Global param; Global global; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { global = param; } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_OperatorEqual); } HWTEST_F_L0(JSNApiSplTest, Global_GlobalMove) { LocalScope scope(vm_); CalculateForTime(); Global param; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Global global(std::move(param)); UNUSED(global); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_GlobalMove); } HWTEST_F_L0(JSNApiSplTest, Global_OperatorEqualMove) { LocalScope scope(vm_); CalculateForTime(); Global param; Global global; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { global = std::move(param); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_OperatorEqualMove); } HWTEST_F_L0(JSNApiSplTest, Global_Global_VM_Local) { LocalScope scope(vm_); CalculateForTime(); Local current = BooleanRef::New(vm_, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Global global(vm_, current); UNUSED(global); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_Global_VM_Local); } HWTEST_F_L0(JSNApiSplTest, Global_Global_VM_Global) { LocalScope scope(vm_); CalculateForTime(); Global current(vm_, BooleanRef::New(vm_, true)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Global global(vm_, current); UNUSED(global); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_Global_VM_Global); } HWTEST_F_L0(JSNApiSplTest, Global_ToLocal) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local local = global.ToLocal(); UNUSED(local); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_ToLocal); } HWTEST_F_L0(JSNApiSplTest, Global_ToLocal_VM) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local local = global.ToLocal(vm_); UNUSED(local); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_ToLocal_VM); } HWTEST_F_L0(JSNApiSplTest, Global_Empty) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { global.Empty(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_Empty); } HWTEST_F_L0(JSNApiSplTest, Global_FreeGlobalHandleAddr) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { global.FreeGlobalHandleAddr(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_FreeGlobalHandleAddr); } HWTEST_F_L0(JSNApiSplTest, Global_OperatorStar) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = (*global)->BooleaValue(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_OperatorStar); } HWTEST_F_L0(JSNApiSplTest, Global_OperatorPointTo) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = global->BooleaValue(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_OperatorPointTo); } HWTEST_F_L0(JSNApiSplTest, Global_IsEmpty_True) { LocalScope scope(vm_); CalculateForTime(); Global global; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = global.IsEmpty(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_IsEmpty_True); } HWTEST_F_L0(JSNApiSplTest, Global_IsEmpty_False) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = global.IsEmpty(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_IsEmpty_False); } HWTEST_F_L0(JSNApiSplTest, Global_SetWeak) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { global.SetWeak(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_SetWeak); } HWTEST_F_L0(JSNApiSplTest, Global_SetWeakCallback_Int) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); void *ref = new int(123); // 123 = random number WeakRefClearCallBack freeGlobalCallBack = FreeGlobalCallBack; WeakRefClearCallBack nativeFinalizeCallback = NativeFinalizeCallback; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { global.SetWeakCallback(ref, freeGlobalCallBack, nativeFinalizeCallback); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_SetWeakCallback_Int); } HWTEST_F_L0(JSNApiSplTest, Global_SetWeakCallback_String) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); void *ref = new std::string("abc"); WeakRefClearCallBack freeGlobalCallBack = FreeGlobalCallBack; WeakRefClearCallBack nativeFinalizeCallback = NativeFinalizeCallback; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { global.SetWeakCallback(ref, freeGlobalCallBack, nativeFinalizeCallback); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_SetWeakCallback_String); } HWTEST_F_L0(JSNApiSplTest, Global_SetWeakCallback_Double) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); void *ref = new double(123.456); // 123.456 = random number WeakRefClearCallBack freeGlobalCallBack = FreeGlobalCallBack; WeakRefClearCallBack nativeFinalizeCallback = NativeFinalizeCallback; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { global.SetWeakCallback(ref, freeGlobalCallBack, nativeFinalizeCallback); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_SetWeakCallback_Double); } HWTEST_F_L0(JSNApiSplTest, Global_SetWeakCallback_Char) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); void *ref = new char('a'); WeakRefClearCallBack freeGlobalCallBack = FreeGlobalCallBack; WeakRefClearCallBack nativeFinalizeCallback = NativeFinalizeCallback; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { global.SetWeakCallback(ref, freeGlobalCallBack, nativeFinalizeCallback); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_SetWeakCallback_Char); } HWTEST_F_L0(JSNApiSplTest, Global_SetWeakCallback_Long) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); void *ref = new long(123456); // 123456 = random number WeakRefClearCallBack freeGlobalCallBack = FreeGlobalCallBack; WeakRefClearCallBack nativeFinalizeCallback = NativeFinalizeCallback; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { global.SetWeakCallback(ref, freeGlobalCallBack, nativeFinalizeCallback); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_SetWeakCallback_Long); } HWTEST_F_L0(JSNApiSplTest, Global_ClearWeak) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { global.ClearWeak(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_ClearWeak); } HWTEST_F_L0(JSNApiSplTest, Global_IsWeak_False) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = global.IsWeak(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_IsWeak_False); } HWTEST_F_L0(JSNApiSplTest, Global_IsWeak_True) { LocalScope scope(vm_); CalculateForTime(); Global global(vm_, BooleanRef::New(vm_, true)); global.SetWeak(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = global.IsWeak(); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Global_IsWeak_True); } HWTEST_F_L0(JSNApiSplTest, StringRef_Cast) { LocalScope scope(vm_); CalculateForTime(); Local local = StringRef::NewFromUtf8(vm_, "abcdefbb"); JSValueRef *jsValue = (*local); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { StringRef *str = StringRef::Cast(jsValue); UNUSED(str); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_Cast); } HWTEST_F_L0(JSNApiSplTest, StringRef_NewFromUtf8) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local local = StringRef::NewFromUtf8(vm_, "abcdefbb"); UNUSED(local); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_NewFromUtf8); } HWTEST_F_L0(JSNApiSplTest, StringRef_NewFromUtf8_0) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local local = StringRef::NewFromUtf8(vm_, "abcdefbb", 0); UNUSED(local); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_NewFromUtf8_0); } HWTEST_F_L0(JSNApiSplTest, StringRef_NewFromUtf8_3) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local local = StringRef::NewFromUtf8(vm_, "abcdefbb", 3); UNUSED(local); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_NewFromUtf8_3); } HWTEST_F_L0(JSNApiSplTest, StringRef_NewFromUtf16) { LocalScope scope(vm_); CalculateForTime(); const char16_t *utf16 = u"您好,华为!"; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local local = StringRef::NewFromUtf16(vm_, utf16); UNUSED(local); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_NewFromUtf16); } HWTEST_F_L0(JSNApiSplTest, StringRef_NewFromUtf16_0) { LocalScope scope(vm_); CalculateForTime(); const char16_t *utf16 = u"您好,华为!"; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local local = StringRef::NewFromUtf16(vm_, utf16, 0); UNUSED(local); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_NewFromUtf16_0); } HWTEST_F_L0(JSNApiSplTest, StringRef_NewFromUtf16_3) { LocalScope scope(vm_); CalculateForTime(); const char16_t *utf16 = u"您好,华为!"; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local local = StringRef::NewFromUtf16(vm_, utf16, 3); UNUSED(local); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_NewFromUtf16_3); } HWTEST_F_L0(JSNApiSplTest, StringRef_ToString) { LocalScope scope(vm_); CalculateForTime(); Local local = StringRef::NewFromUtf8(vm_, "abcdefbb"); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { std::string str = local->ToString(); UNUSED(str); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_ToString); } HWTEST_F_L0(JSNApiSplTest, StringRef_Length) { LocalScope scope(vm_); CalculateForTime(); Local local = StringRef::NewFromUtf8(vm_, "abcdefbb"); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { uint32_t length = local->Length(); UNUSED(length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_Length); } HWTEST_F_L0(JSNApiSplTest, StringRef_Utf8Length) { LocalScope scope(vm_); CalculateForTime(); Local local = StringRef::NewFromUtf8(vm_, "abcdefbb"); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { uint32_t length = local->Utf8Length(vm_); UNUSED(length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_Utf8Length); } HWTEST_F_L0(JSNApiSplTest, StringRef_WriteUtf8) { LocalScope scope(vm_); CalculateForTime(); Local local = StringRef::NewFromUtf8(vm_, "abcdefbb"); char cs[16] = {0}; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { int length = local->WriteUtf8(cs, 6); UNUSED(length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_WriteUtf8); } HWTEST_F_L0(JSNApiSplTest, StringRef_WriteUtf8_all) { LocalScope scope(vm_); CalculateForTime(); Local local = StringRef::NewFromUtf8(vm_, "abcdefbb"); char cs[16] = {0}; // 16 = The size of the character array gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { int length = local->WriteUtf8(cs, local->Length()); UNUSED(length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_WriteUtf8_all); } HWTEST_F_L0(JSNApiSplTest, StringRef_WriteUtf8_0) { LocalScope scope(vm_); CalculateForTime(); Local local = StringRef::NewFromUtf8(vm_, "abcdefbb"); char cs[16] = {0}; // 16 = The size of the character array gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { int length = local->WriteUtf8(cs, 0); UNUSED(length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_WriteUtf8_0); } HWTEST_F_L0(JSNApiSplTest, StringRef_WriteUtf8_true) { LocalScope scope(vm_); CalculateForTime(); Local local = StringRef::NewFromUtf8(vm_, "abcdefbb"); char cs[16] = {0}; // 16 =The size of the character array gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { int length = local->WriteUtf8(cs, 6, true); UNUSED(length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_WriteUtf8_true); } HWTEST_F_L0(JSNApiSplTest, StringRef_WriteUtf8_all_true) { LocalScope scope(vm_); CalculateForTime(); Local local = StringRef::NewFromUtf8(vm_, "abcdefbb"); char cs[16] = {0}; // 16 = The size of the character array gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { int length = local->WriteUtf8(cs, local->Length(), true); UNUSED(length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_WriteUtf8_all_true); } HWTEST_F_L0(JSNApiSplTest, StringRef_WriteUtf16) { LocalScope scope(vm_); CalculateForTime(); Local local = StringRef::NewFromUtf16(vm_, u"您好,华为!"); char16_t cs[16] = {0}; // 16 = The size of the character array gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { int length = local->WriteUtf16(cs, 3); UNUSED(length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_WriteUtf16); } HWTEST_F_L0(JSNApiSplTest, StringRef_WriteLatin1) { LocalScope scope(vm_); CalculateForTime(); Local local = StringRef::NewFromUtf8(vm_, "abcdefbb"); char cs[16] = {0}; // 16 = The size of the character array gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { int length = local->WriteLatin1(cs, 8); UNUSED(length); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_WriteLatin1); } HWTEST_F_L0(JSNApiSplTest, StringRef_GetNapiWrapperString) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local local = StringRef::GetNapiWrapperString(vm_); UNUSED(local); } gettimeofday(&g_endTime, nullptr); TEST_TIME(StringRef_GetNapiWrapperString); } HWTEST_F_L0(JSNApiSplTest, JSNApi_IsMixedDebugEnabled) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bool b = JSNApi::IsMixedDebugEnabled(vm_); UNUSED(b); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_IsMixedDebugEnabled); } HWTEST_F_L0(JSNApiSplTest, JSNApi_NotifyNativeCalling_Int) { LocalScope scope(vm_); CalculateForTime(); void *par = new int(0); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::NotifyNativeCalling(vm_, par); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_NotifyNativeCalling_Int); } HWTEST_F_L0(JSNApiSplTest, JSNApi_NotifyNativeCalling_String) { LocalScope scope(vm_); CalculateForTime(); void *par = new std::string("abc"); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::NotifyNativeCalling(vm_, par); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_NotifyNativeCalling_String); } HWTEST_F_L0(JSNApiSplTest, JSNApi_NotifyNativeCalling_Char) { LocalScope scope(vm_); CalculateForTime(); void *par = new char('a'); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::NotifyNativeCalling(vm_, par); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_NotifyNativeCalling_Char); } HWTEST_F_L0(JSNApiSplTest, JSNApi_NotifyNativeCalling_Long) { LocalScope scope(vm_); CalculateForTime(); void *par = new long(123456); // 123456 = random number gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::NotifyNativeCalling(vm_, par); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_NotifyNativeCalling_Long); } HWTEST_F_L0(JSNApiSplTest, JSNApi_NotifyNativeCalling_Nullptr) { LocalScope scope(vm_); CalculateForTime(); void *par = nullptr; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::NotifyNativeCalling(vm_, par); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_NotifyNativeCalling_Nullptr); } HWTEST_F_L0(JSNApiSplTest, JSNApi_SerializeValue_Bool) { LocalScope scope(vm_); CalculateForTime(); Local value = BooleanRef::New(vm_, true); Local transfer = JSValueRef::Undefined(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *ptr = JSNApi::SerializeValue(vm_, value, transfer, JSValueRef::Undefined(vm_)); UNUSED(ptr); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_SerializeValue_Bool); } HWTEST_F_L0(JSNApiSplTest, JSNApi_SerializeValue_Int) { LocalScope scope(vm_); CalculateForTime(); int num = 123; // 123 = random number Local value = IntegerRef::New(vm_, num); Local transfer = JSValueRef::Undefined(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *ptr = JSNApi::SerializeValue(vm_, value, transfer, JSValueRef::Undefined(vm_)); UNUSED(ptr); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_SerializeValue_Int); } HWTEST_F_L0(JSNApiSplTest, JSNApi_SerializeValue_String) { LocalScope scope(vm_); CalculateForTime(); Local value = StringRef::NewFromUtf8(vm_, "abcdefbb"); Local transfer = JSValueRef::Undefined(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *ptr = JSNApi::SerializeValue(vm_, value, transfer, JSValueRef::Undefined(vm_)); UNUSED(ptr); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_SerializeValue_String); } HWTEST_F_L0(JSNApiSplTest, JSNApi_SerializeValue_String2) { LocalScope scope(vm_); CalculateForTime(); Local value = StringRef::NewFromUtf8(vm_, "abcdefbb"); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *ptr = JSNApi::SerializeValue(vm_, value, JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_), true); UNUSED(ptr); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_SerializeValue_String2); } HWTEST_F_L0(JSNApiSplTest, JSNApi_SerializeValue_String3) { LocalScope scope(vm_); CalculateForTime(); Local value = StringRef::NewFromUtf8(vm_, "abcdefbb"); Local transfer = JSValueRef::Undefined(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *ptr = JSNApi::SerializeValue(vm_, value, transfer, JSValueRef::Undefined(vm_)); UNUSED(ptr); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_SerializeValue_String3); } HWTEST_F_L0(JSNApiSplTest, JSNApi_SerializeValue_String_Bool) { LocalScope scope(vm_); CalculateForTime(); Local value = StringRef::NewFromUtf8(vm_, "abcdefbb"); Local transfer = JSValueRef::Undefined(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *ptr = JSNApi::SerializeValue(vm_, value, transfer, JSValueRef::Undefined(vm_)); UNUSED(ptr); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_SerializeValue_String_Bool); } HWTEST_F_L0(JSNApiSplTest, JSNApi_DeserializeValue_String) { LocalScope scope(vm_); CalculateForTime(); EcmaVM *vm2 = JSNApi::CreateJSVM(RuntimeOption()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *recoder = JSNApi::SerializeValue(vm_, StringRef::NewFromUtf8(vm_, "abcdefbb"), JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_)); void *hint = nullptr; Local local = JSNApi::DeserializeValue(vm2, recoder, hint); UNUSED(local); } gettimeofday(&g_endTime, nullptr); JSNApi::DestroyJSVM(vm2); TEST_TIME(JSNApi_DeserializeValue_String); } HWTEST_F_L0(JSNApiSplTest, JSNApi_DeserializeValue_Bool) { LocalScope scope(vm_); CalculateForTime(); EcmaVM *vm2 = JSNApi::CreateJSVM(RuntimeOption()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *recoder = JSNApi::SerializeValue(vm_, BooleanRef::New(vm_, true), JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_)); void *hint = nullptr; Local local = JSNApi::DeserializeValue(vm2, recoder, hint); UNUSED(local); } gettimeofday(&g_endTime, nullptr); JSNApi::DestroyJSVM(vm2); TEST_TIME(JSNApi_DeserializeValue_Bool); } HWTEST_F_L0(JSNApiSplTest, JSNApi_DeserializeValue_Int) { LocalScope scope(vm_); CalculateForTime(); EcmaVM *vm2 = JSNApi::CreateJSVM(RuntimeOption()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *recoder = JSNApi::SerializeValue(vm_, IntegerRef::New(vm_, 123), JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_)); void *hint = nullptr; Local local = JSNApi::DeserializeValue(vm2, recoder, hint); UNUSED(local); } gettimeofday(&g_endTime, nullptr); JSNApi::DestroyJSVM(vm2); TEST_TIME(JSNApi_DeserializeValue_Int); } HWTEST_F_L0(JSNApiSplTest, JSNApi_DeserializeValue_Undefined) { LocalScope scope(vm_); CalculateForTime(); EcmaVM *vm2 = JSNApi::CreateJSVM(RuntimeOption()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *recoder = JSNApi::SerializeValue(vm_, JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_)); void *hint = nullptr; Local local = JSNApi::DeserializeValue(vm2, recoder, hint); UNUSED(local); } gettimeofday(&g_endTime, nullptr); JSNApi::DestroyJSVM(vm2); TEST_TIME(JSNApi_DeserializeValue_Undefined); } HWTEST_F_L0(JSNApiSplTest, JSNApi_DeserializeValue_Null) { LocalScope scope(vm_); CalculateForTime(); EcmaVM *vm2 = JSNApi::CreateJSVM(RuntimeOption()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *recoder = JSNApi::SerializeValue(vm_, JSValueRef::Null(vm_), JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_)); void *hint = nullptr; Local local = JSNApi::DeserializeValue(vm2, recoder, hint); UNUSED(local); } gettimeofday(&g_endTime, nullptr); JSNApi::DestroyJSVM(vm2); TEST_TIME(JSNApi_DeserializeValue_Null); } HWTEST_F_L0(JSNApiSplTest, JSNApi_DeleteSerializationData_String) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *data = JSNApi::SerializeValue(vm_, StringRef::NewFromUtf8(vm_, "abcdefbb"), StringRef::NewFromUtf8(vm_, "abcdefbb"), JSValueRef::Undefined(vm_)); JSNApi::DeleteSerializationData(data); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_DeleteSerializationData_String); } HWTEST_F_L0(JSNApiSplTest, JSNApi_DeleteSerializationData_Bool) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *data = JSNApi::SerializeValue(vm_, BooleanRef::New(vm_, true), JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_)); JSNApi::DeleteSerializationData(data); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_DeleteSerializationData_Bool); } HWTEST_F_L0(JSNApiSplTest, JSNApi_DeleteSerializationData_Int) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *data = JSNApi::SerializeValue(vm_, BooleanRef::New(vm_, true), JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_)); JSNApi::DeleteSerializationData(data); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_DeleteSerializationData_Int); } HWTEST_F_L0(JSNApiSplTest, JSNApi_DeleteSerializationData_Undefined) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *data = JSNApi::SerializeValue(vm_, JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_)); JSNApi::DeleteSerializationData(data); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_DeleteSerializationData_Undefined); } HWTEST_F_L0(JSNApiSplTest, JSNApi_DeleteSerializationData_Null) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { void *data = JSNApi::SerializeValue(vm_, JSValueRef::Null(vm_), JSValueRef::Undefined(vm_), JSValueRef::Undefined(vm_)); JSNApi::DeleteSerializationData(data); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_DeleteSerializationData_Null); } HWTEST_F_L0(JSNApiSplTest, JSNApi_SetHostPromiseRejectionTracker) { LocalScope scope(vm_); CalculateForTime(); void *data = reinterpret_cast(builtins::BuiltinsFunction::FunctionPrototypeInvokeSelf); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::SetHostPromiseRejectionTracker(vm_, data, data); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_SetHostPromiseRejectionTracker); } HWTEST_F_L0(JSNApiSplTest, JSNApi_SetHostResolveBufferTracker) { LocalScope scope(vm_); CalculateForTime(); std::function cb = [](const std::string &inputPath, uint8_t **buff, size_t *buffSize) -> bool { if (inputPath.empty() || buff == nullptr || buffSize == nullptr) { return false; } return true; }; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::SetHostResolveBufferTracker(vm_, cb); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_SetHostResolveBufferTracker); } void *NativePtrGetterCallback(void *info) { return info; } HWTEST_F_L0(JSNApiSplTest, JSNApi_SetNativePtrGetter) { LocalScope scope(vm_); CalculateForTime(); void *cb = reinterpret_cast(NativePtrGetterCallback); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::SetNativePtrGetter(vm_, cb); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_SetNativePtrGetter); } Local HostEnqueueJobCallback([[maybe_unused]] JsiRuntimeCallInfo *callBackFunc) { Local local; return local; } HWTEST_F_L0(JSNApiSplTest, JSNApi_SetHostEnqueueJob) { LocalScope scope(vm_); CalculateForTime(); Local cb = FunctionRef::New(vm_, HostEnqueueJobCallback); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::SetHostEnqueueJob(vm_, cb); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_SetHostEnqueueJob); } HWTEST_F_L0(JSNApiSplTest, JSNApi_InitializeIcuData) { LocalScope scope(vm_); CalculateForTime(); JSRuntimeOptions runtimeOptions; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::InitializeIcuData(runtimeOptions); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_InitializeIcuData); } HWTEST_F_L0(JSNApiSplTest, JSNApi_InitializePGOProfiler) { LocalScope scope(vm_); CalculateForTime(); JSRuntimeOptions runtimeOptions; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::InitializePGOProfiler(runtimeOptions); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_InitializePGOProfiler); } HWTEST_F_L0(JSNApiSplTest, JSNApi_DestroyAnDataManager) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::DestroyAnDataManager(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_DestroyAnDataManager); } HWTEST_F_L0(JSNApiSplTest, JSNApi_DestroyPGOProfiler) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::DestroyPGOProfiler(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi_DestroyPGOProfiler); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsMapIterator_True) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle builtinsMapFunc = env->GetBuiltinsMapFunction(); JSHandle jsMap(factory->NewJSObjectByConstructor(JSHandle(builtinsMapFunc), builtinsMapFunc)); JSHandle linkedHashMap(LinkedHashMap::Create(thread_)); jsMap->SetLinkedMap(thread_, linkedHashMap); JSHandle mapIteratorVal = JSMapIterator::CreateMapIterator(thread_, JSHandle::Cast(jsMap), IterationKind::KEY); Local object = JSNApiHelper::ToLocal(mapIteratorVal); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(object->IsMapIterator()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsMapIterator); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsMapIterator_False) { LocalScope scope(vm_); CalculateForTime(); int num = 10; // 10 = random number Local object = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsMapIterator()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsMapIterator); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsUint8ClampedArray_True) { LocalScope scope(vm_); CalculateForTime(); int32_t length = 4; // 4 = length int32_t byteOffset = 0; // 0 = length Local buffer = ArrayBufferRef::New(vm_, length); Local object = Uint8ClampedArrayRef::New(vm_, buffer, byteOffset, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(object->IsUint8ClampedArray()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsUint8ClampedArray); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsUint8ClampedArray_False) { LocalScope scope(vm_); CalculateForTime(); int num = 10; // 10 = random number Local object = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsUint8ClampedArray()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsUint8ClampedArray); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt16Array_True) { LocalScope scope(vm_); CalculateForTime(); const int32_t length = 30; // 30 = length int32_t byteOffset = 4; // 4 = offset int32_t len = 6; // 6 = length Local arrayBuffer = ArrayBufferRef::New(vm_, length); Local object = Int16ArrayRef::New(vm_, arrayBuffer, byteOffset, len); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(object->IsInt16Array()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsInt16Array); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsInt16Array_False) { LocalScope scope(vm_); CalculateForTime(); int num = 10; // 10 = random number Local object = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsInt16Array()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsInt16Array); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPrimitiveNumber_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSHandle jsTagValue; JSHandle jsprimitive = factory->NewJSPrimitiveRef(PrimitiveType::PRIMITIVE_NUMBER, jsTagValue); JSHandle jspri = JSHandle::Cast(jsprimitive); Local object = JSNApiHelper::ToLocal(jspri); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsJSPrimitiveNumber(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSPrimitiveNumber); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPrimitiveNumber_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsJSPrimitiveNumber()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSPrimitiveNumber); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPrimitiveInt_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSHandle jsTagValue; JSHandle jsprimitive = factory->NewJSPrimitiveRef(PrimitiveType::PRIMITIVE_BIGINT, jsTagValue); JSHandle jspri = JSHandle::Cast(jsprimitive); Local object = JSNApiHelper::ToLocal(jspri); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsJSPrimitiveInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSPrimitiveInt); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPrimitiveBoolean_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSHandle jsTagValue; JSHandle jsprimitive = factory->NewJSPrimitiveRef(PrimitiveType::PRIMITIVE_BOOLEAN, jsTagValue); JSHandle jspri = JSHandle::Cast(jsprimitive); Local object = JSNApiHelper::ToLocal(jspri); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsJSPrimitiveBoolean(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSPrimitiveBoolean); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPrimitiveBoolean_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsJSPrimitiveBoolean()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSPrimitiveBoolean); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSCollator_True) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = vm_->GetGlobalEnv(); ObjectFactory *factory = vm_->GetFactory(); JSHandle ctor = env->GetCollatorFunction(); JSHandle collator = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); JSHandle localeStr = thread_->GlobalConstants()->GetHandledEnUsString(); JSHandle undefinedHandle(thread_, JSTaggedValue::Undefined()); JSHandle initCollator = JSCollator::InitializeCollator(thread_, collator, localeStr, undefinedHandle); JSHandle collatorTagHandleVal = JSHandle::Cast(initCollator); Local object = JSNApiHelper::ToLocal(collatorTagHandleVal); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(object->IsJSCollator()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSCollator); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSCollator_False) { LocalScope scope(vm_); CalculateForTime(); int num = 10; // 10 = random number Local object = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsJSCollator()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSCollator); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPluralRules_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSHandle env = vm_->GetGlobalEnv(); JSHandle optionHandle(thread_, JSTaggedValue::Undefined()); JSHandle ctor = env->GetPluralRulesFunction(); JSHandle pluralRules = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); JSHandle localeStr(factory->NewFromASCII("en-GB")); JSHandle initPluralRules = JSPluralRules::InitializePluralRules(thread_, pluralRules, localeStr, optionHandle); JSHandle tagPlureRules = JSHandle::Cast(initPluralRules); Local object = JSNApiHelper::ToLocal(tagPlureRules); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(object->IsJSPluralRules()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSPluralRules); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSPluralRules_False) { LocalScope scope(vm_); CalculateForTime(); int num = 10; // 10 = random number Local object = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsJSPluralRules()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSPluralRules); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSListFormat_False) { LocalScope scope(vm_); CalculateForTime(); int num = 10; // 10 = random number Local object = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsJSListFormat()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSListFormat); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsAsyncGeneratorFunction_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); MethodLiteral *methodLiteral = nullptr; JSHandle method = factory->NewMethod(methodLiteral); JSHandle asyncGeneratorFunction = factory->NewJSAsyncGeneratorFunction(method); JSHandle asyncgefu = JSHandle::Cast(asyncGeneratorFunction); Local object = JSNApiHelper::ToLocal(asyncgefu); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(object->IsAsyncGeneratorFunction()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsAsyncGeneratorFunction); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsAsyncGeneratorFunction_False) { LocalScope scope(vm_); CalculateForTime(); int num = 10; // 10 = random number Local object = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsAsyncGeneratorFunction()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsAsyncGeneratorFunction); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsLinkedList_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSHandle env = vm_->GetGlobalEnv(); JSHandle globalObject = env->GetJSGlobalObject(); JSHandle key(factory->NewFromASCII("ArkPrivate")); JSHandle value = JSObject::GetProperty(thread_, JSHandle(globalObject), key).GetValue(); auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::LinkedList))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo); JSHandle contianer = JSHandle(thread_, containers::ContainersPrivate::Load(objCallInfo)); JSHandle linkedList = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(contianer), contianer)); JSTaggedValue doubleList = TaggedDoubleList::Create(thread_); linkedList->SetDoubleList(thread_, doubleList); JSHandle linkedListTag = JSHandle::Cast(linkedList); Local object = JSNApiHelper::ToLocal(linkedListTag); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(object->IsLinkedList()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsLinkedList); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsLinkedList_False) { LocalScope scope(vm_); CalculateForTime(); int num = 10; // 10 = random number Local object = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsLinkedList()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsLinkedList); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsLinkedListIterator_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSHandle env = vm_->GetGlobalEnv(); JSHandle globalObject = env->GetJSGlobalObject(); JSHandle key(factory->NewFromASCII("ArkPrivate")); JSHandle tagvalue = JSObject::GetProperty(thread_, JSHandle(globalObject), key).GetValue(); uint32_t argvLength = 6; // 6 = argv length auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), argvLength); objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(tagvalue.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::LinkedList))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo); JSHandle contianer = JSHandle(thread_, containers::ContainersPrivate::Load(objCallInfo)); JSHandle linkedList = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(contianer), contianer)); JSTaggedValue doubleList = TaggedDoubleList::Create(thread_); linkedList->SetDoubleList(thread_, doubleList); uint32_t elementsNum = 256; // 256 = Number of cycles for (uint32_t i = 0; i < elementsNum; i++) { JSHandle taggedvalue(thread_, JSTaggedValue(i)); JSAPILinkedList::Add(thread_, linkedList, taggedvalue); } JSHandle taggedValueHandle(thread_, linkedList.GetTaggedValue()); JSHandle linkedListIterator(thread_, JSAPILinkedListIterator::CreateLinkedListIterator(thread_, taggedValueHandle).GetTaggedValue()); JSHandle linkedListIteratortag = JSHandle::Cast(linkedListIterator); Local object = JSNApiHelper::ToLocal(linkedListIteratortag); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(object->IsLinkedListIterator()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsLinkedListIterator); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsLinkedListIterator_False) { LocalScope scope(vm_); CalculateForTime(); int num = 10; // 10 = random number Local object = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsLinkedListIterator()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsLinkedListIterator); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsList_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSHandle env = vm_->GetGlobalEnv(); JSHandle globalObject = env->GetJSGlobalObject(); JSHandle key(factory->NewFromASCII("ArkPrivate")); JSHandle value = JSObject::GetProperty(thread_, JSHandle(globalObject), key).GetValue(); uint32_t argvLength = 6; // 6 = argv length auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), argvLength); objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::List))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo); JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread_, prev); JSHandle constructor(thread_, result); JSHandle list(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); JSTaggedValue singleList = TaggedSingleList::Create(thread_); list->SetSingleList(thread_, singleList); JSHandle Listtag = JSHandle::Cast(list); Local object = JSNApiHelper::ToLocal(Listtag); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(object->IsList()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsList); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsList_False) { LocalScope scope(vm_); CalculateForTime(); int num = 10; // 10 = random number Local object = IntegerRef::New(vm_, num); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsList()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsList); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsPlainArray_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSHandle env = vm_->GetGlobalEnv(); JSHandle globalObject = env->GetJSGlobalObject(); JSHandle key(factory->NewFromASCII("ArkPrivate")); JSHandle value = JSObject::GetProperty(thread_, JSHandle(globalObject), key).GetValue(); uint32_t argvLength = 6; // 6 = argv length auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), argvLength); objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::PlainArray))); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, objCallInfo); JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread_, prev); JSHandle constructor(thread_, result); JSHandle plainArray( factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); JSHandle keyArray = JSHandle(factory->NewTaggedArray(8)); JSHandle valueArray = JSHandle(factory->NewTaggedArray(8)); plainArray->SetKeys(thread_, keyArray); plainArray->SetValues(thread_, valueArray); JSHandle plainarraytag = JSHandle::Cast(plainArray); Local object = JSNApiHelper::ToLocal(plainarraytag); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(object->IsPlainArray()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsPlainArray); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsPlainArray_False) { LocalScope scope(vm_); CalculateForTime(); int num = 10; // 10 = random number Local object = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsPlainArray()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsPlainArray); } HWTEST_F_L0(JSNApiSplTest, DateRef_New) { LocalScope scope(vm_); CalculateForTime(); double time = 3.14; // 3.14 = random number gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { DateRef::New(vm_, time); } gettimeofday(&g_endTime, nullptr); TEST_TIME(DateRef::New); } HWTEST_F_L0(JSNApiSplTest, DateRef_ToString) { LocalScope scope(vm_); CalculateForTime(); double time = 3.14; // 3.14 = random number Local object = DateRef::New(vm_, time); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->ToString(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(DateRef::ToString); } HWTEST_F_L0(JSNApiSplTest, DateRef_GetTime) { LocalScope scope(vm_); CalculateForTime(); double time = 3.14; // 3.14 = random number Local object = DateRef::New(vm_, time); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetTime(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(DateRef::GetTime); } HWTEST_F_L0(JSNApiSplTest, ProxyRef_GetHandler) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = vm_->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle hclass(thread_, env->GetObjectFunction().GetObject()); JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle::Cast(hclass), hclass)); JSHandle key(factory->NewFromASCII("x")); JSHandle value(thread_, JSTaggedValue(1)); JSObject::SetProperty(thread_, targetHandle, key, value); JSHandle handlerHandle( factory->NewJSObjectByConstructor(JSHandle::Cast(hclass), hclass)); JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); JSHandle proxyTagValue = JSHandle::Cast(proxyHandle); Local object = JSNApiHelper::ToLocal(proxyTagValue); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetHandler(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ProxyRef::GetHandler); } HWTEST_F_L0(JSNApiSplTest, ProxyRef_GetTarget) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = vm_->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle hclass(thread_, env->GetObjectFunction().GetObject()); JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle::Cast(hclass), hclass)); JSHandle key(factory->NewFromASCII("x")); JSHandle value(thread_, JSTaggedValue(1)); JSObject::SetProperty(thread_, targetHandle, key, value); JSHandle handlerHandle( factory->NewJSObjectByConstructor(JSHandle::Cast(hclass), hclass)); JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); JSHandle proxyTagValue = JSHandle::Cast(proxyHandle); Local object = JSNApiHelper::ToLocal(proxyTagValue); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetTarget(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ProxyRef::GetTarget); } HWTEST_F_L0(JSNApiSplTest, ProxyRef_IsRevoked) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = vm_->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle hclass(thread_, env->GetObjectFunction().GetObject()); JSHandle targetHandle(factory->NewJSObjectByConstructor(JSHandle::Cast(hclass), hclass)); JSHandle key(factory->NewFromASCII("x")); JSHandle value(thread_, JSTaggedValue(1)); JSObject::SetProperty(thread_, targetHandle, key, value); JSHandle handlerHandle( factory->NewJSObjectByConstructor(JSHandle::Cast(hclass), hclass)); JSHandle proxyHandle = JSProxy::ProxyCreate(thread_, targetHandle, handlerHandle); JSHandle proxyTagValue = JSHandle::Cast(proxyHandle); Local object = JSNApiHelper::ToLocal(proxyTagValue); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsRevoked(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ProxyRef::IsRevoked); } HWTEST_F_L0(JSNApiSplTest, MapRef_GetSize) { LocalScope scope(vm_); CalculateForTime(); Local object = MapRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetSize(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(MapRef::GetSize); } HWTEST_F_L0(JSNApiSplTest, MapRef_GetTotalElements) { LocalScope scope(vm_); CalculateForTime(); Local object = MapRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetTotalElements(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(MapRef::GetTotalElements); } HWTEST_F_L0(JSNApiSplTest, MapRef_Get) { LocalScope scope(vm_); CalculateForTime(); Local object = MapRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->Get(vm_, key); } gettimeofday(&g_endTime, nullptr); TEST_TIME(MapRef::Get); } HWTEST_F_L0(JSNApiSplTest, MapRef_GetKey) { LocalScope scope(vm_); CalculateForTime(); Local object = MapRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetKey(vm_, 0); } gettimeofday(&g_endTime, nullptr); TEST_TIME(MapRef::GetKey); } HWTEST_F_L0(JSNApiSplTest, MapRef_GetValue) { LocalScope scope(vm_); CalculateForTime(); Local object = MapRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetValue(vm_, 0); } gettimeofday(&g_endTime, nullptr); TEST_TIME(MapRef::GetValue); } HWTEST_F_L0(JSNApiSplTest, MapRef_New) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { MapRef::New(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(MapRef::New); } HWTEST_F_L0(JSNApiSplTest, MapRef_Set) { LocalScope scope(vm_); CalculateForTime(); Local object = MapRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->Set(vm_, key, value); } gettimeofday(&g_endTime, nullptr); TEST_TIME(MapRef::Set); } HWTEST_F_L0(JSNApiSplTest, WeakMapRef_GetSize) { LocalScope scope(vm_); CalculateForTime(); Local object = WeakMapRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetSize(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(WeakMapRef::GetSize); } HWTEST_F_L0(JSNApiSplTest, WeakMapRef_GetTotalElements) { LocalScope scope(vm_); CalculateForTime(); Local object = WeakMapRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetTotalElements(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(WeakMapRef::GetTotalElements); } HWTEST_F_L0(JSNApiSplTest, WeakMapRef_GetKey) { LocalScope scope(vm_); CalculateForTime(); Local object = WeakMapRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetKey(vm_, 0); } gettimeofday(&g_endTime, nullptr); TEST_TIME(WeakMapRef::GetKey); } HWTEST_F_L0(JSNApiSplTest, WeakMapRef_GetValue) { LocalScope scope(vm_); CalculateForTime(); Local object = WeakMapRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetValue(vm_, 0); } gettimeofday(&g_endTime, nullptr); TEST_TIME(WeakMapRef::GetValue); } HWTEST_F_L0(JSNApiSplTest, SetRef_GetSize) { LocalScope scope(vm_); CalculateForTime(); Local object = SetRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetSize(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(SetRef::GetSize); } HWTEST_F_L0(JSNApiSplTest, SetRef_GetTotalElements) { LocalScope scope(vm_); CalculateForTime(); Local object = SetRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetTotalElements(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(SetRef::GetTotalElements); } HWTEST_F_L0(JSNApiSplTest, SetRef_GetValue) { LocalScope scope(vm_); CalculateForTime(); Local object = SetRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetValue(vm_, 0); } gettimeofday(&g_endTime, nullptr); TEST_TIME(SetRef::GetValue); } HWTEST_F_L0(JSNApiSplTest, WeakSetRef_GetSize) { LocalScope scope(vm_); CalculateForTime(); Local object = WeakSetRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetSize(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(WeakSetRef::GetSize); } HWTEST_F_L0(JSNApiSplTest, WeakSetRef_GetTotalElements) { LocalScope scope(vm_); CalculateForTime(); Local object = WeakSetRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetTotalElements(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(WeakSetRef::GetTotalElements); } HWTEST_F_L0(JSNApiSplTest, WeakSetRef_GetValue) { LocalScope scope(vm_); CalculateForTime(); Local object = WeakSetRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = StringRef::NewFromUtf8(vm_, "TestValue"); object->Set(vm_, key, value); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetValue(vm_, 0); } gettimeofday(&g_endTime, nullptr); TEST_TIME(WeakSetRef::GetValue); } HWTEST_F_L0(JSNApiSplTest, MapIteratorRef_GetIndex) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle builtinsMapFunc = env->GetBuiltinsMapFunction(); JSHandle jsMap(factory->NewJSObjectByConstructor(JSHandle(builtinsMapFunc), builtinsMapFunc)); JSHandle linkedHashMap(LinkedHashMap::Create(thread_)); jsMap->SetLinkedMap(thread_, linkedHashMap); JSHandle mapValue(jsMap); JSHandle mapIteratorVal = JSMapIterator::CreateMapIterator(thread_, mapValue, IterationKind::KEY); JSHandle mapIterator = JSHandle::Cast(mapIteratorVal); mapIterator->SetNextIndex(1); Local object = JSNApiHelper::ToLocal(mapIteratorVal); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetIndex(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(MapIteratorRef::GetIndex); } HWTEST_F_L0(JSNApiSplTest, MapIteratorRef_GetKind) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle builtinsMapFunc = env->GetBuiltinsMapFunction(); JSHandle jsMap(factory->NewJSObjectByConstructor(JSHandle(builtinsMapFunc), builtinsMapFunc)); JSHandle linkedHashMap(LinkedHashMap::Create(thread_)); jsMap->SetLinkedMap(thread_, linkedHashMap); JSHandle mapValue(jsMap); JSHandle mapIteratorVal = JSMapIterator::CreateMapIterator(thread_, mapValue, IterationKind::KEY); JSHandle mapIterator = JSHandle::Cast(mapIteratorVal); mapIterator->SetIterationKind(IterationKind::VALUE); mapIterator->SetIterationKind(IterationKind::KEY_AND_VALUE); Local object = JSNApiHelper::ToLocal(mapIteratorVal); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetKind(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(MapIteratorRef::GetKind); } HWTEST_F_L0(JSNApiSplTest, SetIteratorRef_GetIndex) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle constructor = env->GetBuiltinsSetFunction(); JSHandle set = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); JSHandle hashSet = LinkedHashSet::Create(thread_); set->SetLinkedSet(thread_, hashSet); JSHandle setIteratorValue = JSSetIterator::CreateSetIterator(thread_, JSHandle(set), IterationKind::KEY); JSHandle setIterator = JSHandle::Cast(setIteratorValue); setIterator->SetNextIndex(1); Local object = JSNApiHelper::ToLocal(setIteratorValue); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetIndex(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(SetIteratorRef::GetIndex); } HWTEST_F_L0(JSNApiSplTest, SetIteratorRef_GetKind) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle constructor = env->GetBuiltinsSetFunction(); JSHandle set = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); JSHandle hashSet = LinkedHashSet::Create(thread_); set->SetLinkedSet(thread_, hashSet); JSHandle setIteratorValue = JSSetIterator::CreateSetIterator(thread_, JSHandle(set), IterationKind::KEY); JSHandle setIterator = JSHandle::Cast(setIteratorValue); setIterator->SetIterationKind(IterationKind::VALUE); setIterator->SetIterationKind(IterationKind::KEY_AND_VALUE); Local object = JSNApiHelper::ToLocal(setIteratorValue); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetKind(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(SetIteratorRef::GetKind); } HWTEST_F_L0(JSNApiSplTest, GeneratorFunctionRef_IsGenerator) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle genFunc = env->GetGeneratorFunctionFunction(); JSHandle genObjHandleVal = factory->NewJSGeneratorObject(genFunc); JSHandle hclass = JSHandle::Cast(env->GetGeneratorFunctionClass()); JSHandle generatorFunc = JSHandle::Cast(factory->NewJSObject(hclass)); JSFunction::InitializeJSFunction(thread_, generatorFunc, FunctionKind::GENERATOR_FUNCTION); JSHandle generatorContext = factory->NewGeneratorContext(); generatorContext->SetMethod(thread_, generatorFunc.GetTaggedValue()); JSHandle generatorContextVal = JSHandle::Cast(generatorContext); genObjHandleVal->SetGeneratorContext(thread_, generatorContextVal.GetTaggedValue()); JSHandle genObjTagHandleVal = JSHandle::Cast(genObjHandleVal); Local genObjectRef = JSNApiHelper::ToLocal(genObjTagHandleVal); Local object = genObjectRef->GetGeneratorFunction(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsGenerator(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(GeneratorFunctionRef::IsGenerator); } HWTEST_F_L0(JSNApiSplTest, GeneratorObjectRef_GetGeneratorState) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle genFunc = env->GetGeneratorFunctionFunction(); JSHandle genObjHandleVal = factory->NewJSGeneratorObject(genFunc); JSHandle hclass = JSHandle::Cast(env->GetGeneratorFunctionClass()); JSHandle generatorFunc = JSHandle::Cast(factory->NewJSObject(hclass)); JSFunction::InitializeJSFunction(thread_, generatorFunc, FunctionKind::GENERATOR_FUNCTION); JSHandle generatorContext = factory->NewGeneratorContext(); generatorContext->SetMethod(thread_, generatorFunc.GetTaggedValue()); JSHandle generatorContextVal = JSHandle::Cast(generatorContext); genObjHandleVal->SetGeneratorContext(thread_, generatorContextVal.GetTaggedValue()); genObjHandleVal->SetGeneratorState(JSGeneratorState::COMPLETED); JSHandle genObjTagHandleVal = JSHandle::Cast(genObjHandleVal); Local object = JSNApiHelper::ToLocal(genObjTagHandleVal); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetGeneratorState(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(GeneratorObjectRef::GetGeneratorState); } HWTEST_F_L0(JSNApiSplTest, GeneratorObjectRef_GetGeneratorFunction) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle genFunc = env->GetGeneratorFunctionFunction(); JSHandle genObjHandleVal = factory->NewJSGeneratorObject(genFunc); JSHandle hclass = JSHandle::Cast(env->GetGeneratorFunctionClass()); JSHandle generatorFunc = JSHandle::Cast(factory->NewJSObject(hclass)); JSFunction::InitializeJSFunction(thread_, generatorFunc, FunctionKind::GENERATOR_FUNCTION); JSHandle generatorContext = factory->NewGeneratorContext(); generatorContext->SetMethod(thread_, generatorFunc.GetTaggedValue()); JSHandle generatorContextVal = JSHandle::Cast(generatorContext); genObjHandleVal->SetGeneratorContext(thread_, generatorContextVal.GetTaggedValue()); genObjHandleVal->SetGeneratorState(JSGeneratorState::COMPLETED); JSHandle genObjTagHandleVal = JSHandle::Cast(genObjHandleVal); Local object = JSNApiHelper::ToLocal(genObjTagHandleVal); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetGeneratorFunction(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(GeneratorObjectRef::GetGeneratorFunction); } HWTEST_F_L0(JSNApiSplTest, GeneratorObjectRef_GetGeneratorReceiver) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle genFunc = env->GetGeneratorFunctionFunction(); JSHandle genObjHandleVal = factory->NewJSGeneratorObject(genFunc); JSHandle hclass = JSHandle::Cast(env->GetGeneratorFunctionClass()); JSHandle generatorFunc = JSHandle::Cast(factory->NewJSObject(hclass)); JSFunction::InitializeJSFunction(thread_, generatorFunc, FunctionKind::GENERATOR_FUNCTION); JSHandle generatorContext = factory->NewGeneratorContext(); generatorContext->SetMethod(thread_, generatorFunc.GetTaggedValue()); JSHandle generatorContextVal = JSHandle::Cast(generatorContext); genObjHandleVal->SetGeneratorContext(thread_, generatorContextVal.GetTaggedValue()); genObjHandleVal->SetGeneratorState(JSGeneratorState::COMPLETED); JSHandle genObjTagHandleVal = JSHandle::Cast(genObjHandleVal); Local object = JSNApiHelper::ToLocal(genObjTagHandleVal); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetGeneratorReceiver(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(GeneratorObjectRef::GetGeneratorReceiver); } HWTEST_F_L0(JSNApiSplTest, CollatorRef_GetCompareFunction) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = vm_->GetGlobalEnv(); ObjectFactory *factory = vm_->GetFactory(); JSHandle ctor = env->GetCollatorFunction(); JSHandle collator = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); JSHandle localeStr = thread_->GlobalConstants()->GetHandledEnUsString(); JSHandle undefinedHandle(thread_, JSTaggedValue::Undefined()); JSHandle initCollator = JSCollator::InitializeCollator(thread_, collator, localeStr, undefinedHandle); JSHandle collatorTagHandleVal = JSHandle::Cast(initCollator); Local object = JSNApiHelper::ToLocal(collatorTagHandleVal); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetCompareFunction(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(GeneratorObjectRef::GetCompareFunction); } HWTEST_F_L0(JSNApiSplTest, DataTimeFormatRef_GetFormatFunction) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle localeCtor = env->GetLocaleFunction(); JSHandle locales = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(localeCtor), localeCtor)); icu::Locale icuLocale("zh", "Hans", "Cn", "calendar=chinese"); factory->NewJSIntlIcuData(locales, icuLocale, JSLocale::FreeIcuLocale); JSHandle objFun = env->GetObjectFunction(); JSHandle options = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); options = JSDateTimeFormat::ToDateTimeOptions(thread_, JSHandle::Cast(options), RequiredOption::ANY, DefaultsOption::ALL); JSHandle dtfCtor = env->GetDateTimeFormatFunction(); JSHandle dtf = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(dtfCtor), dtfCtor)); dtf = JSDateTimeFormat::InitializeDateTimeFormat(thread_, dtf, JSHandle::Cast(locales), JSHandle::Cast(options)); JSHandle dtfTagHandleVal = JSHandle::Cast(dtf); Local object = JSNApiHelper::ToLocal(dtfTagHandleVal); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetFormatFunction(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(DataTimeFormatRef::GetFormatFunction); } HWTEST_F_L0(JSNApiSplTest, NumberFormatRef_GetFormatFunction) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory(); JSHandle ctor = env->GetNumberFormatFunction(); JSHandle numberFormat = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); EXPECT_TRUE(*numberFormat != nullptr); JSHandle locales(factory->NewFromASCII("zh-Hans-CN")); JSHandle undefinedOptions(thread_, JSTaggedValue::Undefined()); JSNumberFormat::InitializeNumberFormat(thread_, numberFormat, locales, undefinedOptions); JSHandle numberformatTagHandleVal = JSHandle::Cast(numberFormat); Local object = JSNApiHelper::ToLocal(numberformatTagHandleVal); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetFormatFunction(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NumberFormatRef::GetFormatFunction); } HWTEST_F_L0(JSNApiSplTest, PromiseRejectInfo_PromiseRejectInfo) { LocalScope scope(vm_); CalculateForTime(); Local toStringPromise = StringRef::NewFromUtf8(vm_, "-3.14"); Local promise(toStringPromise); Local toStringReason = StringRef::NewFromUtf8(vm_, "123.3"); Local reason(toStringReason); void *data = static_cast(new std::string("promisereject")); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { PromiseRejectInfo promisereject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PromiseRejectInfo::PromiseRejectInfo); } HWTEST_F_L0(JSNApiSplTest, PromiseRejectInfo_GetPromise) { LocalScope scope(vm_); CalculateForTime(); Local toStringPromise = StringRef::NewFromUtf8(vm_, "-3.14"); Local promise(toStringPromise); Local toStringReason = StringRef::NewFromUtf8(vm_, "3.14"); Local reason(toStringReason); void *data = static_cast(new std::string("promisereject")); PromiseRejectInfo promisereject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { promisereject.GetPromise(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PromiseRejectInfo::GetPromise); } HWTEST_F_L0(JSNApiSplTest, PromiseRejectInfo_GetReason) { LocalScope scope(vm_); CalculateForTime(); Local toStringPromise = StringRef::NewFromUtf8(vm_, "-3.14"); Local promise(toStringPromise); Local toStringReason = StringRef::NewFromUtf8(vm_, "3.14"); Local reason(toStringReason); void *data = static_cast(new std::string("promisereject")); PromiseRejectInfo promisereject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { promisereject.GetReason(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PromiseRejectInfo::GetReason); } HWTEST_F_L0(JSNApiSplTest, PromiseRejectInfo_GetOperation) { LocalScope scope(vm_); CalculateForTime(); Local toStringPromise = StringRef::NewFromUtf8(vm_, "-3.14"); Local promise(toStringPromise); Local toStringReason = StringRef::NewFromUtf8(vm_, "3.14"); Local reason(toStringReason); void *data = static_cast(new std::string("promisereject")); PromiseRejectInfo promisereject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { promisereject.GetOperation(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PromiseRejectInfo::GetOperation); } HWTEST_F_L0(JSNApiSplTest, PromiseRejectInfo_GetData) { LocalScope scope(vm_); CalculateForTime(); Local toStringPromise = StringRef::NewFromUtf8(vm_, "-3.14"); Local promise(toStringPromise); Local toStringReason = StringRef::NewFromUtf8(vm_, "3.14"); Local reason(toStringReason); void *data = static_cast(new std::string("promisereject")); PromiseRejectInfo promisereject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { promisereject.GetData(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PromiseRejectInfo::GetData); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_Int32Value) { LocalScope scope(vm_); CalculateForTime(); int num = 123; // 123 = random number Local res = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->Int32Value(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Int32Value); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToNumber) { LocalScope scope(vm_); CalculateForTime(); Local toString = StringRef::NewFromUtf8(vm_, "-123.3"); Local toValue(toString); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { toString->ToNumber(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToNumber); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsHole) { LocalScope scope(vm_); CalculateForTime(); Local res = IntegerRef::New(vm_, 123); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->IsHole(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsHole); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsTrue) { LocalScope scope(vm_); CalculateForTime(); int num = 123; // 123 = random number Local res = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->IsTrue(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsTrue); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsSymbol) { LocalScope scope(vm_); CalculateForTime(); int num = 123; // 123 = random number Local res = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->IsSymbol(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsSymbol); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsObject) { LocalScope scope(vm_); CalculateForTime(); int num = 123; // 123 = random number Local res = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->IsObject(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsObject); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsTypedArray) { LocalScope scope(vm_); CalculateForTime(); int num = 123; // 123 = random number Local res = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->IsTypedArray(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsTypedArray); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsNativePointer) { LocalScope scope(vm_); CalculateForTime(); int num = 123; // 123 = random number Local res = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->IsNativePointer(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsNativePointer); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsRegExp) { LocalScope scope(vm_); CalculateForTime(); int num = 123; // 123 = random number Local res = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->IsRegExp(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsRegExp); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArrayIterator) { LocalScope scope(vm_); CalculateForTime(); int num = 123; // 123 = random number Local res = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->IsArrayIterator(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsArrayIterator); } HWTEST_F_L0(JSNApiSplTest, EscapeLocalScope_gz) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { EscapeLocalScope test(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(EscapeLocalScope::EscapeLocalScope); } HWTEST_F_L0(JSNApiSplTest, EscapeLocalScope_Escape) { LocalScope scope(vm_); CalculateForTime(); EscapeLocalScope test(vm_); int num = 3; // 3 = random number gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { test.Escape(ArrayRef::New(vm_, num)); } gettimeofday(&g_endTime, nullptr); TEST_TIME(EscapeLocalScope::Escape); } HWTEST_F_L0(JSNApiSplTest, JSExecutionScope_gz) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSExecutionScope res(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSExecutionScope::JSExecutionScope); } HWTEST_F_L0(JSNApiSplTest, LocalScope_gz) { CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { LocalScope scope(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(LocalScope::LocalScope); } HWTEST_F_L0(JSNApiSplTest, PrimitiveRef_GetValue) { LocalScope scope(vm_); CalculateForTime(); int num = 0; // 0 = random number Local intValue = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->GetValue(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(PrimitiveRef::GetValue); } HWTEST_F_L0(JSNApiSplTest, IntegerRef_New) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { IntegerRef::New(vm_, 0); } gettimeofday(&g_endTime, nullptr); TEST_TIME(IntegerRef::New); } HWTEST_F_L0(JSNApiSplTest, IntegerRef_NewFromUnsigned) { LocalScope scope(vm_); CalculateForTime(); unsigned int res = 123; // 123 = random number gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { IntegerRef::NewFromUnsigned(vm_, res); } gettimeofday(&g_endTime, nullptr); TEST_TIME(IntegerRef::NewFromUnsigned); } HWTEST_F_L0(JSNApiSplTest, IntegerRef_Value) { LocalScope scope(vm_); CalculateForTime(); int num = 0; // 0 = random number Local res = IntegerRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->Value(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(IntegerRef::Value); } HWTEST_F_L0(JSNApiSplTest, NumberRef_New01) { LocalScope scope(vm_); CalculateForTime(); double res = 64; // 64 = random number gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NumberRef::New(vm_, res); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NumberRef::New01); } HWTEST_F_L0(JSNApiSplTest, NumberRef_New02) { LocalScope scope(vm_); CalculateForTime(); int32_t res = 64; // 64 = random number gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NumberRef::New(vm_, res); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NumberRef::New02); } HWTEST_F_L0(JSNApiSplTest, NumberRef_New03) { LocalScope scope(vm_); CalculateForTime(); uint32_t res = 64; // 64 = random number gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NumberRef::New(vm_, res); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NumberRef::New03); } HWTEST_F_L0(JSNApiSplTest, NumberRef_New04) { LocalScope scope(vm_); CalculateForTime(); int64_t res = 64; // 64 = random number gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NumberRef::New(vm_, res); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NumberRef::New04); } HWTEST_F_L0(JSNApiSplTest, NumberRef_Value) { LocalScope scope(vm_); CalculateForTime(); int32_t num = 0; // 0 = random number Local res = NumberRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->Value(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NumberRef::Value); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_Cast) { LocalScope scope(vm_); CalculateForTime(); Local value = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ObjectRef::Cast(*value); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::Cast); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_New) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ObjectRef::New(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::New); } void *Detach1() { GTEST_LOG_(INFO) << "detach is running"; return nullptr; } void Attach1([[maybe_unused]] void *buffer) { GTEST_LOG_(INFO) << "attach is running"; } HWTEST_F_L0(JSNApiSplTest, ObjectRef_Set02) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->Set(vm_, key, value); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::Set02); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_Set03) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->Set(vm_, key, value); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::Set03); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_SetAccessorProperty) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local target1 = FunctionRef::New(vm_, nullptr); Local target2 = FunctionRef::New(vm_, nullptr); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->SetAccessorProperty(vm_, key, target1, target2); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::SetAccessorProperty); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_Get01) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->Get(vm_, key); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::Get01); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_Get02) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); int32_t key = 123; // 123 = random number gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->Get(vm_, key); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::Get02); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetOwnProperty) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); Local key = StringRef::NewFromUtf8(vm_, "TestKey"); Local value = ObjectRef::New(vm_); PropertyAttribute attribute(value, true, true, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetOwnProperty(vm_, key, attribute); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::GetOwnProperty); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetOwnPropertyNames) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); Local value = ObjectRef::New(vm_); PropertyAttribute attribute(value, true, true, true); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetOwnPropertyNames(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::GetOwnPropertyNames); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetAllPropertyNames) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); uint32_t filter = 123; // 123 = random number gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetAllPropertyNames(vm_, filter); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::GetAllPropertyNames); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetOwnEnumerablePropertyNames) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetOwnEnumerablePropertyNames(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::GetOwnEnumerablePropertyNames); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetPrototype) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetPrototype(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::GetPrototype); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_SetPrototype) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); Local prototype = object->GetPrototype(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->SetPrototype(vm_, prototype); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::SetPrototype); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_Freeze) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->Freeze(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::Freeze); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_Seal) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->Seal(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::Seal); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_SetNativePointerFieldCount) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); int32_t input = 34; // 34 = random number gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->SetNativePointerFieldCount(vm_, input); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::SetNativePointerFieldCount); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetNativePointerFieldCount) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); int32_t input = 34; // 34 = random number object->SetNativePointerFieldCount(vm_, input); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetNativePointerFieldCount(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::GetNativePointerFieldCount); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_SetNativePointerField) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); NativePointerCallback callBack = nullptr; void *vp1 = static_cast(new std::string("test")); void *vp2 = static_cast(new std::string("test")); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->SetNativePointerField(vm_, 33, vp1, callBack, vp2); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::SetNativePointerField); } HWTEST_F_L0(JSNApiSplTest, ObjectRef_GetNativePointerField) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); NativePointerCallback callBack = nullptr; void *vp1 = static_cast(new std::string("test")); void *vp2 = static_cast(new std::string("test")); object->SetNativePointerField(vm_, 33, vp1, callBack, vp2); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->GetNativePointerField(33); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ObjectRef::GetNativePointerField); } HWTEST_F_L0(JSNApiSplTest, JSNApi_GetGlobalObject) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::GetGlobalObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi::GetGlobalObject); } HWTEST_F_L0(JSNApiSplTest, JSNApi_ExecutePendingJob) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::ExecutePendingJob(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi::ExecutePendingJob); } HWTEST_F_L0(JSNApiSplTest, JSNApi_TriggerGC) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::TriggerGC(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi::TriggerGC); } HWTEST_F_L0(JSNApiSplTest, JSNApi_ThrowException) { LocalScope scope(vm_); CalculateForTime(); Local message = StringRef::NewFromUtf8(vm_, "ErrorTest"); Local error = Exception::Error(vm_, message); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::ThrowException(vm_, error); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi::ThrowException); } HWTEST_F_L0(JSNApiSplTest, JSNApi_GetAndClearUncaughtException) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::GetAndClearUncaughtException(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi::GetAndClearUncaughtException); } HWTEST_F_L0(JSNApiSplTest, JSNApi_GetUncaughtException) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::GetUncaughtException(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi::GetUncaughtException); } HWTEST_F_L0(JSNApiSplTest, JSNApi_HasPendingException) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::HasPendingException(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi::HasPendingException); } HWTEST_F_L0(JSNApiSplTest, JSNApi_EnableUserUncaughtErrorHandler) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::EnableUserUncaughtErrorHandler(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi::EnableUserUncaughtErrorHandler); } HWTEST_F_L0(JSNApiSplTest, JSNApi_StartDebugger) { LocalScope scope(vm_); CalculateForTime(); JSNApi::DebugOption res; res.libraryPath = "mytests"; res.isDebugMode = true; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::StartDebugger(vm_, res); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi::StartDebugger); } HWTEST_F_L0(JSNApiSplTest, JSNApi_StopDebugger) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::StopDebugger(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSNApi::StopDebugger); } HWTEST_F_L0(JSNApiSplTest, JsiRuntimeCallInfo_GetFunctionRef) { LocalScope scope(vm_); CalculateForTime(); JsiRuntimeCallInfo object; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.GetFunctionRef(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JsiRuntimeCallInfo::GetFunctionRef); } HWTEST_F_L0(JSNApiSplTest, JsiRuntimeCallInfo_GetNewTargetRef) { LocalScope scope(vm_); CalculateForTime(); JsiRuntimeCallInfo object; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.GetNewTargetRef(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JsiRuntimeCallInfo::GetNewTargetRef); } HWTEST_F_L0(JSNApiSplTest, JsiRuntimeCallInfo_GetThisRef) { LocalScope scope(vm_); CalculateForTime(); JsiRuntimeCallInfo object; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.GetThisRef(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JsiRuntimeCallInfo::GetThisRef); } HWTEST_F_L0(JSNApiSplTest, JsiRuntimeCallInfo_GetCallArgRef) { LocalScope scope(vm_); CalculateForTime(); JsiRuntimeCallInfo object; uint32_t idx = 123; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.GetCallArgRef(idx); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JsiRuntimeCallInfo::GetCallArgRef); } HWTEST_F_L0(JSNApiSplTest, FunctionCallScope_Gz) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { FunctionCallScope test(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionCallScope::FunctionCallScope); } HWTEST_F_L0(JSNApiSplTest, IsSetIterator_Ture) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSHandle proto = thread_->GetEcmaVM()->GetGlobalEnv()->GetFunctionPrototype(); JSHandle setClass = factory->NewEcmaHClass(JSSet::SIZE, JSType::JS_SET, proto); JSHandle jsSet = JSHandle::Cast(factory->NewJSObjectWithInit(setClass)); JSHandle linkedSet(LinkedHashSet::Create(thread_)); jsSet->SetLinkedSet(thread_, linkedSet); JSHandle jsSetIter = factory->NewJSSetIterator(jsSet, IterationKind::KEY); JSHandle setiter = JSHandle::Cast(jsSetIter); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(JSNApiHelper::ToLocal(setiter)->IsSetIterator()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsSetIterator); } HWTEST_F_L0(JSNApiSplTest, IsSetIterator_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsSetIterator()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsSetIterator); } HWTEST_F_L0(JSNApiSplTest, IsUint16Array_True) { LocalScope scope(vm_); CalculateForTime(); int32_t num = 30; // 30 = ArrayBuff length int32_t byteOffset = 4; // 4 = Offset int32_t length = 6; // 6 = length Local buffer = ArrayBufferRef::New(vm_, num); Local object = Uint16ArrayRef::New(vm_, buffer, byteOffset, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(object->IsUint16Array()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsUint16Array); } HWTEST_F_L0(JSNApiSplTest, IsUint16Array_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsUint16Array()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsUint16Array); } HWTEST_F_L0(JSNApiSplTest, IsInt32Array_True) { LocalScope scope(vm_); CalculateForTime(); int32_t num = 30; // 30 = ArrayBuff length int32_t byteOffset = 4; // 4 = Offset int32_t length = 6; // 6 = length Local buffer = ArrayBufferRef::New(vm_, num); Local object = Int32ArrayRef::New(vm_, buffer, byteOffset, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(object->IsInt32Array()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsInt32Array); } HWTEST_F_L0(JSNApiSplTest, IsInt32Array_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsInt32Array()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsInt32Array); } HWTEST_F_L0(JSNApiSplTest, IsJSPrimitiveString_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsJSPrimitiveString()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSPrimitiveString); } HWTEST_F_L0(JSNApiSplTest, IsGeneratorObject_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); auto env = vm_->GetGlobalEnv(); JSHandle genFunc = env->GetGeneratorFunctionFunction(); JSHandle genObjHandleVal = factory->NewJSGeneratorObject(genFunc); JSHandle hclass = JSHandle::Cast(env->GetGeneratorFunctionClass()); JSHandle generatorFunc = JSHandle::Cast(factory->NewJSObject(hclass)); JSFunction::InitializeJSFunction(thread_, generatorFunc, FunctionKind::GENERATOR_FUNCTION); JSHandle generatorContext = factory->NewGeneratorContext(); generatorContext->SetMethod(thread_, generatorFunc.GetTaggedValue()); JSHandle generatorContextVal = JSHandle::Cast(generatorContext); genObjHandleVal->SetGeneratorContext(thread_, generatorContextVal.GetTaggedValue()); JSHandle genObjTagHandleVal = JSHandle::Cast(genObjHandleVal); Local genObjectRef = JSNApiHelper::ToLocal(genObjTagHandleVal); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(genObjectRef->IsGeneratorObject()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsGeneratorObject); } HWTEST_F_L0(JSNApiSplTest, IsGeneratorObject_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsGeneratorObject()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsGeneratorObject); } HWTEST_F_L0(JSNApiSplTest, IsJSPrimitiveSymbol_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_FALSE(object->IsJSPrimitiveSymbol()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSPrimitiveSymbol); } HWTEST_F_L0(JSNApiSplTest, IsAsyncGeneratorObject_True) { LocalScope scope(vm_); CalculateForTime(); auto factory = vm_->GetFactory(); auto env = vm_->GetGlobalEnv(); JSHandle asyncGenObj = factory->NewJSAsyncGeneratorObject(env->GetAsyncGeneratorFunctionFunction()); JSHandle genObjTagHandleVal = JSHandle::Cast(asyncGenObj); Local genObjectRef = JSNApiHelper::ToLocal(genObjTagHandleVal); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ASSERT_TRUE(genObjectRef->IsAsyncGeneratorObject()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsAsyncGeneratorObject); } HWTEST_F_L0(JSNApiSplTest, IsAsyncGeneratorObject_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsAsyncGeneratorObject(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsAsyncGeneratorObject); } HWTEST_F_L0(JSNApiSplTest, IsModuleNamespaceObject_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSHandle moduleNamespace = factory->NewModuleNamespace(); JSHandle modname = JSHandle::Cast(moduleNamespace); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(modname)->IsModuleNamespaceObject(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsModuleNamespaceObject); } HWTEST_F_L0(JSNApiSplTest, IsModuleNamespaceObject_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsModuleNamespaceObject(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsModuleNamespaceObject); } HWTEST_F_L0(JSNApiSplTest, IsSharedArrayBuffer_True) { LocalScope scope(vm_); CalculateForTime(); auto *factory = vm_->GetFactory(); int32_t num = 40; // 40 = ArrayBuffer length JSHandle jsArrayBuffer = factory->NewJSSharedArrayBuffer(num); JSHandle SAbuffer = JSHandle::Cast(jsArrayBuffer); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(SAbuffer)->IsSharedArrayBuffer(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsSharedArrayBuffer); } HWTEST_F_L0(JSNApiSplTest, IsSharedArrayBuffer_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsSharedArrayBuffer(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsSharedArrayBuffer); } HWTEST_F_L0(JSNApiSplTest, IsStrictEquals_True) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); Local object2 = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsStrictEquals(vm_, object2); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsStrictEquals); } HWTEST_F_L0(JSNApiSplTest, IsStrictEquals_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); Local target1 = StringRef::NewFromUtf8(vm_, "1"); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsStrictEquals(vm_, target1); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsStrictEquals); } HWTEST_F_L0(JSNApiSplTest, IsQueue_Frue) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSThread *thread = vm_->GetJSThread(); JSHandle proto = thread->GetEcmaVM()->GetGlobalEnv()->GetFunctionPrototype(); JSHandle queueClass = factory->NewEcmaHClass(JSAPIQueue::SIZE, JSType::JS_API_QUEUE, proto); JSHandle jsQueue = JSHandle::Cast(factory->NewJSObjectWithInit(queueClass)); JSHandle newElements = factory->NewTaggedArray(JSAPIQueue::DEFAULT_CAPACITY_LENGTH); jsQueue->SetLength(thread, JSTaggedValue(0)); jsQueue->SetFront(0); jsQueue->SetTail(0); jsQueue->SetElements(thread, newElements); JSHandle Que = JSHandle::Cast(jsQueue); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(Que)->IsDeque(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsQueue); } HWTEST_F_L0(JSNApiSplTest, IsQueue_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsQueue(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsQueue); } HWTEST_F_L0(JSNApiSplTest, IsStack_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSThread *thread = vm_->GetJSThread(); JSHandle proto = thread->GetEcmaVM()->GetGlobalEnv()->GetFunctionPrototype(); JSHandle stackClass = factory->NewEcmaHClass(JSAPIStack::SIZE, JSType::JS_API_STACK, proto); JSHandle jsStack = JSHandle::Cast(factory->NewJSObjectWithInit(stackClass)); jsStack->SetTop(0); JSHandle stcak = JSHandle::Cast(jsStack); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(stcak)->IsStack(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsStack); } HWTEST_F_L0(JSNApiSplTest, IsStack_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsStack(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsStack); } HWTEST_F_L0(JSNApiSplTest, IsTreeMap_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSThread *thread = vm_->GetJSThread(); auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetObjectFunctionPrototype(); JSHandle mapClass = factory->NewEcmaHClass(JSAPITreeMap::SIZE, JSType::JS_API_TREE_MAP, proto); JSHandle jsTreeMap = JSHandle::Cast(factory->NewJSObjectWithInit(mapClass)); JSHandle treeMap(thread, TaggedTreeMap::Create(thread)); jsTreeMap->SetTreeMap(thread, treeMap); JSHandle treapp = JSHandle::Cast(jsTreeMap); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(treapp)->IsTreeMap(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsTreeMap); } HWTEST_F_L0(JSNApiSplTest, IsTreeMap_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsTreeMap(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsTreeMap); } HWTEST_F_L0(JSNApiSplTest, IsTreeSet_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSThread *thread = vm_->GetJSThread(); auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle proto = globalEnv->GetObjectFunctionPrototype(); JSHandle setClass = factory->NewEcmaHClass(JSAPITreeSet::SIZE, JSType::JS_API_TREE_SET, proto); JSHandle jsTreeSet = JSHandle::Cast(factory->NewJSObjectWithInit(setClass)); JSHandle treeSet(thread, TaggedTreeSet::Create(thread)); jsTreeSet->SetTreeSet(thread, treeSet); JSHandle tresett = JSHandle::Cast(jsTreeSet); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(tresett)->IsTreeSet(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsTreeSet); } HWTEST_F_L0(JSNApiSplTest, IsTreeSet_False) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object->IsTreeSet(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsTreeSet); } HWTEST_F_L0(JSNApiSplTest, IsVector_True) { LocalScope scope(vm_); CalculateForTime(); ObjectFactory *factory = vm_->GetFactory(); JSThread *thread = vm_->GetJSThread(); JSHandle proto = thread->GetEcmaVM()->GetGlobalEnv()->GetFunctionPrototype(); JSHandle vectorClass = factory->NewEcmaHClass(JSAPIVector::SIZE, JSType::JS_API_VECTOR, proto); JSHandle jsVector = JSHandle::Cast(factory->NewJSObjectWithInit(vectorClass)); jsVector->SetLength(0); JSHandle vectt = JSHandle::Cast(jsVector); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApiHelper::ToLocal(vectt)->IsVector(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsVector); } HWTEST_F_L0(JSNApiSplTest, Parse_False) { LocalScope scope(vm_); CalculateForTime(); const char16_t *utf16 = u"您好,华为!"; Local str = StringRef::NewFromUtf8(vm_, "abc"); Local str2 = StringRef::NewFromUtf16(vm_, utf16); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSON::Parse(vm_, str); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Parse); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSON::Parse(vm_, str2); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Parse); } HWTEST_F_L0(JSNApiSplTest, Stringify) { LocalScope scope(vm_); CalculateForTime(); Local object = ObjectRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSON::Stringify(vm_, object); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Stringify); } HWTEST_F_L0(JSNApiSplTest, Error) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Exception::Error(vm_, StringRef::NewFromUtf8(vm_, "test error")); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Error); } HWTEST_F_L0(JSNApiSplTest, RangeError) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Exception::RangeError(vm_, StringRef::NewFromUtf8(vm_, "test range error")); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::RangeError); } HWTEST_F_L0(JSNApiSplTest, ReferenceError) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Exception::ReferenceError(vm_, StringRef::NewFromUtf8(vm_, "test reference error")); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ReferenceError); } HWTEST_F_L0(JSNApiSplTest, SyntaxError) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Exception::SyntaxError(vm_, StringRef::NewFromUtf8(vm_, "test syntax error")); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::SyntaxError); } HWTEST_F_L0(JSNApiSplTest, TypeError) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Exception::TypeError(vm_, StringRef::NewFromUtf8(vm_, "test type error")); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::TypeError); } HWTEST_F_L0(JSNApiSplTest, AggregateError) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Exception::AggregateError(vm_, StringRef::NewFromUtf8(vm_, "test aggregate error")); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::AggregateError); } HWTEST_F_L0(JSNApiSplTest, EvalError) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Exception::EvalError(vm_, StringRef::NewFromUtf8(vm_, "test eval error")); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::EvalError); } HWTEST_F_L0(JSNApiSplTest, OOMError) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (void)Exception::OOMError(vm_, StringRef::NewFromUtf8(vm_, "test out of memory error")); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::OOMError); } HWTEST_F_L0(JSNApiSplTest, CreateEcmaVM) { LocalScope scope(vm_); CalculateForTime(); JSRuntimeOptions option; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { EcmaVM *workerVm = JSNApi::CreateEcmaVM(option); JSNApi::DestroyJSVM(workerVm); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::CreateEcmaVM); } HWTEST_F_L0(JSNApiSplTest, PostFork) { LocalScope scope(vm_); CalculateForTime(); RuntimeOption option; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::PostFork(vm_, option); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::PostFork); } HWTEST_F_L0(JSNApiSplTest, AddWorker) { LocalScope scope(vm_); CalculateForTime(); JSRuntimeOptions option; gettimeofday(&g_beginTime, nullptr); EcmaVM *workerVm = JSNApi::CreateEcmaVM(option); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::AddWorker(vm_, workerVm); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::addWorker); JSNApi::DestroyJSVM(workerVm); } HWTEST_F_L0(JSNApiSplTest, DeleteWorker) { LocalScope scope(vm_); CalculateForTime(); JSRuntimeOptions option; EcmaVM *workerVm = JSNApi::CreateEcmaVM(option); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::AddWorker(vm_, workerVm); JSNApi::DeleteWorker(vm_, workerVm); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::DeleteWorker); JSNApi::DestroyJSVM(workerVm); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBundle) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::IsBundle(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsBundle); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_SetBundle) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::SetBundle(vm_, false); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::SetBundle); } HWTEST_F_L0(JSNApiSplTest, JSNApi_SetAssetPath) { LocalScope scope(vm_); CalculateForTime(); std::string str = "11"; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::SetAssetPath(vm_, str); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::SetAssetPath); } HWTEST_F_L0(JSNApiSplTest, JSNApi_GetAssetPath) { LocalScope scope(vm_); CalculateForTime(); std::string str = "11"; gettimeofday(&g_beginTime, nullptr); JSNApi::SetAssetPath(vm_, str); for (int i = 0; i < NUM_COUNT; i++) { std::string res = JSNApi::GetAssetPath(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::GetAssetPath); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_SetBundleName) { LocalScope scope(vm_); CalculateForTime(); std::string str = "11"; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::SetBundleName(vm_, str); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::SetBundleName); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_GetBundleName) { LocalScope scope(vm_); CalculateForTime(); std::string str = "11"; JSNApi::SetBundleName(vm_, str); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { std::string res = JSNApi::GetBundleName(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::GetBundleName); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_GetModuleName) { LocalScope scope(vm_); CalculateForTime(); std::string str = "11"; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::SetModuleName(vm_, str); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::SetModuleName); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_SetModuleName) { LocalScope scope(vm_); CalculateForTime(); std::string str = "11"; JSNApi::SetModuleName(vm_, str); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { std::string res = JSNApi::GetModuleName(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::GetModuleName); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_SetLoop) { LocalScope scope(vm_); CalculateForTime(); void *data = reinterpret_cast(BuiltinsFunction::FunctionPrototypeInvokeSelf); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::SetLoop(vm_, data); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::SetLoop); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_InitForConcurrentFunction) { LocalScope scope(vm_); CalculateForTime(); Deleter deleter = nullptr; void *cb = reinterpret_cast(BuiltinsFunction::FunctionPrototypeInvokeSelf); bool callNative = true; size_t nativeBindingsize = 15; Local res = FunctionRef::NewClassFunction(vm_, FunCallback, deleter, cb, callNative, nativeBindingsize); ASSERT_TRUE(res->IsFunction()); Local res1 = res->GetFunctionPrototype(vm_); void *taskInfo = nullptr; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::InitForConcurrentFunction(vm_, res1, taskInfo); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::InitForConcurrentFunction); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_Rethrow) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { TryCatch tryCatch(vm_); tryCatch.Rethrow(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Rethrow); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_InitForConcurrentThread) { LocalScope scope(vm_); CalculateForTime(); void *data = reinterpret_cast(BuiltinsFunction::FunctionPrototypeInvokeSelf); ConcurrentCallback concurrentCallback_ { nullptr }; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSNApi::InitForConcurrentThread(vm_, concurrentCallback_, data); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::InitForConcurrentThread); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_JsiRuntimeCallInfo) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JsiRuntimeCallInfo(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::JsiRuntimeCallInfo); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_GetThread) { LocalScope scope(vm_); CalculateForTime(); JsiRuntimeCallInfo object; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.GetThread(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::GetThread); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_GetArgsNumber) { LocalScope scope(vm_); CalculateForTime(); JsiRuntimeCallInfo object; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { object.GetArgsNumber(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::GetArgsNumber); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_HasCaught_True) { LocalScope scope(vm_); CalculateForTime(); Local message = StringRef::NewFromUtf8(vm_, "ErrorTest"); Local error = Exception::Error(vm_, message); JSNApi::ThrowException(vm_, error); TryCatch tryCatch(vm_); ASSERT_TRUE(tryCatch.HasCaught()); vm_->GetJSThread()->ClearException(); JSNApi::ThrowException(vm_, error); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { tryCatch.HasCaught(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::HasCaught); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_HasCaught_False) { LocalScope scope(vm_); CalculateForTime(); Local message = StringRef::NewFromUtf8(vm_, "ErrorTest"); Local error = Exception::Error(vm_, message); JSNApi::ThrowException(vm_, error); TryCatch tryCatch(vm_); tryCatch.GetAndClearException(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { tryCatch.HasCaught(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::HasCaught); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_Undefined) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number uint64_t maxUint64 = std::numeric_limits::max(); bool inputBool = true; std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local resBool = BooleanRef::New(vm_, inputBool); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->Undefined(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Undefined::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->Undefined(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Undefined::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->Undefined(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Undefined::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resBool->Undefined(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Undefined::BooleanRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->Undefined(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Undefined::StringRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSValueRef::Undefined(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Undefined); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_Null) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number uint64_t maxUint64 = std::numeric_limits::max(); bool inputBool = true; std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local resBool = BooleanRef::New(vm_, inputBool); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->Null(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Null::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->Null(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Null::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->Null(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Null::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resBool->Null(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Null::BooleanRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->Null(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Null::StringRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSValueRef::Null(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::Null); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_True) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number uint64_t maxUint64 = std::numeric_limits::max(); bool inputBool = true; std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local resBool = BooleanRef::New(vm_, inputBool); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->True(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::True::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->True(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::True::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->True(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::True::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resBool->True(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::True::BooleanRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->True(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::True::StringRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSValueRef::True(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::True); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToBoolean) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number uint64_t maxUint64 = std::numeric_limits::max(); bool inputBool = true; std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local resBool = BooleanRef::New(vm_, inputBool); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->ToBoolean(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToBoolean::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->ToBoolean(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToBoolean::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->ToBoolean(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToBoolean::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resBool->ToBoolean(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToBoolean::BooleanRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->ToBoolean(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToBoolean::StringRef); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToObject) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number uint64_t maxUint64 = std::numeric_limits::max(); bool inputBool = true; std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local resBool = BooleanRef::New(vm_, inputBool); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->ToObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToObject::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->ToObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToObject::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->ToObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToObject::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resBool->ToObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToObject::BooleanRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->ToObject(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToObject::StringRef); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_ToString) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number uint64_t maxUint64 = std::numeric_limits::max(); bool inputBool = true; std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local resBool = BooleanRef::New(vm_, inputBool); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->ToString(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToString::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->ToString(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToString::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->ToString(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToString::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resBool->ToString(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToString::BooleanRef); Local toTarget(stringUtf8); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { toTarget->ToString(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::ToString::StringRef); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsFalse) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number uint64_t maxUint64 = std::numeric_limits::max(); bool inputBool = false; std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local resBool = BooleanRef::New(vm_, inputBool); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->IsFalse(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsFalse::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->IsFalse(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsFalse::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->IsFalse(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsFalse::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resBool->IsFalse(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsFalse::BooleanRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->IsFalse(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsFalse::StringRef); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsNumber) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number uint64_t maxUint64 = std::numeric_limits::max(); bool inputBool = true; std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local resBool = BooleanRef::New(vm_, inputBool); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->IsNumber(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsNumber::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->IsNumber(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsNumber::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->IsNumber(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsNumber::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resBool->IsNumber(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsNumber::BooleanRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->IsNumber(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsNumber::StringRef); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBigInt) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number uint64_t maxUint64 = std::numeric_limits::max(); int64_t maxInt64 = std::numeric_limits::max(); Local intValue = IntegerRef::New(vm_, 2147483646); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local resUnit64 = NumberRef::New(vm_, maxInt64); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local maxBigintInt64 = BigIntRef::New(vm_, maxInt64); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->IsBigInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsBigInt::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->IsBigInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsBigInt::NumberRef32); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit64->IsBigInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsBigInt::NumberRef64); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->IsBigInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsBigInt::BigIntRefU64); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintInt64->IsBigInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsBigInt::BigIntRefI64); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsBigInt2) { LocalScope scope(vm_); CalculateForTime(); bool inputBool = true; std::string testUtf8 = "Hello world"; Local resBool = BooleanRef::New(vm_, inputBool); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resBool->IsBigInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsBigInt::BooleanRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->IsBigInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsBigInt::StringRef); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArray) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->IsArray(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsArray::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->IsArray(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsArray::NumberRef); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsArray2) { LocalScope scope(vm_); CalculateForTime(); int num = 3; // 3 = ArrayBuffer Length uint64_t maxUint64 = std::numeric_limits::max(); std::string testUtf8 = "Hello world"; Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); Local arrayObject = ArrayRef::New(vm_, num); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->IsArray(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsArray::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->IsArray(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsArray::StringRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { arrayObject->IsArray(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsArray::ArrayRef); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSArray) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number int length = 3; // 3 = ArrayBuffer Length uint64_t maxUint64 = std::numeric_limits::max(); std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); Local arrayObject = ArrayRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->IsJSArray(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSArray::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->IsJSArray(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSArray::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->IsJSArray(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSArray::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->IsJSArray(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSArray::StringRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { arrayObject->IsJSArray(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSArray::ArrayRef); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsJSArray2) { LocalScope scope(vm_); CalculateForTime(); JSArray *arr = JSArray::ArrayCreate(thread_, JSTaggedNumber(0)).GetObject(); JSHandle obj(thread_, arr); Local JSArrayObject = JSNApiHelper::ToLocal(obj); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSArrayObject->IsJSArray(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsJSArray::JSArrayObject); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsConstructor) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->IsConstructor(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsConstructor::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->IsConstructor(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsConstructor::NumberRef); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsConstructor2) { LocalScope scope(vm_); CalculateForTime(); uint64_t maxUint64 = std::numeric_limits::max(); std::string testUtf8 = "Hello world"; Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); EcmaVM *ecmaVM = thread_->GetEcmaVM(); JSHandle env = ecmaVM->GetGlobalEnv(); JSHandle func = thread_->GetEcmaVM()->GetFactory()->NewJSFunction(env, static_cast(nullptr), FunctionKind::BASE_CONSTRUCTOR); JSHandle nullHandle(thread_, JSTaggedValue::Null()); JSHandle obj = JSObject::ObjectCreate(thread_, nullHandle); JSHandle objValue(obj); [[maybe_unused]] bool makeConstructor = JSFunction::MakeConstructor(thread_, func, objValue); JSHandle funcHandle(func); Local funConstructor = JSNApiHelper::ToLocal(funcHandle); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->IsConstructor(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsConstructor::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->IsConstructor(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsConstructor::StringRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { funConstructor->IsConstructor(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsConstructor::funConstructor); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsDate) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number uint64_t maxUint64 = std::numeric_limits::max(); std::string testUtf8 = "Hello world"; double timeRef = 1.1; // 1.1 = random number Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); Local dateRef = DateRef::New(vm_, timeRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->IsDate(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsDate::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->IsDate(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsDate::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->IsDate(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsDate::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->IsDate(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsDate::StringRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { dateRef->IsDate(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsDate::DateRef); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsError) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number uint64_t maxUint64 = std::numeric_limits::max(); std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); Local message = StringRef::NewFromUtf8(vm_, "ErrorTest"); Local error = Exception::Error(vm_, message); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->IsError(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsError::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->IsError(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsError::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->IsError(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsError::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->IsError(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsError::StringRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { error->IsError(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsError::Exception::Error); } HWTEST_F_L0(JSNApiSplTest, JSValueRef_IsMap) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 0; // 0 = random number uint64_t maxUint64 = std::numeric_limits::max(); std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); Local mapRef = MapRef::New(vm_); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->IsMap(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsMap::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->IsMap(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsMap::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->IsMap(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsMap::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->IsMap(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsMap::StringRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { mapRef->IsMap(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(JSValueRef::IsMap::MapRef); } HWTEST_F_L0(JSNApiSplTest, Local_operator01) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 13; // 13 = random number int length = 3; // 3 = ArrayBufer length uint64_t maxUint64 = std::numeric_limits::max(); std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); Local arrayObject = ArrayRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local integerVaule(intValue); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::Operator::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local NumberVaule(resUnit32); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::Operator::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local bigIntVaule(maxBigintUint64); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::Operator::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local stringVaule(stringUtf8); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::Operator::StringRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local arrayVaule(arrayObject); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::Operator::ArrayRef); } HWTEST_F_L0(JSNApiSplTest, Local_operator02) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 13; // 13 = random number int length = 3; // 3 = ArrayBufer length uint64_t maxUint64 = std::numeric_limits::max(); std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); Local arrayObject = ArrayRef::New(vm_, length); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue->IsNull(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::Operator2::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32->IsNull(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::Operator2::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->IsNull(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::Operator2::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8->IsNull(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::Operator2::StringRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { arrayObject->IsNull(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::Operator2::ArrayRef); } HWTEST_F_L0(JSNApiSplTest, Local_IsEmpty) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number int num = 13; // 13 = random number uint64_t maxUint64 = std::numeric_limits::max(); std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, num); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); Local JSvalue; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue.IsEmpty(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::IsEmpty::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { resUnit32.IsEmpty(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::IsEmpty::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64.IsEmpty(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::IsEmpty::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { stringUtf8.IsEmpty(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::IsEmpty::StringRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSvalue.IsEmpty(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::IsEmpty); } HWTEST_F_L0(JSNApiSplTest, Local_IsNull) { LocalScope scope(vm_); CalculateForTime(); int num = 13; // 13 = random number Local intValue = IntegerRef::New(vm_, num); Local JSvalue; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { intValue.IsNull(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::IsNull::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { JSvalue.IsNull(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(Local::IsNull); } HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_ToLocal) { LocalScope scope(vm_); CalculateForTime(); int num = 13; // 13 = random number Local intValue = IntegerRef::New(vm_, num); CopyableGlobal copyGlobal(vm_, intValue); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobal.ToLocal(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::ToLocal); } HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_Empty) { LocalScope scope(vm_); CalculateForTime(); int num = 13; // 13 = random number Local intValue = IntegerRef::New(vm_, num); CopyableGlobal copyGlobal(vm_, intValue); EXPECT_FALSE(copyGlobal.IsEmpty()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobal.Empty(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::Empty); EXPECT_TRUE(copyGlobal.IsEmpty()); } HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_operator) { LocalScope scope(vm_); CalculateForTime(); int num = 13; // 13 = random number Local intValue = IntegerRef::New(vm_, num); CopyableGlobal copyGlobal(vm_, intValue); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { (*copyGlobal)->IsInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::Operator); EXPECT_TRUE((*copyGlobal)->IsInt()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobal->IsInt(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::Operator2); EXPECT_TRUE(copyGlobal->IsInt()); } HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_IsEmpty) { LocalScope scope(vm_); CalculateForTime(); std::string testUtf8 = "Hello world"; int num = 13; // 13 = random number Local intValue = IntegerRef::New(vm_, num); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); CopyableGlobal copyGlbString(vm_, stringUtf8); CopyableGlobal copyGlobal(vm_, intValue); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlbString.IsEmpty(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::IsEmpty::StringRef::first); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobal.IsEmpty(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::IsEmpty::IntegerRef); copyGlbString.Empty(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlbString.IsEmpty(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::IsEmpty::StringRef::Second); } HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_SetWeak_IsWeak_ClearWeak) { LocalScope scope(vm_); CalculateForTime(); std::string testUtf8 = "Hello world"; Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); CopyableGlobal copyGlobalback(vm_, stringUtf8); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobalback.IsWeak(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::IsWeak::First); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobalback.SetWeak(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::SetWeak); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobalback.IsWeak(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::IsWeak::Second); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobalback.ClearWeak(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::ClearWeak); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobalback.IsWeak(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::IsWeak::three); } HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_SetWeakCallback) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number uint64_t maxUint64 = std::numeric_limits::max(); double doubleSize = 1.1; // 1.1 = random number long longSize = 123456; // 123456 = random number std::string testUtf8 = "Hello world"; Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); CopyableGlobal copyGlobalStr(vm_, stringUtf8); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobalStr.SetWeakCallback(&inputUnit32, FreeGlobalCallBack, NativeFinalizeCallback); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::SetWeakCallback::Uint32); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobalStr.SetWeakCallback(&maxUint64, FreeGlobalCallBack, NativeFinalizeCallback); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::SetWeakCallback::Uint64); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobalStr.SetWeakCallback(&doubleSize, FreeGlobalCallBack, NativeFinalizeCallback); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::SetWeakCallback::Double); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobalStr.SetWeakCallback(&longSize, FreeGlobalCallBack, NativeFinalizeCallback); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::SetWeakCallback::Long); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobalStr.SetWeakCallback(&testUtf8, FreeGlobalCallBack, NativeFinalizeCallback); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::SetWeakCallback::String); } HWTEST_F_L0(JSNApiSplTest, BigIntRef_New) { LocalScope scope(vm_); CalculateForTime(); uint64_t maxUint64 = std::numeric_limits::max(); uint64_t minUint64 = std::numeric_limits::min(); int64_t maxInt64 = std::numeric_limits::max(); int64_t minInt64 = std::numeric_limits::min(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { BigIntRef::New(vm_, maxUint64); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BigIntRef::New::Uint64::Max); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { BigIntRef::New(vm_, minUint64); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BigIntRef::New::Uint64::Min); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { BigIntRef::New(vm_, maxInt64); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BigIntRef::New::Int64::Max); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { BigIntRef::New(vm_, minInt64); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BigIntRef::New::Int64::Min); } HWTEST_F_L0(JSNApiSplTest, BigIntRef_CreateBigWords) { LocalScope scope(vm_); CalculateForTime(); bool sign = false; uint32_t size = 3; // 3 = random number const uint64_t words[3] = { std::numeric_limits::min() - 1, std::numeric_limits::min(), std::numeric_limits::max(), }; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { BigIntRef::CreateBigWords(vm_, sign, size, words); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BigIntRef::CreateBigWords); } HWTEST_F_L0(JSNApiSplTest, BigIntRef_GetWordsArraySize) { LocalScope scope(vm_); CalculateForTime(); bool sign = false; uint32_t size = 3; // 3 = random number const uint64_t words[3] = { std::numeric_limits::min() - 1, std::numeric_limits::min(), std::numeric_limits::max(), }; Local bigWords = BigIntRef::CreateBigWords(vm_, sign, size, words); Local bigWordsRef(bigWords); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bigWordsRef->GetWordsArraySize(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BigIntRef::GetWordsArraySize); } HWTEST_F_L0(JSNApiSplTest, BigIntRef_GetWordsArray) { LocalScope scope(vm_); CalculateForTime(); bool sign = false; uint32_t size = 3; // 3 = random number const uint64_t words[3] = { std::numeric_limits::min() - 1, std::numeric_limits::min(), std::numeric_limits::max(), }; Local bigWords = BigIntRef::CreateBigWords(vm_, sign, size, words); Local bigWordsRef(bigWords); bool resultSignBit = true; uint64_t *resultWords = new uint64_t[3](); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { bigWordsRef->GetWordsArray(&resultSignBit, size, resultWords); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BigIntRef::GetWordsArray::Uint64); } HWTEST_F_L0(JSNApiSplTest, BigIntRef_BigIntToInt64) { LocalScope scope(vm_); CalculateForTime(); uint64_t maxUint64 = std::numeric_limits::max(); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); int64_t toNum; bool lossless = true; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->BigIntToInt64(vm_, &toNum, &lossless); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BigIntRef::BigIntToInt64); } HWTEST_F_L0(JSNApiSplTest, BigIntRef_BigIntToUint64) { LocalScope scope(vm_); CalculateForTime(); uint64_t maxUint64 = std::numeric_limits::max(); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); uint64_t toNum; bool lossless = true; gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { maxBigintUint64->BigIntToUint64(vm_, &toNum, &lossless); } gettimeofday(&g_endTime, nullptr); TEST_TIME(BigIntRef::BigIntToUint64); } HWTEST_F_L0(JSNApiSplTest, SymbolRef_New) { LocalScope scope(vm_); CalculateForTime(); std::string testUtf8 = "Hello world"; Local description = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { SymbolRef::New(vm_, description); } gettimeofday(&g_endTime, nullptr); TEST_TIME(SymbolRef::New::StringRef); } HWTEST_F_L0(JSNApiSplTest, SymbolRef_GetDescription) { LocalScope scope(vm_); CalculateForTime(); std::string testUtf8 = "Hello world"; Local description = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); Local symbol = SymbolRef::New(vm_, description); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { symbol->GetDescription(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(SymbolRef::GetDescription); } HWTEST_F_L0(JSNApiSplTest, NativePointerRef_New) { LocalScope scope(vm_); CalculateForTime(); void *vps = static_cast(new std::string("test")); void *vpd = new double(123.456); void *vpc = new char('a'); void *vpl = new long(123456); void *vpi = new int(123); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NativePointerRef::New(vm_, vps); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::New::String); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NativePointerRef::New(vm_, vpd); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::New::Double); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NativePointerRef::New(vm_, vpc); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::New::Char); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NativePointerRef::New(vm_, vpl); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::New::Long); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NativePointerRef::New(vm_, vpi); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::New::Int); } HWTEST_F_L0(JSNApiSplTest, NativePointerRef_New_Fun) { LocalScope scope(vm_); CalculateForTime(); NativePointerCallback callBack = nullptr; void *vps = static_cast(new std::string("test")); void *vps1 = static_cast(new std::string("test")); void *vpd = new double(123.456); void *vpd1 = new double(123.456); void *vpc = new char('a'); void *vpc1 = new char('e'); void *vpl = new long(123456); void *vpl1 = new long(123456); void *vpi = new int(123); void *vpi1 = new int(123); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NativePointerRef::New(vm_, vps, callBack, vps1, 0); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::New::Fun::String); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NativePointerRef::New(vm_, vpd, callBack, vpd1, 0); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::New::Fun::Double); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NativePointerRef::New(vm_, vpc, callBack, vpc1, 0); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::New::Fun::Char); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NativePointerRef::New(vm_, vpl, callBack, vpl1, 0); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::New::Fun::Long); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { NativePointerRef::New(vm_, vpi, callBack, vpi1, 0); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::New::Fun::Int); } HWTEST_F_L0(JSNApiSplTest, NativePointerRef_Value) { LocalScope scope(vm_); CalculateForTime(); void *vps = static_cast(new std::string("test")); void *vps1 = static_cast(new std::string("test")); void *vpd = new double(123.456); void *vpd1 = new double(123.456); void *vpc = new char('a'); void *vpc1 = new char('c'); void *vpl = new long(123456); void *vpl1 = new long(123456); void *vpi = new int(123); void *vpi1 = new int(123); Local res_vps = NativePointerRef::New(vm_, vps, NativeAreaAllocator::FreeBufferFunc, vps1, 0); Local res_vpd = NativePointerRef::New(vm_, vpd, NativeAreaAllocator::FreeBufferFunc, vpd1, 0); Local res_vpc = NativePointerRef::New(vm_, vpc, NativeAreaAllocator::FreeBufferFunc, vpc1, 0); Local res_vpl = NativePointerRef::New(vm_, vpl, NativeAreaAllocator::FreeBufferFunc, vpl1, 0); Local res_vpi = NativePointerRef::New(vm_, vpi, NativeAreaAllocator::FreeBufferFunc, vpi1, 0); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res_vps->Value(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::Value::String); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res_vpd->Value(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::Value::Double); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res_vpc->Value(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::Value::Char); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res_vpl->Value(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::Value::Long); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res_vpi->Value(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(NativePointerRef::Value::Int); } HWTEST_F_L0(JSNApiSplTest, FunctionRef_New) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { FunctionRef::New(vm_, FunCallback); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionRef::New); } HWTEST_F_L0(JSNApiSplTest, FunctionRef_NewClassFunction) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { FunctionRef::NewClassFunction(vm_, FunCallback, nullptr, nullptr); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionRef::NewClassFunction); } HWTEST_F_L0(JSNApiSplTest, FunctionRef_Call) { LocalScope scope(vm_); CalculateForTime(); uint32_t inputUnit32 = 32; // 32 = random number uint64_t maxUint64 = std::numeric_limits::max(); Local intValue = IntegerRef::New(vm_, 0); Local targetBool = BooleanRef::New(vm_, false); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); std::vector> argumentsInt; std::vector> argumentsBool; std::vector> argumentsNum; std::vector> argumentsBig; argumentsInt.emplace_back(intValue); argumentsBool.emplace_back(targetBool); argumentsNum.emplace_back(resUnit32); argumentsBig.emplace_back(maxBigintUint64); Local callback = FunctionRef::New(vm_, FunCallback); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { callback->Call(vm_, JSValueRef::Undefined(vm_), argumentsInt.data(), argumentsInt.size()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionRef::Call::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { callback->Call(vm_, JSValueRef::Undefined(vm_), argumentsBool.data(), argumentsBool.size()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionRef::Call::BooleanRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { callback->Call(vm_, JSValueRef::Undefined(vm_), argumentsNum.data(), argumentsNum.size()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionRef::Call::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { callback->Call(vm_, JSValueRef::Undefined(vm_), argumentsBig.data(), argumentsBig.size()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionRef::Call::BigIntRef); } HWTEST_F_L0(JSNApiSplTest, FunctionRef_Call2) { LocalScope scope(vm_); CalculateForTime(); std::string testUtf8 = "Hello world"; Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); std::vector> argumentsStr; argumentsStr.emplace_back(stringUtf8); Local callback = FunctionRef::New(vm_, FunCallback); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { callback->Call(vm_, JSValueRef::Undefined(vm_), argumentsStr.data(), argumentsStr.size()); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionRef::Call::StringRef); } HWTEST_F_L0(JSNApiSplTest, FunctionRef_Constructor) { LocalScope scope(vm_); CalculateForTime(); Local cls = FunctionRef::NewClassFunction(vm_, FunCallback, nullptr, nullptr); Local argv[1]; // 1 = Array Size int num = 13; // 13 = random number argv[0] = NumberRef::New(vm_, num); // 0 = The first element gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { cls->Constructor(vm_, argv, 1); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionRef::Constructor); } HWTEST_F_L0(JSNApiSplTest, FunctionRef_GetFunctionPrototype) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = vm_->GetGlobalEnv(); JSHandle set = env->GetBuiltinsSetFunction(); Local setLocal = JSNApiHelper::ToLocal(set); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { [[maybe_unused]] Local funcProtoType = setLocal->GetFunctionPrototype(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionRef::GetFunctionPrototype); } HWTEST_F_L0(JSNApiSplTest, FunctionRef_Inherit) { LocalScope scope(vm_); CalculateForTime(); JSHandle env = vm_->GetGlobalEnv(); JSHandle set = env->GetBuiltinsSetFunction(); Local setLocal = JSNApiHelper::ToLocal(set); JSHandle map = env->GetBuiltinsMapFunction(); Local mapLocal = JSNApiHelper::ToLocal(map); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { mapLocal->Inherit(vm_, setLocal); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionRef::Inherit); } HWTEST_F_L0(JSNApiSplTest, FunctionRef_SetName) { LocalScope scope(vm_); CalculateForTime(); Local res = FunctionRef::NewClassFunction(vm_, FunCallback, nullptr, nullptr); Local origin = StringRef::NewFromUtf8(vm_, "origin test"); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->SetName(vm_, origin); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionRef::SetName); } HWTEST_F_L0(JSNApiSplTest, FunctionRef_GetName) { LocalScope scope(vm_); CalculateForTime(); Local res = FunctionRef::NewClassFunction(vm_, FunCallback, nullptr, nullptr); Local origin = StringRef::NewFromUtf8(vm_, "origin test"); res->SetName(vm_, origin); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->GetName(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionRef::GetName); } HWTEST_F_L0(JSNApiSplTest, FunctionRef_IsNative) { LocalScope scope(vm_); CalculateForTime(); Local res = FunctionRef::NewClassFunction(vm_, FunCallback, nullptr, nullptr); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { res->IsNative(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(FunctionRef::IsNative); } HWTEST_F_L0(JSNApiSplTest, ArrayRef_New) { LocalScope scope(vm_); CalculateForTime(); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { Local arrayObj = ArrayRef::New(vm_, 3); EXPECT_TRUE(arrayObj->IsArray(vm_)); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayRef::New); } HWTEST_F_L0(JSNApiSplTest, ArrayRef_Length) { LocalScope scope(vm_); CalculateForTime(); Local arrayObj = ArrayRef::New(vm_, 3); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { arrayObj->Length(vm_); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayRef::Length); } HWTEST_F_L0(JSNApiSplTest, ArrayRef_SetValueAt) { LocalScope scope(vm_); CalculateForTime(); Local arrayObj = ArrayRef::New(vm_, 1); uint32_t inputUnit32 = 32; uint64_t maxUint64 = std::numeric_limits::max(); std::string testUtf8 = "Hello world"; Local intValue = IntegerRef::New(vm_, 0); Local targetBool = BooleanRef::New(vm_, false); Local resUnit32 = NumberRef::New(vm_, inputUnit32); Local maxBigintUint64 = BigIntRef::New(vm_, maxUint64); Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ArrayRef::SetValueAt(vm_, arrayObj, 0, intValue); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayRef::SetValueAt::IntegerRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ArrayRef::SetValueAt(vm_, arrayObj, 0, targetBool); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayRef::SetValueAt::BooleanRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ArrayRef::SetValueAt(vm_, arrayObj, 0, resUnit32); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayRef::SetValueAt::NumberRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ArrayRef::SetValueAt(vm_, arrayObj, 0, maxBigintUint64); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayRef::SetValueAt::BigIntRef); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ArrayRef::SetValueAt(vm_, arrayObj, 0, stringUtf8); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayRef::SetValueAt::StringRef); } HWTEST_F_L0(JSNApiSplTest, ArrayRef_GetValueAt) { LocalScope scope(vm_); CalculateForTime(); Local arrayObj = ArrayRef::New(vm_, 1); std::string testUtf8 = "Hello world"; Local stringUtf8 = StringRef::NewFromUtf8(vm_, testUtf8.c_str()); ArrayRef::SetValueAt(vm_, arrayObj, 0, stringUtf8); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { ArrayRef::GetValueAt(vm_, arrayObj, 0); } gettimeofday(&g_endTime, nullptr); TEST_TIME(ArrayRef::GetValueAt::StringRef); } HWTEST_F_L0(JSNApiSplTest, CopyableGlobal_GetEcmaVM) { LocalScope scope(vm_); CalculateForTime(); Local intValue = IntegerRef::New(vm_, 13); CopyableGlobal copyGlobal(vm_, intValue); gettimeofday(&g_beginTime, nullptr); for (int i = 0; i < NUM_COUNT; i++) { copyGlobal.GetEcmaVM(); } gettimeofday(&g_endTime, nullptr); TEST_TIME(CopyableGlobal::GetEcmaVM); } }