mirror of
https://github.com/servo/servo.git
synced 2025-09-29 16:19:14 +01:00
Vendors the [blink perf tests](https://chromium.googlesource.com/chromium/src/+/HEAD/third_party/blink/perf_tests/). These perf tests are useful to evaluate the performance of servo. The license that governs the perf tests is included in the folder. Running benchmark cases automatically is left to future work. The update.py script is taken from mozjs and slightly adapted, so we can easily filter (and patch if this should be necessary in the future. Testing: This PR just adds the perf_tests, but does not use or modify them in any way. --------- Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
93 lines
2.5 KiB
JavaScript
Vendored
93 lines
2.5 KiB
JavaScript
Vendored
function prepareFrames(width, height, count) {
|
|
const canvas = new OffscreenCanvas(width, height);
|
|
const ctx = canvas.getContext('2d');
|
|
const duration = 1_000_000 / 30; // 1/30 s
|
|
let timestamp = 0;
|
|
const frames = [];
|
|
for (let i = 0; i < count; i++) {
|
|
fourColorsFrame(ctx, width, height, timestamp.toString());
|
|
let frame = new VideoFrame(canvas, {timestamp: timestamp});
|
|
frames.push(frame);
|
|
timestamp += duration;
|
|
}
|
|
return frames;
|
|
}
|
|
|
|
async function testEncodingConfiguration(name, width, height, count, acc) {
|
|
const encoder_config = {
|
|
codec: "avc1.42001F",
|
|
hardwareAcceleration: acc,
|
|
width: width,
|
|
height: height,
|
|
bitrate: 2000000,
|
|
framerate: 30
|
|
};
|
|
|
|
let support = await VideoEncoder.isConfigSupported(encoder_config);
|
|
if (!support.supported) {
|
|
PerfTestRunner.log("Skipping test. Unsupported encoder config" +
|
|
JSON.stringify(encoder_config));
|
|
return;
|
|
}
|
|
|
|
const warm_up_frames = 5;
|
|
let frames = prepareFrames(width, height, count + warm_up_frames);
|
|
let is_done = false;
|
|
|
|
const init = {
|
|
output(chunk, metadata) {},
|
|
error(e) {
|
|
PerfTestRunner.logFatalError("Encoding error: " + e);
|
|
}
|
|
};
|
|
|
|
async function runTest() {
|
|
const encoder = new VideoEncoder(init);
|
|
encoder.configure(encoder_config);
|
|
|
|
PerfTestRunner.addRunTestStartMarker();
|
|
|
|
// Encode first several frames without timing it, this will given the
|
|
// encoder chance to finish initialization.
|
|
for (let i = 0; i < warm_up_frames; i++) {
|
|
encoder.encode(frames[i], {keyFrame: false});
|
|
}
|
|
|
|
await encoder.flush().catch(e => {
|
|
PerfTestRunner.logFatalError("Test error: " + e);
|
|
});
|
|
|
|
let start_time = PerfTestRunner.now();
|
|
for (let frame of frames.slice(warm_up_frames)) {
|
|
encoder.encode(frame, { keyFrame: false });
|
|
}
|
|
|
|
encoder.flush().then(
|
|
_ => {
|
|
let run_time = PerfTestRunner.now() - start_time;
|
|
PerfTestRunner.measureValueAsync(run_time);
|
|
PerfTestRunner.addRunTestEndMarker();
|
|
encoder.close();
|
|
if (!is_done)
|
|
runTest();
|
|
},
|
|
e => {
|
|
PerfTestRunner.logFatalError("Test error: " + e);
|
|
});
|
|
}
|
|
|
|
PerfTestRunner.startMeasureValuesAsync({
|
|
unit: 'ms',
|
|
done: function () {
|
|
is_done = true;
|
|
for (let frame of frames)
|
|
frame.close();
|
|
},
|
|
run: function() {
|
|
runTest();
|
|
},
|
|
warmUpCount: 0,
|
|
iterationCount: 3,
|
|
description: name,
|
|
});
|
|
}
|