1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16async function main() { 17 console.log('Started...'); 18 const iterations = 1000000; // this value worked reasonably well in trial runs 19 20 const timeNs = await checkPromise(); 21 console.log('Benchmark result: J2j ' + (timeNs)); 22} 23 24async function checkPromise() { 25 let start; 26 let loopTime = 0; 27 28 for (let i = 0; i < iterations; i++) { 29 await (() => { 30 return new Promise((resolve) => { 31 start = process.hrtime.bigint(); 32 resolve(); 33 }); 34 } 35 )().then(() => { 36 loopTime += Number(process.hrtime.bigint() - start); 37 }); 38 } 39 40 return loopTime; 41} 42 43main(); 44