| Crates.io | fast-float-compare |
| lib.rs | fast-float-compare |
| version | 0.1.1 |
| created_at | 2025-01-05 22:16:40.223316+00 |
| updated_at | 2025-01-11 11:42:23.414956+00 |
| description | A lightweight benchmark comparing minimal float comparison implementation against rust_decimal |
| homepage | |
| repository | https://github.com/KhaledYassin/fast-float-compare |
| max_upload_size | |
| id | 1505089 |
| size | 49,845 |
A lightweight experiment comparing different approaches to floating-point number comparison in Rust.
This project aims to explore whether a minimal floating-point representation focused solely on comparison operations can outperform the more comprehensive Decimal from the rust_decimal crate for ordering/comparison use cases.
The hypothesis is that by stripping away all the overhead required for mathematical operations and focusing purely on comparison logic, we might achieve better performance for scenarios where only ordering matters.
The project implements two main approaches:
Decimal - A full-featured decimal floating-point implementationFloat - A minimal custom implementation that:
The project uses Criterion.rs for benchmarking. To run the benchmarks:
cargo bench
This will compare the performance of:
DecimalFloat implementationf64 and Floatf64 and Decimal
// Create a new Float
let a = Float::from_f64(1.23).unwrap();
let b = Float::from_f64(4.56).unwrap();
// Compare the two numbers
assert!(a < b);
// Convert back if needed
let a_f64 = a.to_f64();
let b_f64 = b.to_f64();
src/lib.rs - Core Float implementationsrc/main.rs - Simple demonstration programbenches/float_comparison.rs - Benchmarking codeThis is an experimental project aimed at exploring a specific performance hypothesis. Feel free to:
MIT License
Thanks to the rust_decimal crate for providing a great reference implementation for decimal floating-point numbers in Rust.