Skip to content
Open
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
63 changes: 62 additions & 1 deletion test/bench/typography.bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ const TO_CONTOURS_CASES = TO_POINTS_CASES.map((c, i) => ({
contours: EXPECTED_CONTOURS[i],
}));

const TO_PATHS_CASES = [
{label: "textToPaths() single word", str: strs.single, textSize: 20, commands: 253, variance: 0, render: false},
{label: "textToPaths() single word, 150pt", str: strs.single, textSize: 150, commands: 253, variance: 0, render: false},
{label: "textToPaths() 10 words", str: strs.ten, textSize: 20, commands: 1157, variance: 0, render: false},
{label: "textToPaths() paragraph", str: strs.paragraph, textSize: 20, commands: 16716, variance: 0, render: false},
];

const TO_MODEL_CASES = [
{label: "textToModel() single word", str: strs.single, textSize: 20, sampleFactor: 0.5, render: false},
{label: "textToModel() single word, 150pt", str: strs.single, textSize: 150, sampleFactor: 0.5, render: false},
Expand Down Expand Up @@ -134,6 +141,24 @@ describe("Typography: bench 2D", function() {
);
}

for (let testCase of TO_PATHS_CASES) {
bench(
testCase.label,
async () => {
const paths = font.textToPaths(testCase.str, 10, 20);
assert.closeTo(paths.length, testCase.commands, testCase.variance);
},
{
...options,
setup: async () => {
({myp5, font} = await bootstrap());
myp5.textSize(testCase.textSize);
},
teardown: () => myp5.remove()
}
);
}

});

describe("Typography: bench WebGL", function() {
Expand Down Expand Up @@ -183,6 +208,24 @@ describe("Typography: bench WebGL", function() {
);
}

for (let testCase of TO_PATHS_CASES) {
bench(
testCase.label,
async () => {
const paths = font.textToPaths(testCase.str, 10, 20);
assert.closeTo(paths.length, testCase.commands, testCase.variance);
},
{
...options,
setup: async () => {
({myp5, font} = await bootstrap(400, 400, WEBGL));
myp5.textSize(testCase.textSize);
},
teardown: () => myp5.remove()
}
);
}

for (let testCase of TO_MODEL_CASES) {
bench(
testCase.label,
Expand Down Expand Up @@ -254,6 +297,24 @@ describe("Typography: bench WebGPU", function() {
);
}

for (let testCase of TO_PATHS_CASES) {
bench(
testCase.label,
async () => {
const paths = font.textToPaths(testCase.str, 10, 20);
assert.closeTo(paths.length, testCase.commands, testCase.variance);
},
{
...options,
setup: async () => {
({myp5, font} = await bootstrap(400, 400, WEBGPU));
myp5.textSize(testCase.textSize);
},
teardown: () => myp5.remove()
}
);
}

for (let testCase of TO_MODEL_CASES) {
bench(
testCase.label,
Expand All @@ -275,4 +336,4 @@ describe("Typography: bench WebGPU", function() {
);
}

});
});