{"ScriptPreparationCode":"var bench1buffer;\r\nvar bench2buffer;\r\nvar bench3buffer;\r\nvar size = 1_000_000;\r\n{\r\n const stride = 10;\r\n bench1buffer = new ArrayBuffer(stride * size);\r\n /*\r\n 0 u16 id\r\n 2 f32 x\r\n 6 f32 y\r\n */\r\n for (let i = 0; i \u003C size; i\u002B\u002B) {\r\n const struct = new DataView(bench1buffer, i * stride, stride);\r\n struct.setUint16(0, i, true);\r\n struct.setFloat32(2, i, true);\r\n struct.setFloat32(6, i * 2, true);\r\n }\r\n}\r\n{\r\n const stride = 12;\r\n bench2buffer = new ArrayBuffer(stride * size);\r\n /*\r\n 0 u16 id\r\n 4 f32 x\r\n 8 f32 y\r\n */\r\n for (let i = 0; i \u003C size; i\u002B\u002B) {\r\n const struct = new DataView(bench2buffer, i * stride, stride);\r\n struct.setUint16(0, i, true);\r\n struct.setFloat32(4, i, true);\r\n struct.setFloat32(8, i * 2, true);\r\n }\r\n}\r\n{\r\n bench3buffer = {\r\n id: new Uint16Array(size),\r\n x: new Float32Array(size),\r\n y: new Float32Array(size),\r\n };\r\n for (let i = 0; i \u003C size; i\u002B\u002B) {\r\n bench3buffer.id[i] = i;\r\n bench3buffer.x[i] = i;\r\n bench3buffer.y[i] = i * 2;\r\n }\r\n}\r\n","TestCases":[{"Name":"DataView AoS","Code":"const stride = 10;\r\n/*\r\n 0 u16 id\r\n 2 f32 x\r\n 6 f32 y\r\n*/\r\nconst view = new DataView(bench1buffer);\r\nlet sum = 0;\r\nfor (let i = 0; i \u003C size; i\u002B\u002B) {\r\n const offset = i * stride;\r\n const id = view.getUint16(offset, true);\r\n const x = view.getFloat32(offset \u002B 2, true);\r\n const y = view.getFloat32(offset \u002B 6, true);\r\n sum \u002B= id \u002B x * y;\r\n}\r\nconsole.log(1, sum);","IsDeferred":false},{"Name":"DataView byte-aligned AoS","Code":"const stride = 12;\r\n/*\r\n 0 u16 id\r\n 4 f32 x\r\n 8 f32 y\r\n*/\r\nconst view = new DataView(bench2buffer);\r\nlet sum = 0;\r\nfor (let i = 0; i \u003C size; i\u002B\u002B) {\r\n const offset = i * stride;\r\n const id = view.getUint16(offset, true);\r\n const x = view.getFloat32(offset \u002B 4, true);\r\n const y = view.getFloat32(offset \u002B 8, true);\r\n sum \u002B= id \u002B x * y;\r\n}\r\nconsole.log(2, sum);","IsDeferred":false},{"Name":"TypedArray byte-aligned AoS","Code":"const stride = 12;\r\n/*\r\n 0 u16 id\r\n 4 f32 x\r\n 8 f32 y\r\n*/\r\nconst f32s = new Float32Array(bench2buffer);\r\nconst u16s = new Uint16Array(bench2buffer);\r\nlet sum = 0;\r\nfor (let i = 0; i \u003C size; i\u002B\u002B) {\r\n const offset = i * stride;\r\n const id = u16s[offset / 2];\r\n const x = f32s[offset / 4 \u002B 1];\r\n const y = f32s[offset / 4 \u002B 2];\r\n sum \u002B= id \u002B x * y;\r\n}\r\nconsole.log(3, sum);","IsDeferred":false},{"Name":"TypeArray SoA","Code":"let sum = 0;\r\nconst ids = bench3buffer.id;\r\nconst xs = bench3buffer.x;\r\nconst ys = bench3buffer.y;\r\nfor (let i = 0; i \u003C size; i\u002B\u002B) {\r\n const id = ids[i];\r\n const x = xs[i];\r\n const y = ys[i];\r\n sum \u002B= id \u002B x * y;\r\n}\r\nconsole.log(4, sum);","IsDeferred":false}]}