Skip to content

Commit

Permalink
hardcode js run code
Browse files Browse the repository at this point in the history
Signed-off-by: Su Yihan <[email protected]>
  • Loading branch information
yviansu committed Mar 7, 2024
1 parent 7359949 commit 2b34e10
Show file tree
Hide file tree
Showing 5 changed files with 561 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ logs
*.log
*.swo
example/app-framework/cmake-build/
example/app-framework/out/
example/app-framework/out/
.vscode/
tests/benchmark/compile_output/
1 change: 1 addition & 0 deletions tests/benchmark/array_access_i32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

type i32 = number;
const size: i32 = 1e4;
const arr = new Array<number>(1e4);
const expect = 49999995000000;
Expand Down
61 changes: 61 additions & 0 deletions tests/benchmark/compile_benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname } from 'path';

const __filename = fileURLToPath(import.meta.url);
const benchmark_dir = dirname(__filename);
const benchmarks = fs.readdirSync(benchmark_dir);
const compile_output_dir = path.join(benchmark_dir, 'compile_output');
const ts2wasm_script = path.join(benchmark_dir, '../../build/cli/ts2wasm.js');
const optimize_level = 3;

let tsc_cmd;
try {
tsc_cmd = execSync('which tsc').toString().trim();
} catch (error) {
if (process.env.TSC_PATH) {
tsc_cmd = process.env.TSC_PATH;
} else {
const default_tsc_path = '/usr/local/bin/tsc';
if (fs.existsSync(default_tsc_path)) {
tsc_cmd = default_tsc_path;
} else {
console.error("Error: TSC_PATH is not defined, and no default node path is provided.");
process.exit(1);
}
}
}

console.log(`\x1b[33m======================== options ========================\x1b[0m`);
console.log(`TSC_PATH: ${tsc_cmd}`);
console.log(`\x1b[33m======================== compiling ========================\x1b[0m`);

for (let benchmark of benchmarks) {
let filename = path.basename(benchmark);
let prefix = path.basename(filename, path.extname(filename));
let extension = path.extname(filename).slice(1);

if (extension != 'ts')
continue;

fs.mkdirSync(compile_output_dir, { recursive: true }, (err) => {
if (err) {
console.error(`Failed to create ${compile_output_dir}:`, err);
}
})

console.log(`Compiling ${prefix} benchmark: `);
execSync(`node ${ts2wasm_script} ${filename} --opt ${optimize_level} --output ${compile_output_dir}/${prefix}.wasm > tmp.txt`);
console.log(` wasm target success`);
execSync(`${tsc_cmd} ${filename} --outDir ${compile_output_dir} -m esnext`);
console.log(` js target success`);
}

execSync(`rm -f tmp.txt`);
Loading

0 comments on commit 2b34e10

Please sign in to comment.