my fork of dmp
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 44 |
1 files changed, 20 insertions, 24 deletions
@@ -1,21 +1,18 @@ # diff-match-patch-rs: Efficient port of Google's diff-match-patch implemented in Rust -A very **fast**, **accurate** and **wasm ready** port of [Diff Match Patch](https://github.com/dmsnell/diff-match-patch) in Rust. The -diff implementation is based on [Myers' diff algorithm](https://neil.fraser.name/writing/diff/myers.pdf). - +A very **fast**, **accurate** and **wasm ready** port of [Diff Match Patch](https://github.com/dmsnell/diff-match-patch) in Rust. The diff implementation is based on [Myers' diff algorithm](https://neil.fraser.name/writing/diff/myers.pdf). ## Highlights of this crate - Exposes two modes of operating with `diff-match-patch`, a `Efficient` mode and `Compat` mode. While the `Efficient` mode squeezes out the max performance the `Compat` mode ensures compatibility across other libraries or implementations (rust or otherwise). According to [Benchmarks](#benchmarks), our slower `Compat` mode is still faster than other implementations in rust. - - `**Efficient**` mode works on `&[u8]` and the generated diffs break compatibility with other implementation. Use the `**Efficient**` mode ONLY if you are using this `[crate]()` at the source of diff generation and the destination. - - `**Compat**` mode on the other hand works on `&[char]` and the generated `diffs` and `patches` are compatible across other implementations of `diff-match-patch`. Checkout `tests/compat.rs` for some test cases around this. -- `wasm` ready, you can check out a `[demo here](https://github.com/AnubhabB/wasm-diff.git)` -- **Accurate**, can't believe I have to write this but during the course of this implementation I've realised there are a bunch of implementations that have some implementation issues (wrong diffs, inaccurate flows, silent errors etc.). -- Helper method **pretty_html** provided by this crate is a bit more advanced and allows some configurations to control the generated visuals elements. + - **`Efficient`** mode works on `&[u8]` and the generated diffs break compatibility with other implementation. Use the **`Efficient`** mode ONLY if you are using this [crate](https://crates.io/crates/diff-match-patch-rs) at the source of diff generation and the destination. + - **`Compat`** mode on the other hand works on `&[char]` and the generated `diffs` and `patches` are compatible across other implementations of `diff-match-patch`. Checkout `tests/compat.rs` for some test cases around this. +- `wasm` ready, you can check out a [demo here](https://github.com/AnubhabB/wasm-diff.git) +- **Accurate**, while working on this crate I've realized that there are a bunch of implementations that have major issues (wrong diffs, inaccurate flows, silent errors etc.). +- Helper method **pretty_html** provided by this crate allows some configurations to control the generated visuals elements. - Well tested - Added a `fuzzer` for sanity - Exposes the same APIs as [Diff Match Patch](https://github.com/dmsnell/diff-match-patch) with minor changes to make it more idiomatic in Rust. - ## Usage Examples ### `Effitient` mode @@ -24,10 +21,10 @@ diff implementation is based on [Myers' diff algorithm](https://neil.fraser.name use diff_match_patch_rs::{DiffMatchPatch, Efficient, Error, PatchInput}; // This is the source text -const TXT_OLD: &str = "I am the very model of a modern Major-General, I've information on vegetable, animal, and mineral, ๐๐๐" +const TXT_OLD: &str = "I am the very model of a modern Major-General, I've information on vegetable, animal, and mineral, ๐๐๐"; // Let's assume this to be the text that was editted from the source text -const TXT_NEW: &str = "I am the very model of a cartoon individual, My animation's comical, unusual, and whimsical.๐๐" +const TXT_NEW: &str = "I am the very model of a cartoon individual, My animation's comical, unusual, and whimsical.๐๐"; // An example of a function that creates a diff and returns a set of patches serialized fn at_source() -> Result<String, Error> { @@ -85,10 +82,10 @@ fn main() -> Result<(), Error> { use diff_match_patch_rs::{DiffMatchPatch, Compat, Error, PatchInput}; // This is the source text -const TXT_OLD: &str = "I am the very model of a modern Major-General, I've information on vegetable, animal, and mineral, ๐๐๐" +const TXT_OLD: &str = "I am the very model of a modern Major-General, I've information on vegetable, animal, and mineral, ๐๐๐"; // Let's assume this to be the text that was editted from the source text -const TXT_NEW: &str = "I am the very model of a cartoon individual, My animation's comical, unusual, and whimsical.๐๐" +const TXT_NEW: &str = "I am the very model of a cartoon individual, My animation's comical, unusual, and whimsical.๐๐"; // An example of a function that creates a diff and returns a set of patches serialized fn at_source() -> Result<String, Error> { @@ -144,6 +141,8 @@ The `Efficient` and `Compat` mode APIs are identical with the only chage being t E.g. we initiated a `diff` in the `Efficient` mode with `dmp.diff_main::<Efficient>( ... )` while for `Compat` mode we did `dmp.diff_main::<Compat>( ... )`. +Please checkout the `examples` directory of the [source repo](https://github.com/AnubhabB/diff-match-patch-rs/tree/main/examples) for a few common use-cases. + <div class="warning">The `Effitient` and `Compat` modes are mutually exclusive and will not generate correct output if used interchangibly at source and destination</div> ## Benchmarks @@ -151,24 +150,21 @@ Benchmarks are maintained [diff-match-patch-bench repository](https://github.com | Lang. | Library | Diff Avg. | Patch Avg. | Bencher | Mode | Correct | |:-------:|:----------------------------------------------------------------------------------------:|:---------:|:----------:|:----------:|:-----------:|:-------:| -| `rust` | [diff_match_patch v0.1.1<sup>**</sup>](https://crates.io/crates/diff_match_patch) | 68.108 ms | 10.596 ms | Criterion | - | โ
| -| `rust` | [diffmatchpatch v0.0.4<sup>***</sup>](https://crates.io/crates/diffmatchpatch) | 66.454 ms | - | Criterion | - | โ | +| `rust` | [diff_match_patch v0.1.1](https://crates.io/crates/diff_match_patch)[^2] | 68.108 ms | 10.596 ms | Criterion | - | โ
| +| `rust` | [diffmatchpatch v0.0.4](https://crates.io/crates/diffmatchpatch)[^3] | 66.454 ms | - | Criterion | - | โ | | `rust` | [dmp v0.2.0](https://crates.io/crates/dmp) | 69.019 ms | 14.654 ms | Criterion | - | โ
| | `rust` | [diff-match-patch-rs](https://github.com/AnubhabB/diff-match-patch-rs.git)<sup>our</sup> | 65.487 ms | 631.13 ยตs | Criterion | `Efficient` | โ
| | `rust` | [diff-match-patch-rs](https://github.com/AnubhabB/diff-match-patch-rs.git)<sup>our</sup> | 65.642 ms | 1.1703 ms | Criterion | `Compat` | โ
| -| `go` | [go-diff<sup>*</sup>](https://github.com/sergi/go-diff) | 50.31 ms | 135.2 ms | go test | - | โ | +| `go` | [go-diff](https://github.com/sergi/go-diff)[^1] | 50.31 ms | 135.2 ms | go test | - | โ | | `node` | [diff-match-patch](https://www.npmjs.com/package/diff-match-patch) | 246.90 ms | 1.07 ms | tinybench | - | โ
| | `python`| [diff-match-patch](https://pypi.org/project/diff-match-patch/) | 1.01 s | 0.25 ms | timeit | - | โ
| -> -> Note: -> Omitting [dissimilar](https://crates.io/crates/dissimilar) from the results, I believe that crate has different goals and a headon benchmark is not fair -> Results: Avg[197.30] High[197.46] Low[197.19] -> -> `*` [go-diff](https://github.com/sergi/go-diff) seems to generate wrong diffs for emoticons. This benchmark is on the text with the emoticons removed. <br> -> `**` Adds an extra clone to the iterator because the `patch_apply` method takes mutable refc. to `diffs` <br> -> `***` The crate [diffmatchpatch v0.0.4](https://crates.io/crates/diffmatchpatch) is still a WIP, cound't find the `patch_apply` method <br> +[^1]: [go-diff](https://github.com/sergi/go-diff) seems to generate wrong diffs for emoticons. This benchmark is on the text with the emoticons removed. +[^2]: Adds an extra clone to the iterator because the `patch_apply` method takes mutable refc. to `diffs`. +[^3]: The crate [diffmatchpatch v0.0.4](https://crates.io/crates/diffmatchpatch) is still a WIP, cound't find the `patch_apply` method. + + ## Related projects |