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…

What is this?A test, benchmark and fuzzing suite for sort implementations, written in Rust. It also hosts a novel sort called ipnsort, vendored Rust, C++ and C sorts for comparison, and the resulting research papers.
Is this a library I'd pull into my project, or a standalone suite?A standalone research suite of test and benchmark crates you clone and run with cargo, not a library you depend on. Sort implementations in Rust, C++ and C are vendored inside for comparison.
How do I run the tests and benchmarks?Clone the repository and use cargo: it runs the test suite and the benchmark suite, and you can pass a custom regex to filter which benchmarks run.
What do I need to have installed?Rust with cargo for the core suite; cargo fuzz and cargo afl for fuzzing; Python plus the requirements.txt dependencies if you want to generate graphs from collected results.
Anything to watch out for when running it?Most functionality is disabled by default via cargo features — check Cargo.toml to enable what you need — and some options are switched through environment variables, e.g. in benches/bench.rs.
Who is this for — people building sort implementations, or general Rust developers?Mostly sort implementers and performance researchers: it checks correctness properties not commonly upheld and benchmarks across types, patterns and sizes — useful when writing or evaluating a sort itself.
Can it test and benchmark C and C++ sorts, or only Rust ones?Most tests and benchmarks work on non-Rust implementations: the benchmark types are exposed as #[repr(C)] with a defined C API that you implement to wrap your C or C++ sort, like the vendored cpppdqsort.
What is ipnsort?ipnsort (Instruction-Parallel-Network-Sort) is the novel sort implementation developed in this repo: an efficient, generic and robust unstable sort. The same research produced driftsort, a stable counterpart.
What came out of the research?Results are published as papers: the unreasonable effectiveness of modern sort algorithms, a novel branchless partition implementation, a Safety vs Performance case study of C, C++ and Rust sorts, and performance analyses of Intel's x86-simd-sort (AVX-512) and of glidesort/ipnstable.
Can it turn benchmark results into graphs?Yes: runbenchmarks.py collects result sets, and graphall.py builds graphs from them — install the Python dependencies from requirements.txt first.
Creator
Voultapher
Size
76.5 MB
Stars
546
Updated
CommitMar 02
Age
4y
Commits · 90 Days