Skip to content

Commit

Permalink
Test array flat and flat map
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnaya committed Sep 17, 2020
1 parent 1ab5bd8 commit b5561f9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ jobs:

test:
runs-on: ubuntu-18.04
strategy:
matrix:
node: [12, 14]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: ${{ matrix.node }}

- name: Cache node modules
uses: actions/cache@v2
Expand Down
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"debug.node.autoAttach": "off",
"debug.node.autoAttach": "on",
"search.exclude": {
"**/bower_components": true,
"**/node_modules": true,
Expand Down Expand Up @@ -66,5 +66,7 @@
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
},
"debug.javascript.usePreviewAutoAttach": false,
"debug.javascript.usePreview": false
}
46 changes: 46 additions & 0 deletions src/apiTests/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,50 @@ describe("SharedArrayBuffer tests", () => {
const usedDisposeArrays = memoryStats(ob).used;
expect(usedDisposeArrays - usedAfterCreate).toMatchInlineSnapshot(`48`);
});

test("flat", () => {
const input = [[{ v: 1 }], [{ v: 2 }], [{ v: 3 }], [{ v: 4 }]];

const o = createObjectBuffer({ arrayAdditionalAllocation: 0 }, 1024 * 2, {
arr: input,
});

const output = o.arr.flat();

expect(output).toMatchInlineSnapshot(`
Array [
Object {
"v": 1,
},
Object {
"v": 2,
},
Object {
"v": 3,
},
Object {
"v": 4,
},
]
`);
});

test("flatMap", () => {
const input = [[{ v: 1 }], [{ v: 2 }], [{ v: 3 }], [{ v: 4 }]];

const o = createObjectBuffer({ arrayAdditionalAllocation: 0 }, 1024 * 2, {
arr: input,
});

const output = o.arr.flatMap((v) => v[0].v + 1);

expect(output).toMatchInlineSnapshot(`
Array [
2,
3,
4,
5,
]
`);
});
});

1 comment on commit b5561f9

@Bnaya
Copy link
Owner Author

@Bnaya Bnaya commented on b5561f9 Sep 17, 2020

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: b5561f9 Previous: 77a4bdb Ratio
createObjectBuffer with 200 comments 508 ops/sec (±3.77%) 523 ops/sec (±4.64%) 1.03

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.