From 57641d56b887697e72d74f9a1165035ea998b792 Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez <82833619+notalfredo@users.noreply.github.com> Date: Sun, 2 Jul 2023 09:42:54 -0500 Subject: [PATCH] chore: adding typediff crate (#46) --- crates/semantic_typediff/Cargo.toml | 31 +++++++++++++++++++ crates/semantic_typediff/README.md | 5 +++ .../benches/criterion/fibb.rs | 17 ++++++++++ crates/semantic_typediff/benches/iai/fibb.rs | 19 ++++++++++++ crates/semantic_typediff/fuzz/.gitignore | 3 ++ crates/semantic_typediff/fuzz/Cargo.toml | 25 +++++++++++++++ .../fuzz/fuzz_targets/fuzz_target_1.rs | 6 ++++ crates/semantic_typediff/src/lib.rs | 1 + 8 files changed, 107 insertions(+) create mode 100644 crates/semantic_typediff/Cargo.toml create mode 100644 crates/semantic_typediff/README.md create mode 100644 crates/semantic_typediff/benches/criterion/fibb.rs create mode 100644 crates/semantic_typediff/benches/iai/fibb.rs create mode 100644 crates/semantic_typediff/fuzz/.gitignore create mode 100644 crates/semantic_typediff/fuzz/Cargo.toml create mode 100644 crates/semantic_typediff/fuzz/fuzz_targets/fuzz_target_1.rs create mode 100644 crates/semantic_typediff/src/lib.rs diff --git a/crates/semantic_typediff/Cargo.toml b/crates/semantic_typediff/Cargo.toml new file mode 100644 index 0000000..345e1f7 --- /dev/null +++ b/crates/semantic_typediff/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "semantic-typediff-rs" +version = "0.0.0" +authors = [ + "Samantha Nguyen, ", + "Alfredo Gutierrez " +] +description = "Provies semantic diffing" +repository = "https://github.com/nlp-rs/typediff.git" +readme = "README.md" +keywords = ["nlp", "lemma", "morphemes", "nouns",] +categories = ["data-structures", "algorithms", "text-processing", "text-editors"] +license = "MIT OR Apache-2.0" +edition = "2021" +rust-version = "1.63.0" + +[dev-dependencies] +criterion = { version = "0.4.0", features = ["html_reports"] } +iai = "0.1.0" + +# criterion benchmarks +[[bench]] +path = "benches/criterion/fibb.rs" +name = "criterion_fibb" +harness = false + +# iai benchmarks +[[bench]] +path = "benches/iai/fibb.rs" +name = "iai_fibb" +harness = false diff --git a/crates/semantic_typediff/README.md b/crates/semantic_typediff/README.md new file mode 100644 index 0000000..a2a35ba --- /dev/null +++ b/crates/semantic_typediff/README.md @@ -0,0 +1,5 @@ +# semantic_typediff +[![License](https://img.shields.io/badge/license-MIT%20%26%20Apache%202.0-green)](#license) +[![CI](https://github.com/nlp-rs/typediff/actions/workflows/main.yml/badge.svg)](https://github.com/nlp-rs/typediff/actions/workflows/main.yml) +[![Security audit](https://github.com/nlp-rs/typediff/actions/workflows/security-audit.yml/badge.svg)](https://github.com/nlp-rs/typediff/actions/workflows/security-audit.yml) +> warning: **typediff is currently experimental** diff --git a/crates/semantic_typediff/benches/criterion/fibb.rs b/crates/semantic_typediff/benches/criterion/fibb.rs new file mode 100644 index 0000000..782dab2 --- /dev/null +++ b/crates/semantic_typediff/benches/criterion/fibb.rs @@ -0,0 +1,17 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; + +#[inline] +fn fibonacci(n: u64) -> u64 { + match n { + 0 => 1, + 1 => 1, + n => fibonacci(n - 1) + fibonacci(n - 2), + } +} + +pub fn criterion_benchmark(c: &mut Criterion) { + c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20)))); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/crates/semantic_typediff/benches/iai/fibb.rs b/crates/semantic_typediff/benches/iai/fibb.rs new file mode 100644 index 0000000..79b1c23 --- /dev/null +++ b/crates/semantic_typediff/benches/iai/fibb.rs @@ -0,0 +1,19 @@ +use iai::{black_box, main}; + +fn fibonacci(n: u64) -> u64 { + match n { + 0 => 1, + 1 => 1, + n => fibonacci(n - 1) + fibonacci(n - 2), + } +} + +fn iai_benchmark_short() -> u64 { + fibonacci(black_box(10)) +} + +fn iai_benchmark_long() -> u64 { + fibonacci(black_box(30)) +} + +main!(iai_benchmark_short, iai_benchmark_long); diff --git a/crates/semantic_typediff/fuzz/.gitignore b/crates/semantic_typediff/fuzz/.gitignore new file mode 100644 index 0000000..a092511 --- /dev/null +++ b/crates/semantic_typediff/fuzz/.gitignore @@ -0,0 +1,3 @@ +target +corpus +artifacts diff --git a/crates/semantic_typediff/fuzz/Cargo.toml b/crates/semantic_typediff/fuzz/Cargo.toml new file mode 100644 index 0000000..87298e7 --- /dev/null +++ b/crates/semantic_typediff/fuzz/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "rust-template-fuzz" +version = "0.0.0" +authors = ["Automatically generated"] +publish = false +edition = "2018" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" + +[dependencies.rust-template] +path = ".." + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[[bin]] +name = "fuzz_target_1" +path = "fuzz_targets/fuzz_target_1.rs" +test = false +doc = false diff --git a/crates/semantic_typediff/fuzz/fuzz_targets/fuzz_target_1.rs b/crates/semantic_typediff/fuzz/fuzz_targets/fuzz_target_1.rs new file mode 100644 index 0000000..c5f7755 --- /dev/null +++ b/crates/semantic_typediff/fuzz/fuzz_targets/fuzz_target_1.rs @@ -0,0 +1,6 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: &[u8]| { + // fuzzed code goes here +}); diff --git a/crates/semantic_typediff/src/lib.rs b/crates/semantic_typediff/src/lib.rs new file mode 100644 index 0000000..7913c79 --- /dev/null +++ b/crates/semantic_typediff/src/lib.rs @@ -0,0 +1 @@ +#![doc = include_str!("../README.md")]