{"ScriptPreparationCode":"// \u521D\u59CB\u5316 WebGL \u4E0A\u4E0B\u6587\r\nconst canvas = document.createElement(\u0027canvas\u0027);\r\nconst gl = canvas.getContext(\u0027webgl\u0027);\r\n\r\n// \u521B\u5EFA WebGL buffer\r\nconst buffer = gl.createBuffer();\r\ngl.bindBuffer(gl.ARRAY_BUFFER, buffer);\r\n\r\n// \u51FD\u6570\uFF1A\u6D4B\u91CF bufferSubData \u7684\u8FD0\u884C\u65F6\u95F4\r\nfunction measureBufferSubDataPerformance(array: Float32Array) {\r\n // \u521B\u5EFA\u4E00\u4E2A GPU \u4E0A\u7684\u7A7A buffer\uFF0C\u5E76\u5206\u914D\u4E0E Float32Array \u76F8\u540C\u5927\u5C0F\u7684\u7A7A\u95F4\r\n gl.bufferData(gl.ARRAY_BUFFER, array.length * 4, gl.DYNAMIC_DRAW);\r\n\r\n // \u8BB0\u5F55\u5F00\u59CB\u65F6\u95F4\r\n const startTime = performance.now();\r\n\r\n // \u4F7F\u7528 bufferSubData \u66F4\u65B0 buffer \u6570\u636E\r\n gl.bufferSubData(gl.ARRAY_BUFFER, 0, array);\r\n\r\n // \u8BB0\u5F55\u7ED3\u675F\u65F6\u95F4\r\n const endTime = performance.now();\r\n\r\n // \u8FD4\u56DE\u8017\u65F6\r\n return endTime - startTime;\r\n}\r\n\r\n// \u793A\u4F8B\u7528\u6CD5\r\nconst array1 = new Float32Array(1000); // \u521B\u5EFA\u4E00\u4E2A\u957F\u5EA6\u4E3A1000\u7684Float32Array\r\nconst array2 = new Float32Array(10000); // \u521B\u5EFA\u4E00\u4E2A\u957F\u5EA6\u4E3A10000\u7684Float32Array\r\nconst array3 = new Float32Array(100000); // \u521B\u5EFA\u4E00\u4E2A\u957F\u5EA6\u4E3A100000\u7684Float32Array\r\n\r\n// \u586B\u5145\u6570\u7EC4\uFF08\u53EF\u4EE5\u4F7F\u7528\u4F60\u5DF2\u6709\u7684Float32Array\u5BF9\u8C61\uFF09\r\nfor (let i = 0; i \u003C array1.length; i\u002B\u002B) {\r\n array1[i] = Math.random();\r\n}\r\n\r\nfor (let i = 0; i \u003C array2.length; i\u002B\u002B) {\r\n array2[i] = Math.random();\r\n}\r\n\r\nfor (let i = 0; i \u003C array3.length; i\u002B\u002B) {\r\n array3[i] = Math.random();\r\n}\r\n\r\n\r\n","TestCases":[{"Name":"test array 1","Code":"// \u6D4B\u8BD5\u4E0D\u540C\u5927\u5C0F\u7684 Float32Array \u5728 bufferSubData \u4E0A\u7684\u8017\u65F6\r\nconst time1 = measureBufferSubDataPerformance(array1);\r\n\r\n\r\nconsole.log(\u0060Time for array1 (1000 elements): ${time1} ms\u0060);\r\n","IsDeferred":false},{"Name":"test array 2","Code":"// \u6D4B\u8BD5\u4E0D\u540C\u5927\u5C0F\u7684 Float32Array \u5728 bufferSubData \u4E0A\u7684\u8017\u65F6\r\nconst time2 = measureBufferSubDataPerformance(array2);\r\n\r\nconsole.log(\u0060Time for array2 (10000 elements): ${time2} ms\u0060);\r\n","IsDeferred":false}]}