concordancejs / concordance

Compare, format, diff and serialize any JavaScript value

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add perf comparison to pretty-format

capaj opened this issue · comments

I'd like to see which package does it faster because it seems to me both are doing pretty similar thing.
https://github.com/facebook/jest/tree/master/packages/pretty-format

I've actually included the performance test from pretty-format in this repo, though I haven't kept it up to date or run it in a while. Currently soundness is more important than performance.

The tl;dr is that pretty-format is undoubtedly faster, and Concordance won't ever beat it in performance. But, that's not what Concordance was built for!

The first performance hurdle is that Concordance creates descriptor objects for the value being formatted. These objects carry the comparison, formatting, diffing and serialization logic.

The second hurdle specific to formatting is that Concordance creates objects for each formatted line, and creates line buffers as it walks the value being formatted. These objects are needed so diffing can reuse the formatting logic. pretty-format just uses string concatenation. You'd diff those output strings, whereas with Concordance diffing happens on a structural level.

Lastly Concordance formats more aspects of JavaScript values, which may or may not be significant. It can make performance tests misleading though: depending on the value being formatted Concordance inevitably has to do more work, regardless of the aforementioned performance hurdles. Error objects are a good example here.

For AVA the idea is that comparisons should be fast (enough). If all your tests pass there is nothing to format, so formatting performance is less important.

This may not hold true for other use cases. You'll have to decide which formatting output fits your use case and whether the performance differences are important enough.