test (v3)

Revision 3 of this benchmark created on


Description

test

Preparation HTML

test

Setup

const orderMessages = new Map([
  ['pending', 'Order is pending.'],
  ['shipped', 'Order has been shipped.'],
  ['delivered', 'Order has been delivered.'],
]);

function getOrderMessage(status) {
  return orderMessages.get(status);
}

console.log(getOrderMessage('pending'));   // "Order is pending."
console.log(getOrderMessage('shipped'));   // "Order has been shipped."
console.log(getOrderMessage('delivered')); // "Order has been delivered."

Teardown

const orderMessages = new Map([
  ['pending', 'Order is pending.'],
  ['shipped', 'Order has been shipped.'],
  ['delivered', 'Order has been delivered.'],
]);

function getOrderMessage(status) {
  return orderMessages.get(status);
}

console.log(getOrderMessage('pending'));   // "Order is pending."
console.log(getOrderMessage('shipped'));   // "Order has been shipped."
console.log(getOrderMessage('delivered')); // "Order has been delivered."

Test runner

Ready to run.

Testing in
TestOps/sec
if
function getOrderMessage(status) {
    if (status === 'pending') {
        return 'Order is pending.';
    } else if (status === 'shipped') {
        return 'Order has been shipped.';
    } else if (status === 'delivered') {
        return 'Order has been delivered.';
    }
}

getOrderMessage('pending');
getOrderMessage('shipped');
getOrderMessage('delivered');
ready
object
const orderMessages = {
    'pending': 'Order is pending.',
    'shipped': 'Order has been shipped.',
	'delivered': 'Order has been delivered.',
};

function getOrderMessage(status) {
    return orderMessages[status];
}

getOrderMessage('pending');
getOrderMessage('shipped');
getOrderMessage('delivered');
ready
switch-case
function getOrderMessage(status) {
    switch (status) {
        case 'pending':
            return 'Order is pending.';
        case 'shipped':
            return 'Order has been shipped.';
        case 'delivered':
            return 'Order has been delivered.';
        default:
            return 'Unknown order status.';
    }
}

getOrderMessage('pending');
getOrderMessage('shipped');
getOrderMessage('delivered');
ready

Revisions

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