Skip to content

Commit b5159f0

Browse files
authored
Optimize lualib functions (#1217)
* Add benchmarks * Optimize lualib functions * Introduce NodeFlags * Optimize array push array * Remove `debug()` from tests * PR feedback
1 parent 39480bb commit b5159f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+657
-317
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function arrayConcat(): number[] {
2+
const arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
3+
const arr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
4+
const n = 50000;
5+
for (let i = 0; i < n; i++) {
6+
arr1.concat(arr2);
7+
}
8+
return arr1;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function arrayConcat(): number[] {
2+
const arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
3+
const arr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
4+
const n = 50000;
5+
for (let i = 0; i < n; i++) {
6+
arr1.concat(...arr2);
7+
}
8+
return arr1;
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function arrayEvery() {
2+
const n = 200000;
3+
const array = [1, 2, 3, 4, 5, 6, 7, 8, 7, 10];
4+
for (let i = 0; i < n; i++) {
5+
array.every((item, index) => item > index);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function arrayFilter() {
2+
const n = 100000;
3+
const array = [1, 2, 3, 4, 3, 6, 7, 8, 7, 10];
4+
for (let i = 0; i < n; i++) {
5+
array.filter((item, index) => item > index);
6+
}
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function arrayFind() {
2+
const n = 50000;
3+
const array = [1, 2, 3, 4, 3, 6, 7, 8, 9, 10];
4+
for (let i = 0; i < n; i++) {
5+
for (let j = 0; j < 10; j++) {
6+
array.find(value => value === j);
7+
}
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function arrayFindIndex() {
2+
const n = 50000;
3+
const array = [1, 2, 3, 4, 3, 6, 7, 8, 9, 10];
4+
for (let i = 0; i < n; i++) {
5+
for (let j = 0; j < 10; j++) {
6+
array.findIndex(value => value === j);
7+
}
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function arrayFlat() {
2+
const n = 50000;
3+
const array = [1, 2, [3, [4, 5], 6], 7, [8, 9], 10];
4+
for (let i = 0; i < n; i++) {
5+
array.flat(2);
6+
}
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export default function arrayFlatMap() {
2+
const n = 50000;
3+
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
4+
for (let i = 0; i < n; i++) {
5+
array.flatMap((el, index) => {
6+
if (index < 5) {
7+
return [el, el + 1];
8+
} else {
9+
return el + 2;
10+
}
11+
});
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function arrayForeach() {
2+
const n = 200000;
3+
const array = [1, 2, 3, 4, 3, 6, 7, 8, 9, 10];
4+
for (let i = 0; i < n; i++) {
5+
array.forEach(value => {
6+
let foo = value * 2;
7+
foo = foo;
8+
});
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function arrayIncludes() {
2+
const n = 50000;
3+
const array = [1, 2, 3, 4, 3, 6, 7, 8, 9, 10];
4+
for (let i = 0; i < n; i++) {
5+
for (let j = 0; j < 10; j++) {
6+
array.includes(j);
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)