isString vs typeof === 'string'

Benchmark created on


Setup

const isString = (x) => typeof x === 'string';
const shortString = 'test';
const longString = 'oilu43hrfewnmz 98 8 uidhjas 9-80rh34fuiaewrh4 yq2389riaewrh4 yq2389ry fuehnwfc sepof uq-89 32hfrn sdugfh sd-0389rhqfaiubsd uifs-ea 98 rew;rfnsf -98 23uiofn jikds n fdsa-8g43riufbewiuaewhf c-sd8afesdaufnewarkferwaf-89ewfhuewifhui aef-e89afghjkfdnf a-f8 pufbaewfgewh a-f9e8 yfdiusbafy fuehnwfc sepof uq-89 32hfrn sdugfh sd-0iaewrh4 yq2389ry fuehnwfc sepof uq-89 32hfrn sdugfh sd-0389rhqfaiubsd uifs-ea 98 rew;rfnsf -98 23uiofn jikds n fdsa-8g43riufbewiuaewhf c-sd8afesdaufnewarkferwaf-89ewfhuewifhui aef-e89afghjkfdnf a-f8 pufbaewfgewh a-f9e8 yfdiusbaf389rhqfaiubsd uifs-ea 98 rew;rfnsf -98 23uiofn jikdsiaewrh4 yq2389ry fuehnwfc sepof uq-89 32hfrn sdugfh sd-0389rhqfaiubsd uifs-ea 98 rew;rfnsf -98 23uiofn jikds n fdsa-8g43riufbewiuaewhf c-sd8afesdaufnewarkferwaf-89ewfhuewifhui aef-e89afghjkfdnf a-f8 pufbaewfgewh a-f9e8 yfdiusbaf n fdsa-8g43riufbewiuaewhf c-sd8afesdaufnewarkferwaf-89ewfhuewifhui aef-e89afghjkfdnf a-f8 pufbaewfgewh a-f9e8 yfdiusbafjdks af-dsa89f awhfjeksnafd';
const stringsObj = {
	shortString: shortString,
	longString: longString,
}

const testByCallback = (value, callback) => callback(value);

const testPropertyByCallbackShort = (obj, callback) => callback(obj.shortString);
const testPropertyByCallbackLong = (obj, callback) => callback(obj.longString);

Test runner

Ready to run.

Testing in
TestOps/sec
typeof === 'string' (short)
typeof shortString === 'string'
ready
instanceof String (short)
shortString instanceof String
ready
isString (short)
isString(shortString)
ready
testByCallback (short)
testByCallback(shortString, isString)
ready
testPropertyByCallback (short)
testPropertyByCallbackShort(stringsObj, isString)
ready
typeof === 'string' (long)
typeof longString === 'string'
ready
instanceof String (long)
longString instanceof String
ready
isString (long)
isString(longString)
ready
testByCallback (long)
testByCallback(longString, isString)
ready
testPropertyByCallback (long)
testPropertyByCallbackLong(stringsObj, isString)
ready

Revisions

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