Skip to content

Commit

Permalink
Make library work on stable release channel
Browse files Browse the repository at this point in the history
No functional changes.

As bench is still not stable, use bencher crate. Split testing and
benchmarks out to their own modules.

Remove template and default elements from cargo file. Update to 2018
edition of Rust.

Bump version to 0.3.0.

Add a little documentation and fix clippy lints.
  • Loading branch information
bz2 committed Sep 20, 2020
1 parent d5ab6d5 commit 43632ab
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 271 deletions.
45 changes: 10 additions & 35 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
[package]
name = "morton"
version = "0.2.0"
version = "0.3.0"
authors = ["Reinier Maas <reiniermaas@hotmail.com>"]
edition = "2018"

# METADATA
description = "morton iterator for rust"
documentation = "https://github.com/ReinierMaas/morton/"
description = "Morton space filling curve functions"
documentation = "https://docs.rs/morton/"
homepage = "https://github.com/ReinierMaas/morton/"
repository = "https://github.com/ReinierMaas/morton/"
readme = "README.md"
keywords = ["morton", "iterator", "cache-coherence", "spatial-locality", "data-locality"]
categories = ["algorithms", "caching", "data-structures", "game-engines", "memory-management"]
license = "MIT"

# Optional specification of badges to be displayed on crates.io. The badges
# currently available are Travis CI and Appveyor latest build status, specified
# using the following parameters:
# [badges]
# Travis CI: `repository` is required. `branch` is optional; default is `master`
# travis-ci = { repository = "...", branch = "master" }
# Appveyor: `repository` is required. `branch` is optional; default is `master`
# `service` is optional; valid values are `github` (default), `bitbucket`, and
# `gitlab`.
# appveyor = { repository = "...", branch = "master", service = "github" }
[[bench]]
harness = false
name = "morton"

# PROFILES
# The development profile, used for `cargo build | run`.
[profile.dev]
opt-level = 0
debug = true
debug-assertions = true
[dev-dependencies]
bencher = "0.1"
rand = "0.7"

# The release profile, used for `cargo build | run --release`.
[profile.release]
opt-level = 3
lto = true

# The testing profile, used for `cargo test`.
[profile.test]
opt-level = 0
debug = true
debug-assertions = true

# The benchmarking profile, used for `cargo bench`.
[profile.bench]
opt-level = 3
lto = true

[dependencies]

[dev-dependencies]
rand = "0.3.15"
168 changes: 168 additions & 0 deletions benches/morton.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#[macro_use]
extern crate bencher;

use bencher::{black_box, Bencher};
use rand::{thread_rng, Rng};

use morton::utils::{idx_tile, idx_tile_tuple};
use morton::{deinterleave_morton, interleave_morton};

fn interleave_1000(b: &mut Bencher) {
let x = thread_rng().gen::<u16>();
let y = thread_rng().gen::<u16>();
b.iter(|| {
for _ in 0..1000 {
black_box(interleave_morton(x, y));
}
});
}

fn deinterleave_1000(b: &mut Bencher) {
let morton = thread_rng().gen::<u32>();
b.iter(|| {
for _ in 0..1000 {
black_box(deinterleave_morton(morton));
}
});
}

fn interleave_deinterleave_1000(b: &mut Bencher) {
let x = thread_rng().gen::<u16>();
let y = thread_rng().gen::<u16>();
b.iter(|| {
for _ in 0..1000 {
black_box(deinterleave_morton(interleave_morton(x, y)));
}
});
}

fn deinterleave_interleave_1000(b: &mut Bencher) {
let morton = thread_rng().gen::<u32>();
b.iter(|| {
for _ in 0..1000 {
let (x, y) = deinterleave_morton(morton);
black_box(interleave_morton(x, y));
}
});
}

fn horizontal_access_normal(b: &mut Bencher) {
let mut tile_normal = vec![0; 2048 * 2048]; // 16MB allocate more then largest cache
// fill tiles with some random numbers
for y in 0..2048 {
for x in 0..2048 {
let random = thread_rng().gen::<u32>();
tile_normal[idx_tile(x, y, 2048)] = random;
}
}
// bench horizontal access (x direction)
b.iter(|| {
for y in 0..2048 {
for x in 0..2048 {
black_box(tile_normal[idx_tile(x, y, 2048)]);
}
}
});
}

fn vertical_access_normal(b: &mut Bencher) {
let mut tile_normal = vec![0; 2048 * 2048]; // 16MB allocate more then largest cache
// fill tiles with some random numbers
for x in 0..2048 {
for y in 0..2048 {
let random = thread_rng().gen::<u32>();
tile_normal[idx_tile(x, y, 2048)] = random;
}
}
// bench vertical access (y direction)
b.iter(|| {
for x in 0..2048 {
for y in 0..2048 {
black_box(tile_normal[idx_tile(x, y, 2048) as usize]);
}
}
});
}

fn morton_access_normal(b: &mut Bencher) {
let mut tile_morton = vec![0; 2048 * 2048]; // 16MB allocate more then largest cache
// fill tiles with some random numbers
for z in 0..2048 * 2048 {
let random = thread_rng().gen::<u32>();
tile_morton[idx_tile_tuple(deinterleave_morton(z), 2048) as usize] = random;
}
// bench horizontal access (x direction)
b.iter(|| {
for z in 0..2048 * 2048 {
black_box(tile_morton[idx_tile_tuple(deinterleave_morton(z), 2048) as usize]);
}
});
}

fn horizontal_access_morton(b: &mut Bencher) {
let mut tile_morton = vec![0; 2048 * 2048]; // 16MB allocate more then largest cache
// fill tiles with some random numbers
for y in 0..2048 {
for x in 0..2048 {
let random = thread_rng().gen::<u32>();
tile_morton[interleave_morton(x, y) as usize] = random;
}
}
// bench horizontal access (x direction)
b.iter(|| {
for y in 0..2048 {
for x in 0..2048 {
black_box(tile_morton[interleave_morton(x, y) as usize]);
}
}
});
}

fn vertical_access_morton(b: &mut Bencher) {
let mut tile_morton = vec![0; 2048 * 2048]; // 16MB allocate more then largest cache
// fill tiles with some random numbers
for x in 0..2048 {
for y in 0..2048 {
let random = thread_rng().gen::<u32>();
tile_morton[interleave_morton(x, y) as usize] = random;
}
}
// bench vertical access (y direction)
b.iter(|| {
for x in 0..2048 {
for y in 0..2048 {
black_box(tile_morton[interleave_morton(x, y) as usize]);
}
}
});
}

fn morton_access_morton(b: &mut Bencher) {
let mut tile_morton = vec![0; 2048 * 2048]; // 16MB allocate more then largest cache
// fill tiles with some random numbers
for z in 0..2048 * 2048 {
let random = thread_rng().gen::<u32>();
tile_morton[z] = random;
}
// bench horizontal access (x direction)
b.iter(|| {
for z in 0..2048 * 2048 {
black_box(tile_morton[z]);
}
});
}

benchmark_group!(
benches,
interleave_1000,
deinterleave_1000,
interleave_deinterleave_1000,
deinterleave_interleave_1000,
horizontal_access_normal,
vertical_access_normal,
morton_access_normal,
horizontal_access_morton,
vertical_access_morton,
morton_access_morton
);
benchmark_main!(benches);
Loading

0 comments on commit 43632ab

Please sign in to comment.