You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • How does {} compare to the map code above?

    The map code will be slower because it's executing more JS, but both will take O(n) time and delegate the search itself to the interpreter so the map implementation isn't going to be that bad. Using indexOf is definitely slower than a map access because Espruino's object access can check the keys quickly at first rather than doing a full equality test, but it'd be interesting to do some benchmarks.

    I'd definitely say use {} if you're at all able to though - it'll use less memory, is faster, and will probably get a lot better in future versions of Espruino too.


Avatar for Gordon @Gordon started