User Agent Data Test (v8)

Revision 8 of this benchmark created on


Setup

function includesUserAgentDataBrandOld(brand) {
    try {
      let result = false;

      (() => {
      	if(navigator.userAgentData) {
          // @ts-ignore: AUTO-IGNORING ALL ERRORS
          for (let i = 0; i < navigator.userAgentData.brands.length; i++) {
            // @ts-ignore: AUTO-IGNORING ALL ERRORS
            if (navigator.userAgentData.brands[i].brand == brand) {
              result = true;
              break;
            }
          }
          }
      })();
      return result;
    } catch ($$e_2) {
      return false;
    }
  }
  
function includesUserAgentDataBrandOptionalChaining(brand) {
      return window.navigator.userAgentData?.brands.some(
        (b) => b.brand === brand
      ) ?? false;
  }
  
  function includesUserAgentDataBrandShortCircuit(brand) {
      return navigator.userAgentData && window.navigator.userAgentData.brands.some(
        (b) => b.brand === brand
      );
  }
  
    function includesUserAgentDataBrandIfStatement(brand) {
    	if(navigator.userAgentData) { 	
    	return window.navigator.userAgentData.brands.some(
        (b) => b.brand === brand
      );
      }
      return false;
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Before
includesUserAgentDataBrandOld("Foo")
ready
Optional Chaining
includesUserAgentDataBrandOptionalChaining("Foo")
ready
Short Circuit
includesUserAgentDataBrandShortCircuit("Foo")
ready
If Satement
includesUserAgentDataBrandIfStatement("Foo")
ready

Revisions

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