AoS vs SoA vs AoSoA

Benchmark created on


Description

Setup

"use strict";

const N = 10000
const AoSoA_SPLIT = 8
const i = Math.round( Math.random() )

class point3D {
  constructor (x, y, z) {
    this.x = x
    this.y = y
    this.z = z
  }
}

// AoS
const AoS_points = Array( N ).fill().map( e =>
	new point3D(
		Math.random(),
		Math.random(),
		Math.random()
	)
)
const AoS_get_point_x = i => AoS_points[i].x

// SoA
const SoA_points = new point3D(
	Array( N ).fill().map( e => Math.random() ),
	Array( N ).fill().map( e => Math.random() ),
	Array( N ).fill().map( e => Math.random() )
)
const SoA_get_point_x = i => SoA_points.x[i]

// AoSoA
const AoSoA_points = Array( Math.ceil( ( N + AoSoA_SPLIT - 1 ) / AoSoA_SPLIT ) ).fill().map( e =>
	new point3D(
		Array( AoSoA_SPLIT ).fill().map( e => Math.random() ),
		Array( AoSoA_SPLIT ).fill().map( e => Math.random() ),
		Array( AoSoA_SPLIT ).fill().map( e => Math.random() )
	)
)
const AoSoA_get_point_x = i => AoSoA_points[Math.floor( i / AoSoA_SPLIT )].x[i % AoSoA_SPLIT]

Test runner

Ready to run.

Testing in
TestOps/sec
Array of structures
"use strict";

AoS_get_point_x( i )
ready
Structure of arrays
"use strict";

SoA_get_point_x( i )
ready
Array of structures of arrays
"use strict";

AoSoA_get_point_x( i )
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.