Map versus consts (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script type="module">
import { css } from "https://unpkg.com/@microsoft/fast-element@2.0.0/dist/fast-element.min.js"

globalThis.css = css;

const CustomStatesSetSupported = CSS.supports('selector(:state(g))');

const statesMap = new Map();

globalThis.stateSelector = function stateSelector(state) {
  return (statesMap.get(state) ??
    statesMap
      .set(state, CustomStatesSetSupported ? `:state(${state})` : `[state--${state}]`)
      .get(state));
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
StateSelector
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
stateSelector('foo');
stateSelector('bar');
ready
CSS Partial
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
css.partial`:is(:state(foo), [state--foo])`;
css.partial`:is(:state(bar), [state--bar])`;
ready

Revisions

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