The article is saying that using the
List |> sort |> and fold can be faster than
Set |> fromList |> toList. And proves it with Benchmarking those two approaches on the reverse List with few duplicities and list with a lots of duplicities:
But then I found out that the blogpost is from 2018, and I’m unable to run the old Ellie to see for myself. So I have recreated the benchmark and run it with the current Elm version and I have ran it.
What do you think the result looks like?
Well, it is one of those funny ones as… it is inconclusive
The result of benchmark for small number of duplicities used in the original article is still faster with
sort |> fold method, but not 10x but 4x.
But the second part where you have a list with lots of duplicities is having different outcome than in the article as the
Set |> fromList |> toList performs better by 33% compared to being 2x slower in the article version.
Try it out for yourself in the Ellie: https://ellie-app.com/byLyGTsH9rFa1
So the conclusion? It is interesting to know that the
List |> sort |> fold is faster when you have fewer duplications, but it is hard to tell from what number of duplicities it is outperformed by the
Set |> fromList |> toList approach.
Lesson from this short exercise: Trust no one! And rather try the hypothesis out by yourself if you have a chance.
@Janiczek ran the benchmark with
--optimize flag and here are the results