Clearly Seq asymptotically performs the same or better as [] for all possible operations. But since its structure is more complicated than lists, for small sizes its constant overhead will probably make it slower. I'd like to know how much, in particular:
- How much slower is
<|compared to:? - How much slower is folding over/traversing
Seqcompared to folding over/traversing[](excluding the cost of a folding/traversing function)? - What is the size (approximately) for which
\xs x -> xs ++ [x]becomes slower than|>? - What is the size (approximately) for which
++becomes slower than><? - What's the cost of calling
viewland pattern matching on the result compared to pattern matching on a list? - How much memory does an
n-elementSeqoccupy compared to ann-element list? (Not counting the memory occupied by the elements, only the structure.)
I know that it's difficult to measure, since with Seq we talk about amortized complexity, but I'd like to know at least some rough numbers.
This should be a start - http://www.haskell.org/haskellwiki/Performance#Data.Sequence_vs._lists
A sequence uses between 5/6 and 4/3 times as much space as the equivalent list (assuming an overhead of one word per node, as in GHC). If only deque operations are used, the space usage will be near the lower end of the range, because all internal nodes will be ternary. Heavy use of split and append will result in sequences using approximately the same space as lists. In detail:
List is a non-trivial constant-factor faster for operations at the head (cons and head), making it a more efficient choice for stack-like and stream-like access patterns. Data.Sequence is faster for every other access pattern, such as queue and random access.