performance

Pattern matching obviously comes at a price: there is some overhead involved in matching, with respect to the equivalent hand-coded tests and accesses to sub-data. For custom notations to be usable in practice, it is a very important question whether the performance price to be paid is acceptable.

Since myPatterns generalize regex pattern matching of strings, let us take this as a reference.

The overhead of regex matching in JavaScript can be easily measured using a simple benchmark. On our platform, we obtain an overhead of 2.5 - 3 times over a hand-crafted version that doesn't use pattern matching.

Matching with myPatterns on a very matching-intensive benchmark (red-black trees) incurs an overhead of 3.8 - 5 times when parsed patterns are used, in comparison to hand-crafted code that doesn't use pattern matching. Thus, with respect to regex matching, myPatterns adds an extra factor of about 1.1 - 2.5 times.

We think that this extra factor over regex matching is quite acceptable for many practical purposes, in regards of the extra generality related to matching general data structures, especially when combined with custom notations.


Up: myPatterns tutorial