{"ScriptPreparationCode":"var N = 1000\r\nconst dim = {\r\n width: 1024,\r\n height: 768\r\n}\r\nvar ctxs = []\r\nconst SZ = 4\r\nconst SZ2 = 2 * SZ\r\nconst TWO_PI = 2 * Math.PI\r\n\r\nfor (let i = 0; i \u003C 6; i\u002B\u002B) {\r\n const canvas = document.createElement(\u0022canvas\u0022)\r\n Object.assign(canvas, dim)\r\n ctxs.push(canvas.getContext(\u00222d\u0022))\r\n}\r\n\r\nfunction randXY() {\r\n const x = dim.width * Math.random()|0\r\n const y = dim.height * Math.random()|0\r\n return [x, y]\r\n}\r\n\r\n/*\r\n * Square stuff\r\n */\r\nfunction drawSquare() {\r\n ctxs[0].rect(...randXY(), SZ2, SZ2)\r\n}\r\n\r\nconst buffer = document.createElement(\u0022canvas\u0022)\r\nbuffer.width = SZ2\r\nbuffer.height = 2 * SZ2\r\nconst bufferCtx = buffer.getContext(\u00222d\u0022)\r\nbufferCtx.fillRect(0, 0, SZ2, SZ2)\r\n\r\nfunction drawImageSquare() {\r\n ctxs[1].drawImage(buffer, 0, 0, SZ2, SZ2, ...randXY(), SZ2, SZ2)\r\n}\r\n\r\nconst imageDataSquare = bufferCtx.getImageData(0, 0, SZ2, SZ2)\r\nfunction putImageDataSquare() {\r\n ctxs[2].putImageData(imageDataSquare, ...randXY())\r\n}\r\n\r\n/*\r\n * Circle stuff\r\n */\r\nfunction drawCircle() {\r\n const ctx = ctxs[3]\r\n ctx.arc(...randXY(), SZ, 0, TWO_PI)\r\n ctx.closePath()\r\n}\r\n\r\n// draw a circle onto the buffer, below the square\r\nbufferCtx.beginPath()\r\nbufferCtx.arc(SZ2, 1.5*SZ2, SZ, 0, TWO_PI)\r\nbufferCtx.closePath()\r\nbufferCtx.fill()\r\n\r\nfunction drawImageCircle() {\r\n ctxs[4].drawImage(buffer, 0, SZ2, SZ2, SZ2, ...randXY(), SZ2, SZ2)\r\n}\r\n\r\nconst imageDataCircle = bufferCtx.getImageData(0, SZ2, SZ2, SZ2)\r\nfunction putImageDataCircle() {\r\n ctxs[5].putImageData(imageDataCircle, ...randXY())\r\n}\r\n\r\n\r\nfunction doMany(func) {\r\n for (let i = 0; i \u003C N; i\u002B\u002B) {\r\n func()\r\n }\r\n}","TestCases":[{"Name":"draw squares","Code":"ctxs[0].beginPath()\r\ndoMany(drawSquare)\r\nctxs[0].fill()","IsDeferred":false},{"Name":"draw circles","Code":"ctxs[1].beginPath()\r\ndoMany(drawCircle)\r\nctxs[1].fill()\r\n","IsDeferred":false},{"Name":"drawImage squares","Code":"doMany(drawImageSquare)","IsDeferred":false},{"Name":"drawImage circles","Code":"doMany(drawImageCircle)","IsDeferred":false},{"Name":"putImageData squares","Code":"doMany(putImageDataSquare)","IsDeferred":false},{"Name":"putImageData circles","Code":"doMany(putImageDataCircle)\r\n","IsDeferred":false}]}