mpope
Efficient comparision of large data structures
Say I have a very large data structure who’s size is in the 10s of MB. This structure is arbitrarily complex, consisting of many tuples and proplists and maps, but in a roughly tree-like structure. What is the most efficient way to compare two of these structures? Was curious before I started running some benchmarks. Is pattern matching breadth first, or depth first, or does it involve a bit to bit comparison of the terms? Would using zlib on a a term_to_binary then comparing the compressed binaries make sense?
I’m having trouble finding documentation on the generally most efficient way of doing this.
Most Liked
jhogberg
The equality operator terminates as early as it can. Any speed up you got was most likely because you checked the term in an order that happened to be more efficient (equality check uses DFS IIRC).
hauleth
I meant “in matter of performance”.
benwilson512
What kind of comparison are you trying to do? A simple equality check? A diff?
hauleth
There is no difference between == and pattern matching.
aenglisc
I meant “as opposed to comparing hashes or using other tricks”. As far as matching vs equality operators, I believe there shouldn’t be any difference, although to nitpick I vaguely remember pattern matching using the strict operator (=== or =:= in Erlang terms).







