sort-research-rs README

The project's README from github.com/Voultapher/sort-research-rs. As one markdown file: README.md.

sort-research-rs

This repository contains:

Most tests and benchmarks can be applied to non Rust implementations. This works by implementing the 5 benchmark types as #[repr(C)] and having a defined C API that can be implemented, wrapping the C/C++ sorts.

Most functionality is by default disabled via cargo features, see the Cargo.toml. Some functionality can be enabled or switched by setting environment variables. See for example benches/bench.rs.

Research results

Running the tests

cargo test

cargo miri test

# Might require disabling criterion dependency.
RUSTFLAGS=-Zsanitizer=address cargo t --release

Running the benchmarks

cargo bench

cargo bench <sort_name>-<prediction_state>-<type>-<pattern>-<size>

# Example
cargo bench rust_std_stable-hot-u64-random-10000
cargo bench hot-u64-random-10000
cargo bench random

You can also set a custom regex to filter the benchmarks you want to run:

BENCH_REGEX="std.*i32-random-8$" cargo bench

If you want to collect a set of results that can then later be used to create graphs, you can use the run_benchmarks.py utility script:

# Will write results to my_test_zen3.json
BENCH_REGEX="_stable.*random-" python util/run_benchmarks.py my_test_zen3

To run the graph_all.py script to create graphs from this data you need to first install the dependencies as specified in requirements.txt e.g. on Linux:

python -m venv venv
source ./venv/bin/active
pip install --requirement util/graph_bench_result/requirements.txt

Afterwards, you can use the graph_all.py script:

python util/graph_bench_result/graph_all.py my_test_zen3.json

Fuzzing

You'll need to install cargo fuzz and cargo afl respectively. See https://rust-fuzz.github.io/book/introduction.html.

Fuzzing with libfuzzer

cd fuzz
cargo fuzz run libfuzzer_main

Fuzzing with afl

cd fuzz-afl
RUSTFLAGS=-Zsanitizer=address cargo afl build --release && cargo afl fuzz -i in -o out -D target/release/afl

Adjust fuzz/fuzz_targets/libfuzzer_main.rs and fuzz/fuzz_targets/libfuzzer_main.rs respectively to change the fuzz target. Default rust_ipn_stable.

Contributing

Please respect the CODE_OF_CONDUCT.md when contributing.

Adding a new sort implementation

Please open an issue before investing the effort of adding a new sort implementation. The maintainer of this project is currently not interested in building an up-to-date database of all existing sort implementations. Implementations are added based on situational context and relevance to the maintainers' goals. Baseline for all new sort implementations is they must pass all functionality tests, they may pass the safety tests but don't have to.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the Apache License, Version 2.0 - see the LICENSE.md file for details.

sort-research-rs (Voultapher/sort-research-rs)

Searching Database…

这是做什么的?一个用 Rust 编写的排序实现测试、基准测试和模糊测试套件。它还包含一个名为 ipnsort 的新排序算法,内嵌了用于对比的 Rust、C++ 和 C 排序实现,以及由此产出的研究论文。
这是一个我要引入自己项目的库,还是一个独立的套件?一个独立的研究套件,由测试和基准测试 crate 组成,需要克隆下来用 cargo 运行,不是作为依赖引入的库。Rust、C++ 和 C 的排序实现都内嵌在其中,用于对比。
我怎么运行测试和基准测试?克隆仓库后使用 cargo:它会运行测试套件和基准测试套件,你还可以传入自定义正则表达式来筛选要运行哪些基准测试。
我需要安装哪些东西?核心套件需要带 cargo 的 Rust;模糊测试需要 cargo fuzz 和 cargo afl;如果想根据收集到的结果生成图表,还需要 Python 以及 requirements.txt 里的依赖。
运行时有什么需要注意的?大部分功能默认通过 cargo 特性关闭——查看 Cargo.toml,启用你需要的部分——另外一些选项要通过环境变量来切换,例如在 benches/bench.rs 中。
这是给谁用的——是写排序实现的人,还是一般的 Rust 开发者?主要是排序实现者和性能研究者:它会检查一些平时很少被遵守的正确性属性,并针对不同类型、数据模式和规模做基准测试——在自己编写或评估排序算法时很有用。
它能测试和基准测试 C 和 C++ 的排序吗,还是只支持 Rust 的?大部分测试和基准测试针对的是非 Rust 实现:基准测试的类型以 #[repr(C)] 的形式暴露,并定义了一套 C API,你实现这个 API 来包装你的 C 或 C++ 排序,就像内嵌的 cpppdqsort 那样。
ipnsort 是什么?ipnsort(Instruction-Parallel-Network-Sort)是这个仓库中开发的新型排序实现:一个高效、通用且健壮的非稳定排序。同一项研究还产出了它的稳定版本 driftsort。
这项研究产出了什么?成果以论文形式发表:关于现代排序算法出奇高效的研究、一种新的无分支分区实现、一份 C、C++ 和 Rust 排序的安全性对比性能案例研究,以及对 Intel x86-simd-sort(AVX-512)和 glidesort/ipnstable 的性能分析。
它能把基准测试结果画成图表吗?可以:runbenchmarks.py 负责收集结果集,graphall.py 根据这些结果生成图表——先安装 requirements.txt 里的 Python 依赖。
Creator
Voultapher
Size
76.5 MB
Stars
546
Updated
CommitMar 02
Age
4y
Commits · 90 Days