| <!DOCTYPE html> |
| <html> |
| <body> |
| <script src="../resources/runner.js"></script> |
| <script> |
| |
| var canvas = document.createElement("canvas"); |
| var ctx = canvas.getContext("2d"); |
| |
| var dataSize = 4000000; |
| var dataU8 = new Uint8ClampedArray(dataSize); |
| var dataU16 = new Uint16Array(dataSize); |
| var dataF32 = new Float32Array(dataSize); |
| |
| var imageData; |
| var imageDataU8; |
| var imageDataU16; |
| var imageDataF32; |
| |
| var accessCount = 1000000; |
| var accessLocations = new Uint32Array(accessCount); |
| |
| function rand(range) { |
| return Math.floor(Math.random() * range); |
| } |
| |
| function fillArrays() { |
| for (i = 0; i < dataSize; i++) { |
| dataU8[i] = rand(256); |
| dataU16[i] = rand(65536); |
| dataF32[i] = rand(1); |
| } |
| for (i = 0; i < accessCount; i++) |
| accessLocations[i] = rand(dataSize); |
| } |
| |
| |
| function readArray(array, accessLocations, arrayName) { |
| var sum = 0; |
| for (i = 0; i < accessLocations.length; i++) |
| sum = sum + array[accessLocations[i]]; |
| return sum; |
| } |
| |
| function writeArray(array, accessLocations, arrayName) { |
| for (i = 0; i < accessLocations.length; i++) |
| array[accessLocations[i]] = 0; |
| } |
| |
| function ImageData_data_AccessTime() { |
| imageDataU8 = ctx.createImageData(dataU8, 1000, 1000, {colorSpace: "srgb"}); |
| readArray(imageData.data, accessLocations); |
| writeArray(imageData.data, accessLocations); |
| } |
| |
| function ImageData_dataUnionU8_AccessTime() { |
| imageDataU8 = ctx.createImageData(dataU8, 1000, 1000, {colorSpace: "srgb", pixelFormat: "uint8"}); |
| readArray(imageDataU8.dataUnion, accessLocations); |
| writeArray(imageDataU8.dataUnion, accessLocations); |
| |
| } |
| |
| function ImageData_dataUnionU16_AccessTime() { |
| imageDataU16 = ctx.createImageData(dataU16, 1000, 1000, {colorSpace: "srgb", pixelFormat: "uint16"}); |
| readArray(imageDataU16.dataUnion, accessLocations); |
| writeArray(imageDataU16.dataUnion, accessLocations); |
| } |
| |
| function ImageData_dataUnionF32_AccessTime() { |
| imageDataF32 = ctx.createImageData(dataF32, 1000, 1000, {colorSpace: "srgb", pixelFormat: "float32"}); |
| readArray(imageDataF32.dataUnion, accessLocations, "imageDataF32.dataUnion"); |
| writeArray(imageDataF32.dataUnion, accessLocations, "imageDataF32.dataUnion"); |
| } |
| |
| |
| PerfTestRunner.measureRunsPerSecond({run: ImageData_data_AccessTime, description: "This bench test checks the speed of reading and writing 250K pixels (equivalent) to ImageData.data."}); |
| |
| PerfTestRunner.measureRunsPerSecond({run: ImageData_dataUnionU8_AccessTime, description: "This bench test checks the speed of reading and writing 250K pixels (equivalent) to ImageData.dataUnion of type Uint8ClampedArray."}); |
| |
| PerfTestRunner.measureRunsPerSecond({run: ImageData_dataUnionU16_AccessTime, description: "This bench test checks the speed of reading and writing 250K pixels (equivalent) to ImageData.dataUnion of type Uin16Array."}); |
| |
| PerfTestRunner.measureRunsPerSecond({run: ImageData_dataUnionF32_AccessTime, description: "This bench test checks the speed of reading and writing 250K pixels (equivalent) to ImageData.dataUnion of type Float32Array."}); |
| </script> |
| </body> |
| </html> |
| |
| |
| test(() => { |
| runTest(); |
| }, "Test ImageData.dataUnion access time"); |
| </script> |
| </body> |