Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Includes vs has
(version: 1)
Comparing performance of:
isText valid vs isText invalid vs isText as Set valid vs isText as Set invalid
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
const modifierKeys = [ 'Alt', 'AltGraph', 'CapsLock', 'Control', 'Fn', 'FnLock', 'Meta', 'NumLock', 'ScrollLock', 'Shift', 'Symbol', 'SymbolLock', 'Hyper', 'Super', 'OS', // https://bugzilla.mozilla.org/show_bug.cgi?id=1232918) ]; const whitespaceKeys = ['Enter', 'Tab']; const navigationKeys = [ 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'End', 'Home', 'PageDown', 'PageUp', ]; const editingKeys = [ 'Backspace', 'Clear', 'Copy', 'CrSel', 'Cut', 'Delete', 'EraseEof', 'ExSel', 'Insert', 'Paste', 'Redo', 'Undo', ]; const uiKeys = [ 'Accept', 'Again', 'Attn', 'Cancel', 'ContextMenu', 'Escape', 'Execute', 'Find', 'Help', 'Pause', 'Play', 'Props', 'Select', 'ZoomIn', 'ZoomOut', ]; const deviceKeys = [ 'BrightnessDown', 'BrightnessUp', 'Eject', 'LogOff', 'Power', 'PowerOff', 'PrintScreen', 'Hibernate', 'Standby', 'WakeUp', ]; const compositionKeys = [ 'AllCandidates', 'Alphanumeric', 'CodeInput', 'Compose', 'Convert', // When a user presses alt+e, alt+u, etc on a Mac, the key value is "Dead" // i.e, a dead character for an accent that'll be used next 'Dead', 'FinalMode', 'GroupFirst', 'GroupLast', 'GroupNext', 'GroupPrevious', 'ModeChange', 'NextCandidate', 'NonConvert', 'PreviousCandidate', 'Process', 'SingleCandidate', 'HangulMode', 'HanjaMode', 'JunjaMode', 'Eisu', 'Hankaku', 'Hiragana', 'HiraganaKatakana', 'KanaMode', 'KanjiMode', 'Katakana', 'Romaji', 'Zenkaku', 'ZenkakuHankaku', ]; const fnKeys = [ 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'Soft1', 'Soft2', 'Soft3', 'Soft4', ]; const multimediaKeys = [ 'ChannelDown', 'ChannelUp', 'Close', 'MailForward', 'MailReply', 'MailSend', 'MediaClose', 'MediaFastForward', 'MediaPause', 'MediaPlay', 'MediaPlayPause', 'MediaRecord', 'MediaRewind', 'MediaStop', 'MediaTrackNext', 'MediaTrackPrevious', 'New', 'Open', 'Print', 'Save', 'SpellCheck', ]; const audioKeys = [ 'AudioBalanceLeft', 'AudioBalanceRight', 'AudioBassBoostDown', 'AudioBassBoostToggle', 'AudioBassBoostUp', 'AudioFaderFront', 'AudioFaderRear', 'AudioSurroundModeNext', 'AudioTrebleDown', 'AudioTrebleUp', 'AudioVolumeDown', 'AudioVolumeUp', 'AudioVolumeMute', 'MicrophoneToggle', 'MicrophoneVolumeDown', 'MicrophoneVolumeUp', 'MicrophoneVolumeMute', ]; const speechKeys = ['SpeechCorrectionList', 'SpeechInputToggle']; const applicationKeys = [ 'LaunchApplication1', 'LaunchApplication2', 'LaunchCalendar', 'LaunchContacts', 'LaunchMail', 'LaunchMediaPlayer', 'LaunchMusicPlayer', 'LaunchPhone', 'LaunchScreenSaver', 'LaunchSpreadsheet', 'LaunchWebBrowser', 'LaunchWebCam', 'LaunchWordProcessor', ]; const browserKeys = [ 'BrowserBack', 'BrowserFavorites', 'BrowserForward', 'BrowserHome', 'BrowserRefresh', 'BrowserSearch', 'BrowserStop', ]; const mobilePhoneKeys = [ 'AppSwitch', 'Call', 'Camera', 'CameraFocus', 'EndCall', 'GoBack', 'GoHome', 'HeadsetHook', 'LastNumberRedial', 'Notification', 'MannerMode', 'VoiceDial', ]; const tvKeys = [ 'TV', 'TV3DMode', 'TVAntennaCable', 'TVAudioDescription', 'TVAudioDescriptionMixDown', 'TVAudioDescriptionMixUp', 'TVContentsMenu', 'TVDataService', 'TVInput', 'TVInputComponent1', 'TVInputComponent2', 'TVInputComposite1', 'TVInputComposite2', 'TVInputHDMI1', 'TVInputHDMI2', 'TVInputHDMI3', 'TVInputHDMI4', 'TVInputVGA1', 'TVMediaContext', 'TVNetwork', 'TVNumberEntry', 'TVPower', 'TVRadioService', 'TVSatellite', 'TVSatelliteBS', 'TVSatelliteCS', 'TVSatelliteToggle', 'TVTerrestrialAnalog', 'TVTerrestrialDigital', 'TVTimer', ]; const mediaControllerKeys = [ 'AVRInput', 'AVRPower', 'ColorF0Red', 'ColorF1Green', 'ColorF2Yellow', 'ColorF3Blue', 'ColorF4Grey', 'ColorF5Brown', 'ClosedCaptionToggle', 'Dimmer', 'DisplaySwap', 'DVR', 'Exit', 'FavoriteClear0', 'FavoriteClear1', 'FavoriteClear2', 'FavoriteClear3', 'FavoriteRecall0', 'FavoriteRecall1', 'FavoriteRecall2', 'FavoriteRecall3', 'FavoriteStore0', 'FavoriteStore1', 'FavoriteStore2', 'FavoriteStore3', 'Guide', 'GuideNextDay', 'GuidePreviousDay', 'Info', 'InstantReplay', 'Link', 'ListProgram', 'LiveContent', 'Lock', 'MediaApps', 'MediaAudioTrack', 'MediaLast', 'MediaSkipBackward', 'MediaSkipForward', 'MediaStepBackward', 'MediaStepForward', 'MediaTopMenu', 'NavigateIn', 'NavigateNext', 'NavigateOut', 'NavigatePrevious', 'NextFavoriteChannel', 'NextUserProfile', 'OnDemand', 'Pairing', 'PinPDown', 'PinPMove', 'PinPToggle', 'PinPUp', 'PlaySpeedDown', 'PlaySpeedReset', 'PlaySpeedUp', 'RandomToggle', 'RcLowBattery', 'RecordSpeedNext', 'RfBypass', 'ScanChannelsToggle', 'ScreenModeNext', 'Settings', 'SplitScreenToggle', 'STBInput', 'STBPower', 'Subtitle', 'Teletext', 'VideoModeNext', 'Wink', 'ZoomToggle', ]; function isText(eventKey) { return !modifierKeys.includes(eventKey) && !whitespaceKeys.includes(eventKey) && !navigationKeys.includes(eventKey) && !editingKeys.includes(eventKey) && !uiKeys.includes(eventKey) && !deviceKeys.includes(eventKey) && !compositionKeys.includes(eventKey) && !fnKeys.includes(eventKey) && !multimediaKeys.includes(eventKey) && !audioKeys.includes(eventKey) && !speechKeys.includes(eventKey) && !applicationKeys.includes(eventKey) && !browserKeys.includes(eventKey) && !mobilePhoneKeys.includes(eventKey) && !tvKeys.includes(eventKey) && !mediaControllerKeys.includes(eventKey); } const keysAsSet = new Set([...whitespaceKeys, ...navigationKeys, ...editingKeys, ...uiKeys, ...deviceKeys, ...compositionKeys, ...fnKeys, ...multimediaKeys, ...audioKeys, ...speechKeys, ...applicationKeys, ...browserKeys, ...mobilePhoneKeys, ...tvKeys, ...mediaControllerKeys]); function isTextAsSet(eventKey) { return keysAsSet.has(eventKey); }
Tests:
isText valid
return isText('BrowserStop');
isText invalid
return isText('sarasa');
isText as Set valid
return isTextAsSet('BrowserStop');
isText as Set invalid
return isTextAsSet('sarasa');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
isText valid
isText invalid
isText as Set valid
isText as Set invalid
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Object values vs _.values vs improved polyfill
isEmptyObject: keys vs for in
Immutable.JS get vs object access
Immutable.JS keyseq + toarray vs object keys
Immutable.JS get vs object access vs map get
Comments
Confirm delete:
Do you really want to delete benchmark?