Switch vs Object

Benchmark created on


Setup

const event = 'bookmark_edit_bookmarks_mystuff_open';

const data = {};

Test runner

Ready to run.

Testing in
TestOps/sec
Event Lookup
const eventLookup = {
    'save-click': 'save_click',
    'save-success': 'save_success',
    'unsave': 'save_unsave',
    'find-more': ('button', {ctaText: data.ctaText}),
    'sign-up': 'save_modal_signup',
    'sign-in': 'save_modal_signin',
    'modal-close': 'save_modal_close',
    'save-cap-modal-view': 'save_cap_modal_view',
    'save-cap-modal-join': 'save_cap_modal_join',
    'save-cap-modal-close': 'save_cap_modal_close',
    'tooltip-view': 'contentsaved_tooltip_view',
    'tooltip-link-click': 'contentsaved_tooltip_clicktomystuff',
    'exclusives-subscription-modal-view': 'save_exclusives_subscription_modal_view',
    'exclusives-subscription-modal-join': 'save_exclusives_subscription_modal_join',
    'exclusives-subscription-modal-close': 'save_exclusives_subscription_modal_close',
    'edit-bookmarks-mystuff-confirm': 'bookmark_edit_bookmarks_mystuff_confirm',
    'edit-bookmarks-myStuff-click': 'bookmark_edit_bookmarks_mystuff_open',
    'create-folder-save-modal-content-open': 'bookmark_create_folder_bookmarkmodal_open',
    'create-folder-save-modal-content-confirm': 'bookmark_create_folder_bookmarkmodal_confirm',
    'create-folder-menu-panel-confirm': 'bookmark_create_folder_mystuff_confirm',
    'create-folder-menu-panel-open': 'bookmark_create_folder_mystuff_open',
    'edit-bookmarks-article-confirm': 'bookmark_edit_bookmarks_article_confirm',
    'edit-bookmarks-article-open': 'bookmark_edit_bookmarks_article_open',
    'create-folder-article-open': 'bookmark_create_folder_article_open',
    'create-folder-article-confirm': 'bookmark_create_folder_article_confirm',
};

const result = eventLookup[event];
if (result) {
    name = result;
} else {
    return false;
}
ready
Switch / Case
switch (event) {
		case 'save-click':
			name = 'save_click';
			break;
		case 'save-success':
			name = 'save_success';
			break;
		case 'unsave':
			name = 'save_unsave';
			break;
		case 'find-more':
			ctaText = data.ctaText;
			name = 'button';
			break;
		case 'sign-up':
			name = 'save_modal_signup';
			break;
		case 'sign-in':
			name = 'save_modal_signin';
			break;
		case 'modal-close':
			name = 'save_modal_close';
			break;
		case 'save-cap-modal-view':
			name = 'save_cap_modal_view';
			break;
		case 'save-cap-modal-join':
			name = 'save_cap_modal_join';
			break;
		case 'save-cap-modal-close':
			name = 'save_cap_modal_close';
			break;
		case 'tooltip-view':
			name = 'contentsaved_tooltip_view';
			break;
		case 'tooltip-link-click':
			name = 'contentsaved_tooltip_clicktomystuff';
			break;
		case 'exclusives-subscription-modal-view':
			name = 'save_exclusives_subscription_modal_view';
			break;
		case 'exclusives-subscription-modal-join':
			name = 'save_exclusives_subscription_modal_join';
			break;
		case 'exclusives-subscription-modal-close':
			name = 'save_exclusives_subscription_modal_close';
			break;
		case 'edit-bookmarks-mystuff-confirm':
			name = 'bookmark_edit_bookmarks_mystuff_confirm';
			break;
		case 'edit-bookmarks-myStuff-click':
			name = 'bookmark_edit_bookmarks_mystuff_open';
			break;
		case 'create-folder-save-modal-content-open':
			name = 'bookmark_create_folder_bookmarkmodal_open';
			break;
		case 'create-folder-save-modal-content-confirm':
			name = 'bookmark_create_folder_bookmarkmodal_confirm';
			break;
		case 'create-folder-menu-panel-confirm':
			name = 'bookmark_create_folder_mystuff_confirm';
			break;
		case 'create-folder-menu-panel-open':
			name = 'bookmark_create_folder_mystuff_open';
			break;
		case 'edit-bookmarks-article-confirm':
			name = 'bookmark_edit_bookmarks_article_confirm';
			break;
		case 'edit-bookmarks-article-open':
			name = 'bookmark_edit_bookmarks_article_open';
			break;
		case 'create-folder-article-open':
			name = 'bookmark_create_folder_article_open';
			break;
		case 'create-folder-article-confirm':
			name = 'bookmark_create_folder_article_confirm';
			break;
		default:
			return false;
	}
ready

Revisions

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