🚀 gif creator benchmark
This commit is contained in:
1
.github/workflows/main.yml
vendored
1
.github/workflows/main.yml
vendored
@@ -32,6 +32,7 @@ jobs:
|
|||||||
- uses: bahmutov/npm-install@v1.4.1
|
- uses: bahmutov/npm-install@v1.4.1
|
||||||
|
|
||||||
- run: ( cd packages/compute ; yarn benchmark )
|
- run: ( cd packages/compute ; yarn benchmark )
|
||||||
|
- run: ( cd packages/gif-creator ; yarn benchmark )
|
||||||
|
|
||||||
test-action:
|
test-action:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
38
packages/gif-creator/__tests__/benchmark.ts
Normal file
38
packages/gif-creator/__tests__/benchmark.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { performance } from "perf_hooks";
|
||||||
|
import { createSnake, nextSnake } from "@snk/compute/snake";
|
||||||
|
import { realistic as grid } from "@snk/compute/__fixtures__/grid";
|
||||||
|
import { createGif } from "..";
|
||||||
|
|
||||||
|
let snake = createSnake(Array.from({ length: 6 }, (_, i) => ({ x: i, y: -1 })));
|
||||||
|
|
||||||
|
const chain = [snake];
|
||||||
|
for (let y = -1; y < grid.height; y++) {
|
||||||
|
snake = nextSnake(snake, 0, 1);
|
||||||
|
chain.push(snake);
|
||||||
|
|
||||||
|
for (let x = grid.width - 1; x--; ) {
|
||||||
|
snake = nextSnake(snake, (y + 100) % 2 ? 1 : -1, 0);
|
||||||
|
chain.push(snake);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const drawOptions = {
|
||||||
|
sizeBorderRadius: 2,
|
||||||
|
sizeCell: 16,
|
||||||
|
sizeDot: 12,
|
||||||
|
colorBorder: "#1b1f230a",
|
||||||
|
colorDots: { 1: "#9be9a8", 2: "#40c463", 3: "#30a14e", 4: "#216e39" },
|
||||||
|
colorEmpty: "#ebedf0",
|
||||||
|
colorSnake: "purple",
|
||||||
|
};
|
||||||
|
|
||||||
|
const gifOptions = { frameDuration: 20, step: 1 };
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const m = 3;
|
||||||
|
const s = performance.now();
|
||||||
|
for (let k = m; k--; )
|
||||||
|
await createGif(grid, chain.slice(0, 50), drawOptions, gifOptions);
|
||||||
|
|
||||||
|
console.log((performance.now() - s) / m, "ms");
|
||||||
|
})();
|
||||||
@@ -4,6 +4,7 @@ import { createGif } from "..";
|
|||||||
import { getBestRoute } from "@snk/compute/getBestRoute";
|
import { getBestRoute } from "@snk/compute/getBestRoute";
|
||||||
import * as grids from "@snk/compute/__fixtures__/grid";
|
import * as grids from "@snk/compute/__fixtures__/grid";
|
||||||
import { snake3 as snake } from "@snk/compute/__fixtures__/snake";
|
import { snake3 as snake } from "@snk/compute/__fixtures__/snake";
|
||||||
|
import { createSnake, nextSnake } from "@snk/compute/snake";
|
||||||
|
|
||||||
jest.setTimeout(20 * 1000);
|
jest.setTimeout(20 * 1000);
|
||||||
|
|
||||||
@@ -44,3 +45,25 @@ for (const key of [
|
|||||||
|
|
||||||
fs.writeFileSync(path.resolve(dir, key + ".gif"), gif);
|
fs.writeFileSync(path.resolve(dir, key + ".gif"), gif);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it(`should generate swipper`, async () => {
|
||||||
|
const grid = grids.smallFull;
|
||||||
|
let snk = createSnake(Array.from({ length: 6 }, (_, i) => ({ x: i, y: -1 })));
|
||||||
|
|
||||||
|
const chain = [snk];
|
||||||
|
for (let y = -1; y < grid.height; y++) {
|
||||||
|
snk = nextSnake(snk, 0, 1);
|
||||||
|
chain.push(snk);
|
||||||
|
|
||||||
|
for (let x = grid.width - 1; x--; ) {
|
||||||
|
snk = nextSnake(snk, (y + 100) % 2 ? 1 : -1, 0);
|
||||||
|
chain.push(snk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const gif = await createGif(grid, chain, drawOptions, gifOptions);
|
||||||
|
|
||||||
|
expect(gif).toBeDefined();
|
||||||
|
|
||||||
|
fs.writeFileSync(path.resolve(dir, "swipper.gif"), gif);
|
||||||
|
});
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/execa": "2.0.0",
|
"@types/execa": "2.0.0",
|
||||||
"@types/tmp": "0.2.0"
|
"@types/tmp": "0.2.0",
|
||||||
|
"@zeit/ncc": "0.22.3"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"benchmark": "ncc run __tests__/benchmark.ts --quiet"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user