🚀 gif creator benchmark

This commit is contained in:
platane
2020-10-09 12:43:25 +02:00
parent bc18120a98
commit 202bd7cacb
4 changed files with 67 additions and 1 deletions

View File

@@ -32,6 +32,7 @@ jobs:
- uses: bahmutov/npm-install@v1.4.1
- run: ( cd packages/compute ; yarn benchmark )
- run: ( cd packages/gif-creator ; yarn benchmark )
test-action:
runs-on: ubuntu-latest

View 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");
})();

View File

@@ -4,6 +4,7 @@ import { createGif } from "..";
import { getBestRoute } from "@snk/compute/getBestRoute";
import * as grids from "@snk/compute/__fixtures__/grid";
import { snake3 as snake } from "@snk/compute/__fixtures__/snake";
import { createSnake, nextSnake } from "@snk/compute/snake";
jest.setTimeout(20 * 1000);
@@ -44,3 +45,25 @@ for (const key of [
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);
});

View File

@@ -10,6 +10,10 @@
},
"devDependencies": {
"@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"
}
}