Skip to content

Commit

Permalink
myers dff algo
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyTimes committed Apr 11, 2022
1 parent b2f6f96 commit 5bd7b76
Show file tree
Hide file tree
Showing 8 changed files with 856 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ members = [
'crates/skw-contract-sys',
'crates/skw-contract-sim',

# a Myers Diff algo impl
'crates/skw-myers-diff',

# sgx enclave host
'crates/skw-sgx-ipfs',
]
Expand Down
18 changes: 18 additions & 0 deletions crates/skw-myers-diff/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "skw-myers-diff"
version = "0.0.0"
license = "GPL-3.0"
authors = ["SkyeKiwi <[email protected]>", "Near Inc <[email protected]>"]
publish = false
# Please update rust-toolchain.toml as well when changing version here:
rust-version = "1.56.0"
edition = "2021"

[dev-dependencies]
bencher = "0.1"
rand = "0.8.5"

[[bench]]
name = "diff_patch"
path = "src/bench.rs"
harness = false
43 changes: 43 additions & 0 deletions crates/skw-myers-diff/src/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#[macro_use]
extern crate bencher;

use bencher::{Bencher};

use skw_myers_diff::{diff, patch, diff_ops_to_bytes, bytes_to_diff_ops};

macro_rules! random_bytes{
($len:expr) => ({
let mut bytes = [0_u8; $len];
for byte in bytes.iter_mut() {
*byte = rand::random::<u8>();
}
bytes
})
}

fn diff_n_patch(bench: &mut Bencher) {
let mut original = random_bytes!(1000);
let mut modified = random_bytes!(10000);

bench.iter(|| {
let res = diff(&mut original[..], &mut modified[..]);
let r = patch(res, &original[..]);

assert_eq!(r, modified);
});
}

fn parse_diff_op(bench: &mut Bencher) {
let mut original = random_bytes!(1000);
let mut modified = random_bytes!(100000);
let res = diff(&mut original[..], &mut modified[..]);

bench.iter(|| {
let bytes = diff_ops_to_bytes(res.clone());
let r = bytes_to_diff_ops(&bytes[..]);
assert_eq!(r, res);
});
}

benchmark_group!(benches, parse_diff_op, diff_n_patch);
benchmark_main!(benches);
7 changes: 7 additions & 0 deletions crates/skw-myers-diff/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod types;
mod parse;
mod myers;

pub use types::{DiffOp};
pub use parse::{diff_ops_to_bytes, bytes_to_diff_ops};
pub use myers::{diff, patch};
Loading

0 comments on commit 5bd7b76

Please sign in to comment.