Snake case mapping (v2)

Revision 2 of this benchmark created on


Setup

function camelCaseObject(obj) {
	const result = {};
	for (const key of Object.keys(obj)) {
		const value = obj[key];
		if (value && typeof value === 'object') {
			result[_.camelCase(key)] = camelCaseObject(value);
		} else {
			result[_.camelCase(key)] = value;
		}
	}
	return result;
}

const staff = [
  {
    "uuid": "694045019-25dfa7ea-6f5e-47e4-ae5c-9162236e1f2c",
    "email": "nicholasroach@example.net",
    "preferred_name": "Liz",
    "role": "administrator",
    "permissions": [
      "user_can_manage_staff"
    ],
    "has_staff_pin": true,
    "staff_id": "1234",
    "staff_number": "EMP2022",
    "nested_example": {
    	"foo_bar": 42
    }
  }
];

// Make 10 copies of the staff member.
for (let i = 0; i < 10; ++i) {
	staff.push(staff[0]);
}

const memoryDiffs = [];
let lastUsedJSHeapSize = performance.memory.usedJSHeapSize;
function measureMemory() {
	const current = performance.memory.usedJSHeapSize;
	memoryDiffs.push(current - lastUsedJSHeapSize);
	lastUsedJSHeapSize = current;
}

Teardown

console.log('MEMORY DIFF', memoryDiffs.reduce((t, n) => t + n, 0));

Test runner

Ready to run.

Testing in
TestOps/sec
Identity
staff;
ready
Lodash
camelCaseObject(staff);
measureMemory();
ready

Revisions

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