From 2847dc132817c729a5af559a4b3293f5df7f1a30 Mon Sep 17 00:00:00 2001 From: logan Date: Wed, 31 Jul 2024 18:25:10 -0500 Subject: [PATCH] Updated README.md --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..1a42e0c --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# nrange +The Rust standard library has a Range type, which represents a bounds for +a scalar value (i.e. 1 ≤ n ≤ 100). A range can be open ended, iterated over, +and tested for overlap with other ranges. I designed nrange as an extension +of the Range type to vector space. This makes code less nested. Below is an +example comparing an operation on a 3D array using standard Ranges and nrange. +```rust +let array3 = [[[0; 128]; 128]; 128]; +// Using standard Ranges +for x in 0..128 { + for y in 0..128 { + for z in 0..128 { + let element = &array3[x][y][z]; + // Do something with element + } + } +} +// Using nrange +for [x, y, z] in nrange!(0..128, 0..128, 0..128) { + let element = &array3[x][y][z]; + // Do something with element +} +``` +## Performance +My implementation is competitive with similar libraries in the Rust +ecosystem. While nrange only works for ranges of contiguous +integers, itertools and cartesian-rs work for any iterators. +However, by restricting my use case I can extract more performance +gains and integrate better with the Rust standard library. Below +are benchmark results comparing my solution to comparable libraries: +* **itertools** ..... 1,821,573 ns +* **cartesian-rs**... 989,232 ns +* **nrange** ........ 968,853 ns