Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Report benchmark results on page
Browse files Browse the repository at this point in the history
  • Loading branch information
sbalko committed Jun 3, 2024
1 parent 7d5ef7f commit ef2639e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
21 changes: 18 additions & 3 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ <h3>Encoder settings</h3>
<div class="progress">
<div id="encoder-progress" class="progress-bar" role="progressbar" style="width: 0%" aria-label="encoder progress"></div>
</div>
<div>Exported file size: <span id="output-size">0</span> bytes</div>
</div>
</div>

Expand All @@ -137,9 +136,25 @@ <h3>Encoder settings</h3>
<div id="loading-progress" class="progress-bar" role="progressbar" style="width: 0%" aria-label="loading progress"></div>
</div>
</div>
</div>

<div class="row">
<div class="mb-3"><hr></div>

<div class="mb-3">
<h3>Benchmark results</h3>
</div>

<div class="mb-3">
<div>Export time: <span id="export-time">0</span> seconds</div>
</div>

<div class="m3-b">
<div>Export time (seconds): <span id="export-time">0</span></div>
<div class="mb-3">
<div>Exported file size: <span id="output-size">0</span> bytes</div>
</div>

<div class="mb-3">
<div><span id="decoded-frames">0</span> frames decoded, <span id="encoded-packets">0</span> packets encoded</span></div>
</div>
</div>

Expand Down
23 changes: 11 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ const TOTAL_TIME_MICROS = 596380000;
const encoderProgressControl = $('#encoder-progress');
const exportTimeText = $('#export-time');
const outputSizeText = $('#output-size');
const decodedFramesText = $('#decoded-frames');
const encodedPacketsText = $('#encoded-packets');


function setExportProgress(timestampMicros: number, durationSeconds: number, outputSizeBytes: number): void {
function setExportProgress(timestampMicros: number, durationSeconds: number, outputSizeBytes: number, decodedFrames: number, encodedPackets: number): void {
encoderProgressControl.css('width', `${Math.round(timestampMicros / TOTAL_TIME_MICROS * 100)}%`);
exportTimeText.text(`${durationSeconds.toFixed(3)}`);
outputSizeText.text(`${outputSizeBytes}`);
decodedFramesText.text(`${decodedFrames}`);
encodedPacketsText.text(`${encodedPackets}`);
}

const loadingProgressControl = $('#loading-progress');
Expand All @@ -40,9 +43,10 @@ $('button#run-benchmark').click(async () => {
$('button#run-benchmark').attr('disabled', 'disabled');
$('select').attr('disabled', 'disabled');
$('input').attr('disabled', 'disabled');
loadingProgressControl.css('width', `0%`);
encoderProgressControl.css('width', `0%`);

setExportProgress(0, 0, 0, 0, 0);
setLoadingProgress(0, 0);

const inputFileName = $('select#input-file').val() as string;
const decoderAcceleration = $('select#decoder-acceleration').val() as HardwareAcceleration;
const decoderCanvas = $('canvas#decoder-canvas')[0] as HTMLCanvasElement;
Expand All @@ -57,11 +61,8 @@ $('button#run-benchmark').click(async () => {
const latencyMode = $('select#latency-mode').val() as LatencyMode;
const showEncodingProgress = $('input#progress-update:checked').val() === 'on';

exportTimeText.val('Loading video.');
outputSizeText.text('0');

const inputFile = await loadInputFile(inputFileName, setLoadingProgress);
exportTimeText.val('Running...');

const startTimeMillis = performance.now();

Expand Down Expand Up @@ -99,18 +100,16 @@ $('button#run-benchmark').click(async () => {
++encodedPackets;

if (showEncodingProgress) {
setExportProgress(chunk.timestamp, performance.now() - startTimeMillis, outputSizeBytes);
setExportProgress(chunk.timestamp, performance.now() - startTimeMillis, outputSizeBytes, decodedFrames, encodedPackets);
}
}

const durationSeconds = (performance.now() - startTimeMillis) / 1000;

setLoadingProgress(0, 0);
setExportProgress(0, durationSeconds, outputSizeBytes);
alert(`Benchmark finished in ${durationSeconds.toFixed(3)} seconds.\n${decodedFrames} frames decoded, ${encodedPackets} packets encoded (${outputSizeBytes} bytes).`);
setExportProgress(0, durationSeconds, outputSizeBytes, decodedFrames, encodedPackets);

$('button#run-benchmark').removeAttr('disabled');
$('select').removeAttr('disabled');
$('input').removeAttr('disabled');

loadingProgressControl.css('width', `0%`);
});

0 comments on commit ef2639e

Please sign in to comment.