• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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('Starting...');
18    let penv = process.env;
19    let stsVm = require(penv.MODULE_PATH + '/ets_interop_js_napi.node');
20
21    const stsRT = stsVm.createRuntime({
22        'boot-panda-files': penv.ARK_ETS_STDLIB_PATH + ':' + penv.ARK_ETS_INTEROP_JS_GTEST_ABC_PATH,
23        'panda-files': penv.ARK_ETS_INTEROP_JS_GTEST_ABC_PATH,
24        'gc-trigger-type': 'heap-trigger',
25        'compiler-enable-jit': 'false',
26        'run-gc-in-place': 'false',
27    });
28
29    if (!stsRT) {
30        console.error('Failed to create ETS runtime');
31        return 1;
32    }
33
34    const iterations = 1000000; // this value worked reasonably well in trial runs
35    const promise = stsVm.getFunction('LETSGLOBAL;', 'promise');
36
37    async function checkPromise() {
38        let start;
39        let loopTime = 0;
40
41        for (let i = 0; i < iterations; i++) {
42            await (() => {
43                console.log(i);
44
45                start = process.hrtime.bigint();
46                return promise();
47            }
48            )().then(() => {
49                loopTime = Number(process.hrtime.bigint() - start);
50            });
51        }
52
53        return loopTime;
54    }
55
56    //NOTE issue(19656) enable this after fix global reference storage
57    if (false) {
58        const timeNs = await checkPromise();
59        console.log('Benchmark result: J2a ' + (timeNs));
60    }
61    return null;
62}
63
64main();
65