Object Lookup vs Comparison Function (v2)

Revision 2 of this benchmark created on


Setup

const CATEGORY_A = "Category A";
const CATEGORY_B = "Category B";
const CATEGORY_C = "Category C";

function lookupCategoryName(category) {
	if (category === CATEGORY_A) {
		return "Name A";
	}
	if (category === CATEGORY_B) {
		return "Name B";
	}
	if (category === CATEGORY_C) {
		return "Name C";
	}
}


const LOOKUP_OBJECT = {};
LOOKUP_OBJECT[CATEGORY_A] = "Name A";
LOOKUP_OBJECT[CATEGORY_B] = "Name B";
LOOKUP_OBJECT[CATEGORY_C] = "Name C";

Test runner

Ready to run.

Testing in
TestOps/sec
Comparison Function
let a = lookupCategoryName("Category A");
let b = lookupCategoryName("Category B");
let c = lookupCategoryName("Category C");

ready
Object Lookup
let a = LOOKUP_OBJECT["Category A"];
let b = LOOKUP_OBJECT["Category B"];
let c = LOOKUP_OBJECT["Category C"];
ready

Revisions

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