| 1 | use criterionrust-analyzer cargo criterion 0.3.6 crate/::*; |
| 2 | use randrust-analyzer cargo rand 0.7.3 crate/::preluderust-analyzer cargo rand 0.7.3 prelude/::*; |
| 3 | use triple_accelrust-analyzer cargo triple_accel 0.4.0 crate/::*; |
| 4 | use triple_accelrust-analyzer cargo triple_accel 0.4.0 crate/::levenshteinrust-analyzer cargo triple_accel 0.4.0 levenshtein/::*; |
| 5 | use triple_accelrust-analyzer cargo triple_accel 0.4.0 crate/::hammingrust-analyzer cargo triple_accel 0.4.0 hamming/::*; |
| 6 | |
| 7 | fn bench_rand_hammingrust-analyzer cargo triple_accel 0.4.0 bench_rand_hamming().(c: &mut Criterionrust-analyzer cargo criterion 0.3.6 Criterion#) { |
| 8 | let mut rng = StdRngrust-analyzer cargo rand 0.7.3 rngs/std/StdRng#::seed_from_u64rust-analyzer cargo rand_core 0.5.1 SeedableRng#seed_from_u64().(1234); |
| 9 | let mut group = c.benchmark_grouprust-analyzer cargo criterion 0.3.6 impl#[`Criterion<M>`]benchmark_group().("bench_rand_hamming"); |
| 10 | let config = PlotConfigurationrust-analyzer cargo criterion 0.3.6 PlotConfiguration#::defaultrust-analyzer cargo criterion 0.3.6 impl#[PlotConfiguration][Default]default().().summary_scalerust-analyzer cargo criterion 0.3.6 impl#[PlotConfiguration]summary_scale().(AxisScalerust-analyzer cargo criterion 0.3.6 AxisScale#::Logarithmicrust-analyzer cargo criterion 0.3.6 AxisScale#Logarithmic#); |
| 11 | group.plot_configrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]plot_config().(config); |
| 12 | |
| 13 | for str_len in [10, 100, 1000].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 14 | let k = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len) as u32) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().10); |
| 15 | let (a_str, b_str) = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(rand_hamming_pairrust-analyzer cargo triple_accel 0.4.0 rand_hamming_pair().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len, k, &mut rng)); |
| 16 | |
| 17 | let res = hamming_naiverust-analyzer cargo triple_accel 0.4.0 hamming/hamming_naive().(&a_str, &b_str); |
| 18 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res == hamming_words_64rust-analyzer cargo triple_accel 0.4.0 hamming/hamming_words_64().(&a_str, &b_str)); |
| 19 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res == hamming_words_128rust-analyzer cargo triple_accel 0.4.0 hamming/hamming_words_128().(&a_str, &b_str)); |
| 20 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res == hamming_simd_movemaskrust-analyzer cargo triple_accel 0.4.0 hamming/hamming_simd_movemask().(&a_str, &b_str)); |
| 21 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res == hamming_simd_parallelrust-analyzer cargo triple_accel 0.4.0 hamming/hamming_simd_parallel().(&a_str, &b_str)); |
| 22 | |
| 23 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("hamming_naive", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| hamming_naiverust-analyzer cargo triple_accel 0.4.0 hamming/hamming_naive().(&a_str, &b_str))); |
| 24 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("hamming_words_64", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| hamming_words_64rust-analyzer cargo triple_accel 0.4.0 hamming/hamming_words_64().(&a_str, &b_str))); |
| 25 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("hamming_words_128", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| hamming_words_128rust-analyzer cargo triple_accel 0.4.0 hamming/hamming_words_128().(&a_str, &b_str))); |
| 26 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("hamming_simd_movemask", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| hamming_simd_movemaskrust-analyzer cargo triple_accel 0.4.0 hamming/hamming_simd_movemask().(&a_str, &b_str))); |
| 27 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("hamming_simd_parallel", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| hamming_simd_parallelrust-analyzer cargo triple_accel 0.4.0 hamming/hamming_simd_parallel().(&a_str, &b_str))); |
| 28 | } |
| 29 | |
| 30 | group.finishrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]finish().(); |
| 31 | } |
| 32 | |
| 33 | fn bench_rand_hamming_searchrust-analyzer cargo triple_accel 0.4.0 bench_rand_hamming_search().(c: &mut Criterionrust-analyzer cargo criterion 0.3.6 Criterion#) { |
| 34 | let mut rng = StdRngrust-analyzer cargo rand 0.7.3 rngs/std/StdRng#::seed_from_u64rust-analyzer cargo rand_core 0.5.1 SeedableRng#seed_from_u64().(1234); |
| 35 | let mut group = c.benchmark_grouprust-analyzer cargo criterion 0.3.6 impl#[`Criterion<M>`]benchmark_group().("bench_rand_hamming_search"); |
| 36 | let config = PlotConfigurationrust-analyzer cargo criterion 0.3.6 PlotConfiguration#::defaultrust-analyzer cargo criterion 0.3.6 impl#[PlotConfiguration][Default]default().().summary_scalerust-analyzer cargo criterion 0.3.6 impl#[PlotConfiguration]summary_scale().(AxisScalerust-analyzer cargo criterion 0.3.6 AxisScale#::Logarithmicrust-analyzer cargo criterion 0.3.6 AxisScale#Logarithmic#); |
| 37 | group.plot_configrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]plot_config().(config); |
| 38 | |
| 39 | for str_len in [100, 1000].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 40 | let needle_len = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().10); |
| 41 | let num_needles = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().20); |
| 42 | let k = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len) as u32) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().100); |
| 43 | let (needle, haystack) = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(rand_hamming_needle_haystackrust-analyzer cargo triple_accel 0.4.0 rand_hamming_needle_haystack().(needle_len, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len, num_needles, k, &mut rng)); |
| 44 | |
| 45 | let res: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Matchrust-analyzer cargo triple_accel 0.4.0 Match#> = hamming_search_naive_with_optsrust-analyzer cargo triple_accel 0.4.0 hamming/hamming_search_naive_with_opts().(&needle, &haystack, k, SearchTyperust-analyzer cargo triple_accel 0.4.0 SearchType#::Allrust-analyzer cargo triple_accel 0.4.0 SearchType#All#).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 46 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res == hamming_search_simd_with_optsrust-analyzer cargo triple_accel 0.4.0 hamming/hamming_search_simd_with_opts().(&needle, &haystack, k, SearchTyperust-analyzer cargo triple_accel 0.4.0 SearchType#::Allrust-analyzer cargo triple_accel 0.4.0 SearchType#All#).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Matchrust-analyzer cargo triple_accel 0.4.0 Match#>>()); |
| 47 | |
| 48 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("hamming_search_naive_k", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| hamming_search_naive_with_optsrust-analyzer cargo triple_accel 0.4.0 hamming/hamming_search_naive_with_opts().(&needle, &haystack, k, SearchTyperust-analyzer cargo triple_accel 0.4.0 SearchType#::Allrust-analyzer cargo triple_accel 0.4.0 SearchType#All#).lastrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/iter/impl#[`Box<I, A>`][Iterator]last().())); |
| 49 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("hamming_search_simd_k", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| hamming_search_simd_with_optsrust-analyzer cargo triple_accel 0.4.0 hamming/hamming_search_simd_with_opts().(&needle, &haystack, k, SearchTyperust-analyzer cargo triple_accel 0.4.0 SearchType#::Allrust-analyzer cargo triple_accel 0.4.0 SearchType#All#).lastrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/iter/impl#[`Box<I, A>`][Iterator]last().())); |
| 50 | } |
| 51 | |
| 52 | group.finishrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]finish().(); |
| 53 | } |
| 54 | |
| 55 | fn bench_rand_levenshteinrust-analyzer cargo triple_accel 0.4.0 bench_rand_levenshtein().(c: &mut Criterionrust-analyzer cargo criterion 0.3.6 Criterion#) { |
| 56 | let mut rng = StdRngrust-analyzer cargo rand 0.7.3 rngs/std/StdRng#::seed_from_u64rust-analyzer cargo rand_core 0.5.1 SeedableRng#seed_from_u64().(1234); |
| 57 | let mut group = c.benchmark_grouprust-analyzer cargo criterion 0.3.6 impl#[`Criterion<M>`]benchmark_group().("bench_rand_levenshtein"); |
| 58 | let config = PlotConfigurationrust-analyzer cargo criterion 0.3.6 PlotConfiguration#::defaultrust-analyzer cargo criterion 0.3.6 impl#[PlotConfiguration][Default]default().().summary_scalerust-analyzer cargo criterion 0.3.6 impl#[PlotConfiguration]summary_scale().(AxisScalerust-analyzer cargo criterion 0.3.6 AxisScale#::Logarithmicrust-analyzer cargo criterion 0.3.6 AxisScale#Logarithmic#); |
| 59 | group.plot_configrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]plot_config().(config); |
| 60 | |
| 61 | for str_len in [10, 100, 1000].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 62 | let k = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len) as u32) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().10); |
| 63 | let (a_str, b_str) = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(rand_levenshtein_pairrust-analyzer cargo triple_accel 0.4.0 rand_levenshtein_pair().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len, k, &mut rng)); |
| 64 | |
| 65 | let res = levenshtein_naiverust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_naive().(&a_str, &b_str); |
| 66 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res == levenshtein_exprust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_exp().(&a_str, &b_str)); |
| 67 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res == levenshteinrust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein().(&a_str, &b_str)); |
| 68 | |
| 69 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("levenshtein_naive", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| levenshtein_naiverust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_naive().(&a_str, &b_str))); |
| 70 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("levenshtein_exp", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| levenshtein_exprust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_exp().(&a_str, &b_str))); |
| 71 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("levenshtein", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| levenshteinrust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein().(&a_str, &b_str))); |
| 72 | } |
| 73 | |
| 74 | group.finishrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]finish().(); |
| 75 | } |
| 76 | |
| 77 | fn bench_rand_levenshtein_krust-analyzer cargo triple_accel 0.4.0 bench_rand_levenshtein_k().(c: &mut Criterionrust-analyzer cargo criterion 0.3.6 Criterion#) { |
| 78 | let mut rng = StdRngrust-analyzer cargo rand 0.7.3 rngs/std/StdRng#::seed_from_u64rust-analyzer cargo rand_core 0.5.1 SeedableRng#seed_from_u64().(1234); |
| 79 | let mut group = c.benchmark_grouprust-analyzer cargo criterion 0.3.6 impl#[`Criterion<M>`]benchmark_group().("bench_rand_levenshtein_k"); |
| 80 | let config = PlotConfigurationrust-analyzer cargo criterion 0.3.6 PlotConfiguration#::defaultrust-analyzer cargo criterion 0.3.6 impl#[PlotConfiguration][Default]default().().summary_scalerust-analyzer cargo criterion 0.3.6 impl#[PlotConfiguration]summary_scale().(AxisScalerust-analyzer cargo criterion 0.3.6 AxisScale#::Logarithmicrust-analyzer cargo criterion 0.3.6 AxisScale#Logarithmic#); |
| 81 | group.plot_configrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]plot_config().(config); |
| 82 | |
| 83 | for str_len in [10, 100, 1000].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 84 | let k = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len) as u32) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().10); |
| 85 | let trace_on = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(false); |
| 86 | let (a_str, b_str) = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(rand_levenshtein_pairrust-analyzer cargo triple_accel 0.4.0 rand_levenshtein_pair().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len, k, &mut rng)); |
| 87 | |
| 88 | let res = levenshtein_naive_with_optsrust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_naive_with_opts().(&a_str, &b_str, trace_on, LEVENSHTEIN_COSTSrust-analyzer cargo triple_accel 0.4.0 levenshtein/LEVENSHTEIN_COSTS.); |
| 89 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res == levenshtein_naive_k_with_optsrust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_naive_k_with_opts().(&a_str, &b_str, k, trace_on, LEVENSHTEIN_COSTSrust-analyzer cargo triple_accel 0.4.0 levenshtein/LEVENSHTEIN_COSTS.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 90 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res == levenshtein_simd_k_with_optsrust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_simd_k_with_opts().(&a_str, &b_str, k, trace_on, LEVENSHTEIN_COSTSrust-analyzer cargo triple_accel 0.4.0 levenshtein/LEVENSHTEIN_COSTS.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 91 | |
| 92 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("levenshtein_naive", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| levenshtein_naive_with_optsrust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_naive_with_opts().(&a_str, &b_str, trace_on, LEVENSHTEIN_COSTSrust-analyzer cargo triple_accel 0.4.0 levenshtein/LEVENSHTEIN_COSTS.))); |
| 93 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("levenshtein_naive_k", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| levenshtein_naive_k_with_optsrust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_naive_k_with_opts().(&a_str, &b_str, k, trace_on, LEVENSHTEIN_COSTSrust-analyzer cargo triple_accel 0.4.0 levenshtein/LEVENSHTEIN_COSTS.))); |
| 94 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("levenshtein_simd_k", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| levenshtein_simd_k_with_optsrust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_simd_k_with_opts().(&a_str, &b_str, k, trace_on, LEVENSHTEIN_COSTSrust-analyzer cargo triple_accel 0.4.0 levenshtein/LEVENSHTEIN_COSTS.))); |
| 95 | } |
| 96 | |
| 97 | group.finishrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]finish().(); |
| 98 | } |
| 99 | |
| 100 | fn bench_rand_levenshtein_searchrust-analyzer cargo triple_accel 0.4.0 bench_rand_levenshtein_search().(c: &mut Criterionrust-analyzer cargo criterion 0.3.6 Criterion#) { |
| 101 | let mut rng = StdRngrust-analyzer cargo rand 0.7.3 rngs/std/StdRng#::seed_from_u64rust-analyzer cargo rand_core 0.5.1 SeedableRng#seed_from_u64().(1234); |
| 102 | let mut group = c.benchmark_grouprust-analyzer cargo criterion 0.3.6 impl#[`Criterion<M>`]benchmark_group().("bench_rand_levenshtein_search"); |
| 103 | let config = PlotConfigurationrust-analyzer cargo criterion 0.3.6 PlotConfiguration#::defaultrust-analyzer cargo criterion 0.3.6 impl#[PlotConfiguration][Default]default().().summary_scalerust-analyzer cargo criterion 0.3.6 impl#[PlotConfiguration]summary_scale().(AxisScalerust-analyzer cargo criterion 0.3.6 AxisScale#::Logarithmicrust-analyzer cargo criterion 0.3.6 AxisScale#Logarithmic#); |
| 104 | group.plot_configrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]plot_config().(config); |
| 105 | |
| 106 | for str_len in [100, 1000].iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 107 | let needle_len = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().10); |
| 108 | let num_needles = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().20); |
| 109 | let k = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(((*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len) as u32) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().100); |
| 110 | let anchored = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(false); |
| 111 | let (needle, haystack) = black_boxrust-analyzer cargo criterion 0.3.6 black_box().(rand_levenshtein_needle_haystackrust-analyzer cargo triple_accel 0.4.0 rand_levenshtein_needle_haystack().(needle_len, *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len, num_needles, k, &mut rng)); |
| 112 | |
| 113 | let res: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Matchrust-analyzer cargo triple_accel 0.4.0 Match#> = levenshtein_search_naive_with_optsrust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_search_naive_with_opts().(&needle, &haystack, k, SearchTyperust-analyzer cargo triple_accel 0.4.0 SearchType#::Allrust-analyzer cargo triple_accel 0.4.0 SearchType#All#, LEVENSHTEIN_COSTSrust-analyzer cargo triple_accel 0.4.0 levenshtein/LEVENSHTEIN_COSTS., anchored).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 114 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(res == levenshtein_search_simd_with_optsrust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_search_simd_with_opts().(&needle, &haystack, k, SearchTyperust-analyzer cargo triple_accel 0.4.0 SearchType#::Allrust-analyzer cargo triple_accel 0.4.0 SearchType#All#, LEVENSHTEIN_COSTSrust-analyzer cargo triple_accel 0.4.0 levenshtein/LEVENSHTEIN_COSTS., anchored).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Matchrust-analyzer cargo triple_accel 0.4.0 Match#>>()); |
| 115 | |
| 116 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("levenshtein_search_naive_k", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| levenshtein_search_naive_with_optsrust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_search_naive_with_opts().(&needle, &haystack, k, SearchTyperust-analyzer cargo triple_accel 0.4.0 SearchType#::Allrust-analyzer cargo triple_accel 0.4.0 SearchType#All#, LEVENSHTEIN_COSTSrust-analyzer cargo triple_accel 0.4.0 levenshtein/LEVENSHTEIN_COSTS., anchored).lastrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/iter/impl#[`Box<I, A>`][Iterator]last().())); |
| 117 | group.bench_functionrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]bench_function().(BenchmarkIdrust-analyzer cargo criterion 0.3.6 benchmark_group/BenchmarkId#::newrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[BenchmarkId]new().("levenshtein_search_simd_k", *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().str_len), |b| b.iterrust-analyzer cargo criterion 0.3.6 bencher/impl#[`Bencher<'a, M>`]iter().(|| levenshtein_search_simd_with_optsrust-analyzer cargo triple_accel 0.4.0 levenshtein/levenshtein_search_simd_with_opts().(&needle, &haystack, k, SearchTyperust-analyzer cargo triple_accel 0.4.0 SearchType#::Allrust-analyzer cargo triple_accel 0.4.0 SearchType#All#, LEVENSHTEIN_COSTSrust-analyzer cargo triple_accel 0.4.0 levenshtein/LEVENSHTEIN_COSTS., anchored).lastrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/iter/impl#[`Box<I, A>`][Iterator]last().())); |
| 118 | } |
| 119 | |
| 120 | group.finishrust-analyzer cargo criterion 0.3.6 benchmark_group/impl#[`BenchmarkGroup<'a, M>`]finish().(); |
| 121 | } |
| 122 | |
| 123 | criterion_grouprust-analyzer cargo criterion 0.3.6 macros/criterion_group!!(bench_randrust-analyzer cargo triple_accel 0.4.0 bench_rand()., bench_rand_hammingrust-analyzer cargo triple_accel 0.4.0 bench_rand_hamming()., bench_rand_hamming_searchrust-analyzer cargo triple_accel 0.4.0 bench_rand_hamming_search()., bench_rand_levenshteinrust-analyzer cargo triple_accel 0.4.0 bench_rand_levenshtein()., bench_rand_levenshtein_krust-analyzer cargo triple_accel 0.4.0 bench_rand_levenshtein_k()., bench_rand_levenshtein_searchrust-analyzer cargo triple_accel 0.4.0 bench_rand_levenshtein_search().); |
| 124 | criterion_mainrust-analyzer cargo criterion 0.3.6 macros/criterion_main!!(bench_randrust-analyzer cargo triple_accel 0.4.0 bench_rand().); |
| 125 | |
| 126 | fn rand_hamming_needle_haystackrust-analyzer cargo triple_accel 0.4.0 rand_hamming_needle_haystack().<R: Rngrust-analyzer cargo rand 0.7.3 Rng#>(needle_len: usize, haystack_len: usize, num_match: usize, k: u32, rng: &mut R) -> (Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) { |
| 127 | let mut idx: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize> = (0usize..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#haystack_len).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 128 | idx.shufflerust-analyzer cargo rand 0.7.3 seq/impl#[`[T]`][SliceRandom]shuffle().(rng); |
| 129 | let mut insert = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![false; haystack_len]; |
| 130 | |
| 131 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#num_match { |
| 132 | insert[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().idx[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = true; |
| 133 | } |
| 134 | |
| 135 | let bytes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = (33u8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#127u8).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 136 | let needle = rand_alloc_strrust-analyzer cargo triple_accel 0.4.0 rand_alloc_str().(needle_len, rng); |
| 137 | let mut haystack: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 138 | |
| 139 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#haystack_len { |
| 140 | if insert[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). { |
| 141 | let s = rand_hamming_mutaterust-analyzer cargo triple_accel 0.4.0 rand_hamming_mutate().(&needle, k, rng); |
| 142 | haystack.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(&s[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#needle_len]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().); |
| 143 | }else{ |
| 144 | haystack.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().bytes.chooserust-analyzer cargo rand 0.7.3 seq/impl#[`[T]`][SliceRandom]choose().(rng).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | let mut haystack_final = alloc_strrust-analyzer cargo triple_accel 0.4.0 alloc_str().(haystack.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 149 | fill_strrust-analyzer cargo triple_accel 0.4.0 fill_str().(&mut haystack_final, &haystack); |
| 150 | |
| 151 | (needle, haystack_final) |
| 152 | } |
| 153 | |
| 154 | fn rand_hamming_pairrust-analyzer cargo triple_accel 0.4.0 rand_hamming_pair().<R: Rngrust-analyzer cargo rand 0.7.3 Rng#>(length: usize, k: u32, rng: &mut R) -> (Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) { |
| 155 | let a = rand_alloc_strrust-analyzer cargo triple_accel 0.4.0 rand_alloc_str().(length, rng); |
| 156 | let b = rand_hamming_mutaterust-analyzer cargo triple_accel 0.4.0 rand_hamming_mutate().(&a, k, rng); |
| 157 | |
| 158 | (a, b) |
| 159 | } |
| 160 | |
| 161 | fn rand_hamming_mutaterust-analyzer cargo triple_accel 0.4.0 rand_hamming_mutate().<R: Rngrust-analyzer cargo rand 0.7.3 Rng#>(a: &[u8], k: u32, rng: &mut R) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 162 | let mut b = alloc_strrust-analyzer cargo triple_accel 0.4.0 alloc_str().(a.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 163 | fill_strrust-analyzer cargo triple_accel 0.4.0 fill_str().(&mut b, a); |
| 164 | let curr_k: usize = rng.gen_rangerust-analyzer cargo rand 0.7.3 Rng#gen_range().((k rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().2) as usize, k as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1); |
| 165 | let mut idx: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize> = (0usize..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#a.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 166 | idx.shufflerust-analyzer cargo rand 0.7.3 seq/impl#[`[T]`][SliceRandom]shuffle().(rng); |
| 167 | |
| 168 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#curr_k { |
| 169 | b[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().idx[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = 32u8; |
| 170 | } |
| 171 | |
| 172 | b |
| 173 | } |
| 174 | |
| 175 | fn rand_levenshtein_needle_haystackrust-analyzer cargo triple_accel 0.4.0 rand_levenshtein_needle_haystack().<R: Rngrust-analyzer cargo rand 0.7.3 Rng#>(needle_len: usize, haystack_len: usize, num_match: usize, k: u32, rng: &mut R) -> (Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) { |
| 176 | let mut idx: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize> = (0usize..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#haystack_len).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 177 | idx.shufflerust-analyzer cargo rand 0.7.3 seq/impl#[`[T]`][SliceRandom]shuffle().(rng); |
| 178 | let mut insert = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![false; haystack_len]; |
| 179 | |
| 180 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#num_match { |
| 181 | insert[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().idx[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = true; |
| 182 | } |
| 183 | |
| 184 | let bytes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = (33u8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#127u8).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 185 | let needle = rand_strrust-analyzer cargo triple_accel 0.4.0 rand_str().(needle_len, rng); |
| 186 | let mut haystack: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 187 | |
| 188 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#haystack_len { |
| 189 | if insert[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). { |
| 190 | let s = rand_levenshtein_mutaterust-analyzer cargo triple_accel 0.4.0 rand_levenshtein_mutate().(&needle, k, rng); |
| 191 | haystack.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(&s); |
| 192 | }else{ |
| 193 | haystack.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().bytes.chooserust-analyzer cargo rand 0.7.3 seq/impl#[`[T]`][SliceRandom]choose().(rng).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | (needle, haystack) |
| 198 | } |
| 199 | |
| 200 | fn rand_levenshtein_pairrust-analyzer cargo triple_accel 0.4.0 rand_levenshtein_pair().<R: Rngrust-analyzer cargo rand 0.7.3 Rng#>(length: usize, k: u32, rng: &mut R) -> (Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) { |
| 201 | let a = rand_strrust-analyzer cargo triple_accel 0.4.0 rand_str().(length, rng); |
| 202 | let b = rand_levenshtein_mutaterust-analyzer cargo triple_accel 0.4.0 rand_levenshtein_mutate().(&a, k, rng); |
| 203 | |
| 204 | (a, b) |
| 205 | } |
| 206 | |
| 207 | fn rand_levenshtein_mutaterust-analyzer cargo triple_accel 0.4.0 rand_levenshtein_mutate().<R: Rngrust-analyzer cargo rand 0.7.3 Rng#>(a: &[u8], k: u32, rng: &mut R) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 208 | let mut edits = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0u8; a.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()]; |
| 209 | let curr_k: usize = rng.gen_rangerust-analyzer cargo rand 0.7.3 Rng#gen_range().((k rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().2) as usize, k as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1); |
| 210 | let mut idx: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize> = (0usize..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#a.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 211 | idx.shufflerust-analyzer cargo rand 0.7.3 seq/impl#[`[T]`][SliceRandom]shuffle().(rng); |
| 212 | |
| 213 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#curr_k { |
| 214 | edits[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().idx[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = rng.gen_rangerust-analyzer cargo rand 0.7.3 Rng#gen_range().(1u8, 4u8); |
| 215 | } |
| 216 | |
| 217 | let bytes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = (33u8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#127u8).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 218 | let mut b = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 219 | |
| 220 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#a.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 221 | match edits[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). { |
| 222 | 0u8 => { // same |
| 223 | b.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(a[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 224 | }, |
| 225 | 1u8 => { // diff |
| 226 | b.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(32u8); |
| 227 | }, |
| 228 | 2u8 => { // insert |
| 229 | b.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().bytes.chooserust-analyzer cargo rand 0.7.3 seq/impl#[`[T]`][SliceRandom]choose().(rng).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()); |
| 230 | b.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(a[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 231 | }, |
| 232 | 3u8 => (), // delete |
| 233 | _ => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("This should not have been reached!") |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | b |
| 238 | } |
| 239 | |
| 240 | fn rand_strrust-analyzer cargo triple_accel 0.4.0 rand_str().<R: Rngrust-analyzer cargo rand 0.7.3 Rng#>(length: usize, rng: &mut R) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 241 | let bytes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = (33u8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#127u8).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 242 | let mut res = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0u8; length]; |
| 243 | |
| 244 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#length { |
| 245 | res[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().bytes.chooserust-analyzer cargo rand 0.7.3 seq/impl#[`[T]`][SliceRandom]choose().(rng).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 246 | } |
| 247 | |
| 248 | res |
| 249 | } |
| 250 | |
| 251 | fn rand_alloc_strrust-analyzer cargo triple_accel 0.4.0 rand_alloc_str().<R: Rngrust-analyzer cargo rand 0.7.3 Rng#>(length: usize, rng: &mut R) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 252 | let bytes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = (33u8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#127u8).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 253 | let mut res = alloc_strrust-analyzer cargo triple_accel 0.4.0 alloc_str().(length); |
| 254 | |
| 255 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#length { |
| 256 | res[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().bytes.chooserust-analyzer cargo rand 0.7.3 seq/impl#[`[T]`][SliceRandom]choose().(rng).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 257 | } |
| 258 | |
| 259 | res |
| 260 | } |
| 261 |