Imperative vs functional styles for Vector3 operations

Benchmark created on


Setup

function add(a, b){
	return {
		x: a.x+b.x, 
		y: a.y+b.y,
		z: a.z+b.z}
}

class Vector3{
	constructor(x,y,z){
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	add(b){
		this.x += b.x;
		this.y += b.y;
		this.z += b.z;
	}
}

let positionFunctional = {x:0,y:0,z:0}
let velocityFunctional = {x:1,y:1,z:1}
const positionImperative = new Vector3(0,0,0);
const velocityImperative = new Vector3(1,1,1);

Test runner

Ready to run.

Testing in
TestOps/sec
Add two Vector3s (Functional Style)
positionFunctional = add(positionFunctional, velocityFunctional);
ready
Add two Vector3s (Imperative Style)
positionImperative.add(velocityImperative);
ready

Revisions

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