Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hardcode js run code #151

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
14 changes: 6 additions & 8 deletions tests/benchmark/any_basic_type_access.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
"use strict";
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

"use strict";

var size = 1e6;
var val = 0;
var res = 0;
const expect = 499998500001;

function main() {
var size = 1e6;
var val = 0;
var res = 0;
var expect = 499998500001;
for (var i = 0; i < size; i++) {
res += val;
val = i;
Expand All @@ -21,4 +19,4 @@ function main() {
return res;
}

console.log(main());
main()
9 changes: 4 additions & 5 deletions tests/benchmark/any_basic_type_access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

const size = 1e6;
let val: any = 0;
let res = 0;
const expect = 499998500001;

export function main() {
const size = 1e6;
let val: any = 0;
let res = 0;
const expect = 499998500001;
for (let i = 0; i < size; i++) {
res += val;
val = i;
Expand Down
16 changes: 8 additions & 8 deletions tests/benchmark/any_complex_type_access.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
"use strict";
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

"use strict";

var Foo = /** @class */ (function () {
function Foo() {
this.x = 0;
this.y = false;
}
return Foo;
}());
var val = new Foo();
val.z = 0;
var size = 4e5;
var res = 0;
var expect = 159998800002;
function main() {
var val = new Foo();
val.z = 0;
var size = 4e5;
var res = 0;
var expect = 159998800002;
for (var i = 0; i < size; i++) {
res += val.x;
val.x = i;
Expand All @@ -29,4 +28,5 @@ function main() {
}
return res;
}
console.log(main());

main()
10 changes: 5 additions & 5 deletions tests/benchmark/any_complex_type_access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class Foo {
x = 0;
y = false;
}
const val: any = new Foo();
val.z = 0;
const size = 4e5;
let res = 0;
const expect = 159998800002;

export function main() {
const val: any = new Foo();
val.z = 0;
const size = 4e5;
let res = 0;
const expect = 159998800002;
for (let i = 0; i < size; i++) {
res += val.x;
val.x = i;
Expand Down
20 changes: 10 additions & 10 deletions tests/benchmark/array_access.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
"use strict";
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

"use strict";

const size = 1e4;
const arr = new Array(size);
const expect = 49999995000000;
let res = 0;

function main() {
for (let i = 0, j = 0; i < 1e7; i++, j++) {
var size = 1e4;
var arr = new Array(size);
var expect = 49999995000000;
var res = 0;
for (var i = 0, j = 0; i < 1e7; i++, j++) {
arr[j] = i;
res += arr[j];
if (j >= size - 1) j = 0;
if (j >= size - 1)
j = 0;
}
if (res !== expect) {
console.log('Validate result error in array access');
}
return res;
}
console.log(main());

main()
10 changes: 5 additions & 5 deletions tests/benchmark/array_access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

const size = 1e4;
const arr = new Array<number>(size);
const expect = 49999995000000;
let res = 0;

export function main() {
const size = 1e4;
const arr = new Array<number>(size);
const expect = 49999995000000;
let res = 0;

for (let i = 0, j = 0; i < 1e7; i++, j++) {
arr[j] = i;
res += arr[j];
Expand Down
20 changes: 10 additions & 10 deletions tests/benchmark/array_access_i32.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
"use strict";
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

"use strict";

const size = 1e4;
const arr = new Array(size);
const expect = 49999995000000;
let res = 0;

function main() {
for (let i = 0, j = 0; i < 1e7; i++, j++) {
var size = 1e4;
var arr = new Array(1e4);
var expect = 49999995000000;
var res = 0;
for (var i = 0, j = 0; i < 1e7; i++, j++) {
arr[j] = i;
res += arr[j];
if (j >= size - 1) j = 0;
if (j >= size - 1)
j = 0;
}
if (res !== expect) {
console.log('Validate result error in array access (i32 index)');
}
return res;
}
console.log(main());

main()
9 changes: 5 additions & 4 deletions tests/benchmark/array_access_i32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

const size: i32 = 1e4;
const arr = new Array<number>(1e4);
const expect = 49999995000000;
let res = 0;
type i32 = number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we require app to write this line?

Copy link
Contributor Author

@yviansu yviansu Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For compiling ts to wasm, we don't need this line, but we also need to compile ts to js, in this situation, we need to set i32 as a reasonable type.


export function main() {
const size: i32 = 1e4;
const arr = new Array<number>(1e4);
const expect = 49999995000000;
let res = 0;
for (let i = 0, j: i32 = 0; i < 1e7; i++, j++) {
arr[j] = i;
res += arr[j];
Expand Down
5 changes: 3 additions & 2 deletions tests/benchmark/binarytrees_class.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* This file is generated by tsc */
"use strict";
/* This file is modified base on:
* https://github.com/hanabi1224/Programming-Language-Benchmarks/blob/main/bench/algorithm/binarytrees/1.ts
Expand Down Expand Up @@ -29,6 +28,7 @@ function main() {
// console.log(`${iterations} trees of depth ${depth} check: ${sum}`)
}
}

function checksum(node) {
if (!node) {
return 1;
Expand All @@ -47,4 +47,5 @@ function createTree(depth) {
return new Tree(null, null);
}
}
main();

main()
6 changes: 4 additions & 2 deletions tests/benchmark/binarytrees_interface.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* This file is generated by tsc */
"use strict";
/* This file is modified base on:
* https://github.com/hanabi1224/Programming-Language-Benchmarks/blob/main/bench/algorithm/binarytrees/1.ts
*/

function main() {
var maxDepth = Math.max(10, 0);
var stretchDepth = maxDepth + 1;
Expand All @@ -19,6 +19,7 @@ function main() {
//console.log(`${iterations} trees of depth ${depth} check: ${sum}`)
}
}

function checksum(node) {
if (!node) {
return 1;
Expand All @@ -37,4 +38,5 @@ function createTree(depth) {
return { left: null, right: null };
}
}
main();

main()
13 changes: 6 additions & 7 deletions tests/benchmark/class_access.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"use strict";
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

"use strict";

var Foo = /** @class */ (function () {
function Foo(x) {
this.x = x;
Expand All @@ -14,11 +13,11 @@ var Foo = /** @class */ (function () {
};
return Foo;
}());
var size = 1e7;
var expect = 99999970000002;
var res = 0;
var f = new Foo(0);
function main() {
var size = 1e7;
var expect = 99999970000002;
var res = 0;
var f = new Foo(0);
for (var i = 0; i < size; i++) {
res += f.x;
res += f.bar();
Expand All @@ -30,4 +29,4 @@ function main() {
return res;
}

console.log(main());
main()
10 changes: 5 additions & 5 deletions tests/benchmark/class_access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class Foo {
}
}

const size = 1e7;
const expect = 99999970000002;
let res = 0;
const f = new Foo(0);

export function main() {
const size = 1e7;
const expect = 99999970000002;
let res = 0;
const f = new Foo(0);

for (let i = 0; i < size; i++) {
res += f.x;
res += f.bar();
Expand Down
14 changes: 7 additions & 7 deletions tests/benchmark/class_allocation.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"use strict";
/*
* Copyright (C) 2023 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

"use strict";

var Foo = /** @class */ (function () {
function Foo(x) {
this.x = x;
Expand All @@ -14,15 +13,16 @@ var Foo = /** @class */ (function () {
};
return Foo;
}());
var size = 1e7;
var len = 10;
var arr = new Array(len);
function main() {
var size = 1e7;
var len = 10;
var arr = new Array(len);
for (var i = 0, j = 0; i < size; i++, j++) {
if (j >= len) j = 0;
if (j >= len)
j = 0;
arr[j] = new Foo(i);
}
return arr;
}

console.log(main());
main()
8 changes: 4 additions & 4 deletions tests/benchmark/class_allocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class Foo {
}
}

const size = 1e7;
const len = 10;

const arr = new Array<Foo>(len);
export function main() {
const size = 1e7;
const len = 10;
const arr = new Array<Foo>(len);

for (let i = 0, j = 0; i < size; i++, j++) {
if (j >= len) j = 0;
arr[j] = new Foo(i);
Expand Down
Loading
Loading