View Source mix timings.keyed (Lens 2 v0.2.1)

Crude timings that compare Access and Lens operations on a struct+map container.

The container has this structure:

 .Network{
   cluster_count: 10,
   names_by_index: %{
     1 => :name1,
     2 => :name2,
     3 => :name3,
     ...
   },
   clusters_by_name: %{
     name1: %Mix.Tasks.Timings.Keyed.Cluster{
       router: %{c: 0, a: 0, d: 0, b: 0, e: 0},
       fun: &Kernel.inspect/1,
       string: ":name1",
       atom1: :name1
     },
     name2: %Mix.Tasks.Timings.Keyed.Cluster{
       router: %{c: 0, a: 0, d: 0, b: 0, e: 0},
       fun: &Kernel.inspect/1,
       string: ":name2",
       atom1: :name2
     },
     ...
   }
 }

Get operations (get_in, Deeply.get_all) extract values like

 network.clusters_by_name[:name2].router.[:c]

Update operations increment those values.

Call with a list of the number of clusters:

  % mix timings.keyed 10 100 1000

Each number creates a scaled network and runs the operation 40_000_000 times.

I wrote this because I realized that Deeply.get_all will create a copy of the original structure as it "retreats" from finding the gotten values. Fortunately, for maps and structs, Map.put(container, key, new_value) actually returns the original container if the new value is the same as the existing value, so that's not so bad. But it's interesting to compare Access to Lens anyway.