{"ScriptPreparationCode":"\u0027use strict\u0027;\r\nwindow.N = Math.pow(10, 9);\r\n\r\nclass Packed256 {\r\n \tconstructor(length) {\r\n \tthis.store = new Float64Array(length \u003C\u003C 2);\r\n }\r\n \r\n \tgetPX(index) { return this.store[(index \u003C\u003C 2) \u002B 0]; }\r\n \tgetPY(index) { return this.store[(index \u003C\u003C 2) \u002B 1]; }\r\n \tgetVX(index) { return this.store[(index \u003C\u003C 2) \u002B 2]; }\r\n \tgetVY(index) { return this.store[(index \u003C\u003C 2) \u002B 3]; }\r\n \r\n \tsetPX(index, val) { this.store[(index \u003C\u003C 2) \u002B 0] = val; }\r\n \tsetPY(index, val) { this.store[(index \u003C\u003C 2) \u002B 1] = val; }\r\n \tsetVX(index, val) { this.store[(index \u003C\u003C 2) \u002B 2] = val; }\r\n \tsetVY(index, val) { this.store[(index \u003C\u003C 2) \u002B 3] = val; }\r\n}\r\n\r\nclass PointAndVelocity {\r\n constructor(x, y, vx, vy) {\r\n this.x = x;\r\n this.y = y;\r\n this.vx = vx;\r\n this.vy = vy;\r\n }\r\n}\r\n\r\nclass Point {\r\n constructor(x, y) {\r\n this.x = x;\r\n this.y = y;\r\n }\r\n}\r\n\r\nclass Velocity {\r\n constructor(vx, vy) {\r\n this.vx = vx;\r\n this.vy = vy;\r\n }\r\n}\r\n\r\naos = Array(N).fill(new PointAndVelocity(0, 0, 0, 0))\r\n .map(() =\u003E new PointAndVelocity(Math.random() * 100, Math.random() * 100, Math.random() * 100, Math.random() * 100));\r\n\r\npacked = new Packed256(N);\r\nfor (let i = 0; i \u003C N; i\u002B\u002B) {\r\n \tpacked.setPX(i, Math.random() * 100);\r\n \tpacked.setPY(i, Math.random() * 100);\r\n \tpacked.setVX(i, Math.random() * 100);\r\n \tpacked.setVY(i, Math.random() * 100);\r\n}\r\n\r\n// SoA, we try to duplicate the data so numeric differences are out of the question.\r\npoints = Array(N).fill(new Point(0, 0)).\r\n .map((_, i) =\u003E new Point(aos[i].x, aos[i].y));\r\nvelocities = Array(N).fill(new Velocity(0, 0)).\r\n .map((_, i) =\u003E new Velocity(aos[i].vx, aos[i].vy));","TestCases":[{"Name":"SoA","Code":"var N = window.N;\r\nfor (var i = 0; i \u003C N; \u002B\u002Bi) {\r\n\tvar point = points[i];\r\n\tvar velocity = velocities[i];\r\n point.x \u002B= velocity.vx;\r\n point.y \u002B= velocity.vy;\r\n}","IsDeferred":false},{"Name":"AoS","Code":"var N = window.N;\r\nfor (var i = 0; i \u003C N; \u002B\u002Bi) {\r\n\tvar pav = aos[i]\r\n pav.x \u002B= pav.vx;\r\n pav.y \u002B= pav.vy;\r\n}","IsDeferred":false},{"Name":"Packed Typed Array","Code":"var N = window.N;\r\nfor (var i = 0; i \u003C N; i\u002B\u002B) {\r\n \tpacked.setPX(i, packed.getPX(i) \u002B packed.getVX(i));\r\n \tpacked.setPY(i, packed.getPY(i) \u002B packed.getVY(i));\r\n}","IsDeferred":false}]}