Skip to content

String comparison #1

@stevensonmt

Description

@stevensonmt

Not sure it has any performance impact, but just FYI since Elixir does bitstring comparison byte by byte and your city keys are going to be unique strings (enforced by using them as keys for a map) you don't gain anything by comparing against the key versus comparing against the generated string in this function:

 keys_strings =
      Map.keys(combined_map)
      |> Enum.map(fn key ->
        {min_temp, count, sum, max_temp} = Map.get(combined_map, key)

        {key,
         "#{key}=#{min_temp / 10}/#{:erlang.float_to_binary(sum / (count * 10), decimals: 1)}/#{max_temp / 10}"}
      end)

    # sort the strings by city/key then discard the key, keep the output
    sorted_strings = Enum.sort_by(keys_strings, &elem(&1, 0)) |> Enum.map(&elem(&1, 1))

and you might get a tiny performance improvement by avoiding a second Enum.map call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions