Data Structure Comparison in a Typed Context

JavaScript performance comparison

Test case created by TejasQ

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  // Hard to type, but fast
  const fastHardToTypeDataStructure = {
  	uuid_1: {
        name: "Tejas",
        hasACrushOn: "@dan_abramov",
        crushKnows: "maybe",
      },
  	uuid_2: {
        name: "Ken",
        hasACrushOn: "wife's cheeks",
        crushKnows: "yes",
      },
  	uuid_3: {
        name: "Gabe",
        hasACrushOn: "@tejaskumar_",
        crushKnows: "yes", // awkward love triangle
      },
  };
  
  // More common in TypeScript/GraphQL, but slow
  const slowTypeSafeDataStructure = [
  	{
        id: "uuid_1",
        name: "Tejas",
        hasACrushOn: "@dan_abramov",
        crushKnows: "maybe",
      },
  	{
        id: "uuid_2",
        name: "Ken",
        hasACrushOn: "wife's cheeks",
        crushKnows: "yes",
      },
  	{
        id: "uuid_3",
        name: "Gabe",
        hasACrushOn: "@tejaskumar_",
        crushKnows: "yes", // awkward love triangle
      },
  ];
  
  // Let's find this ID.
  const target = "uuid_2";

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Constant complexity on hard to type example
fastHardToTypeDataStructure[target];
pending…
Linear complexity on type-safe example
slowTypeSafeDataStructure.find(i => i.id === target);
pending…

Revisions

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

0 Comments