Object Lookup vs Comparison Function (v3)

Revision 3 of this benchmark created on


Setup

const CATEGORY_A = "Category A";
const CATEGORY_B = "Category B";
const CATEGORY_C = "Category C";
const CATEGORY_D = "Category D";
const CATEGORY_E = "Category E";
const CATEGORY_F = "Category F";
const CATEGORY_G = "Category G";
const CATEGORY_H = "Category H";
const CATEGORY_I = "Category I";
const CATEGORY_J = "Category J";
const CATEGORY_K = "Category K";

function lookupCategoryName(category) {
	if (category === CATEGORY_A) {
		return "Name A";
	}
	if (category === CATEGORY_B) {
		return "Name B";
	}
	if (category === CATEGORY_C) {
		return "Name C";
	}
	if (category === CATEGORY_D) {
		return "Name D";
	}
	if (category === CATEGORY_E) {
		return "Name E";
	}
	if (category === CATEGORY_F) {
		return "Name F";
	}
	if (category === CATEGORY_G) {
		return "Name G";
	}
	if (category === CATEGORY_H) {
		return "Name H";
	}
	if (category === CATEGORY_I) {
		return "Name I";
	}
	if (category === CATEGORY_J) {
		return "Name J";
	}
	if (category === CATEGORY_K) {
		return "Name K";
	}
}


const LOOKUP_OBJECT = {};
LOOKUP_OBJECT[CATEGORY_A] = "Name A";
LOOKUP_OBJECT[CATEGORY_B] = "Name B";
LOOKUP_OBJECT[CATEGORY_C] = "Name C";
LOOKUP_OBJECT[CATEGORY_D] = "Name D";
LOOKUP_OBJECT[CATEGORY_E] = "Name E";
LOOKUP_OBJECT[CATEGORY_F] = "Name F";
LOOKUP_OBJECT[CATEGORY_G] = "Name G";
LOOKUP_OBJECT[CATEGORY_H] = "Name H";
LOOKUP_OBJECT[CATEGORY_I] = "Name I";
LOOKUP_OBJECT[CATEGORY_J] = "Name J";
LOOKUP_OBJECT[CATEGORY_K] = "Name K";

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");
let d = lookupCategoryName("Category D");
let e = lookupCategoryName("Category E");
let f = lookupCategoryName("Category F");
let g = lookupCategoryName("Category G");
let h = lookupCategoryName("Category H");
let i = lookupCategoryName("Category I");
let j = lookupCategoryName("Category J");
let k = lookupCategoryName("Category K");

ready
Object Lookup
let a = LOOKUP_OBJECT["Category A"];
let b = LOOKUP_OBJECT["Category B"];
let c = LOOKUP_OBJECT["Category C"];
let d = LOOKUP_OBJECT["Category D"];
let e = LOOKUP_OBJECT["Category E"];
let f = LOOKUP_OBJECT["Category F"];
let g = LOOKUP_OBJECT["Category G"];
let h = LOOKUP_OBJECT["Category H"];
let i = LOOKUP_OBJECT["Category I"];
let j = LOOKUP_OBJECT["Category J"];
let k = LOOKUP_OBJECT["Category K"];
ready

Revisions

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