1 <!-- This benchmark run a lot of small benchmarks that are defined with a karma-like sytax
7 <title>CanvasKit SKP Perf</title>
8 <meta charset="utf-8" />
9 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
10 <meta name="viewport" content="width=device-width, initial-scale=1.0">
11 <script src="/static/canvaskit.js" type="text/javascript" charset="utf-8"></script>
12 <script src="/static/benchmark.js" type="text/javascript" charset="utf-8"></script>
13 <script src="/static/canvas_perf.js" type="text/javascript" charset="utf-8"></script>
14 <style type="text/css" media="screen">
23 <button id="start_bench">Start Benchmark</button>
25 <canvas id=anim width=600 height=600 style="height: 600px; width: 600px;"></canvas>
27 <script type="text/javascript" charset="utf-8">
30 const WARM_UP_FRAMES = 5;
31 // Keeping this a little lower because this test runs many smaller tests,
32 // each for this many frames, which could add up to a long time.
33 const MAX_FRAMES = 51;
35 // Any external files needed by tests in canvas_perf.js must be listed here.
36 // And checked in under canvas_perf_assets/
37 // tests may then fetch them from ctx.files['filename']
38 const testDataFiles = [
43 'Roboto-Regular.woff',
44 'Roboto-Regular.woff2',
48 const filePromises = [];
49 for (const filename of testDataFiles) {
50 filePromises.push(fetch('/static/assets/'+filename).then((resp) => {
51 return resp.arrayBuffer(); // this is also a promise.
54 const externals = Promise.all(filePromises).then((results) => {
57 for (const bytes of results) {
59 files[testDataFiles[i]] = bytes;
65 const loadCanvasKit = CanvasKitInit({
66 locateFile: (file) => '/static/' + file,
69 Promise.all([loadCanvasKit, externals]).then(([CanvasKit, externalFiles]) => {
70 const urlSearchParams = new URLSearchParams(window.location.search);
72 if (urlSearchParams.has('webgl1')) {
75 let surface = getSurface(CanvasKit, glversion);
77 console.error('Could not make surface', window._error);
81 document.getElementById('start_bench').addEventListener('click', async () => {
82 window._perfData = {};
84 // canvas_perf.js should have defined an array called tests whose objects have:
85 // setup: A function called once before testing begins, it is expected to make its
86 // own canvas and put it in ctx.
87 // test: A function called to draw one frame
88 // teardown: A function called after testing finishes
89 // description: A human readable description
90 // perfkey: A key used to save the results in perf.skia.org.
92 // For quick local bench testing, there is also an array called onlytests. This way
93 // a developer can replace tests.push with onlytests.push to just run one or two
94 // performance benchmarks they care about.
95 let testsToRun = tests;
96 if (onlytests.length) {
97 testsToRun = onlytests;
100 for (const t of testsToRun) {
103 'files': externalFiles,
105 console.log('Benchmarking "' + t.description + '"');
106 t.setup(CanvasKit, ctx);
108 t.test(CanvasKit, ctx);
110 // TODO(nifong): is it ok to keep re-using the surface?
111 results = await startTimingFrames(draw, surface, WARM_UP_FRAMES, MAX_FRAMES);
112 t.teardown(CanvasKit, ctx);
113 window._perfData[t.perfKey] = results;
115 // Delete and re-create surface between tests, to prevent the possibility of
116 // interference between them through the state of surface, the gl context, or things
117 // that are keyed by the surface's gen id.
119 surface = getSurface(CanvasKit, glversion);
121 // TODO(nifong): provide a function similar to startTimingFrames for timing
125 window._perfDone = true;
127 console.log('Perf is ready');
128 window._perfReady = true;