diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2016-08-19 14:53:37 +0200 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2016-08-19 14:53:37 +0200 |
commit | 8d0d7de38a97f5c7e8f37b423aab804978406838 (patch) | |
tree | 8c25c651e405cb2ae294d08fda005d5e3a9216c5 /src | |
download | benchsort-master.tar.xz |
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..b9fc6c6 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,96 @@ +extern crate time; +extern crate ironsort; +extern crate quicksort; + + +use std::io::prelude::*; +use std::fs::File; +use std::cmp::Ordering; + +use time::PreciseTime; + + +#[derive(Eq)] +struct Line { + key: [u8; 10], + index: [u8; 32], + value: [u8; 52] +} + +impl PartialEq for Line { + fn eq(&self, other: &Line) -> bool { + self.key.iter().zip(other.key.iter()).all(|(a, b)| a == b) + } +} + +impl PartialOrd for Line { + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { + self.key.partial_cmp(&other.key) + } +} +impl Ord for Line { + fn cmp(&self, other: &Self) -> Ordering { + self.key.cmp(&other.key) + } +} + + +fn main() { + for input in ["10_000.dat", "1_000_000.dat", "10_000_000.dat"].iter() { + for _ in 1..10 { + let mut lines: Vec<Line> = read_file(input); + + + let start = PreciseTime::now(); + ironsort::quicksort(&mut lines); + let stop = PreciseTime::now(); + + println!("ironsort {} {}", input, start.to(stop)); + + +// let mut f = File::create(format!("output.ironsort.{}.{}", i, input)).unwrap(); +// for line in lines.iter() { +// f.write_all(&line.key).unwrap(); +// write!(&mut f, " ").unwrap(); +// f.write_all(&line.index).unwrap(); +// write!(&mut f, " ").unwrap(); +// f.write_all(&line.value).unwrap(); +// write!(&mut f, "\r\n").unwrap(); +// } + } + } + + for input in ["10_000.dat", "1_000_000.dat", "10_000_000.dat"].iter() { + for _ in 1..10 { + let mut lines: Vec<Line> = read_file(input); + + + let start = PreciseTime::now(); + ironsort::quicksort_bc(&mut lines); + let stop = PreciseTime::now(); + + println!("ironsort_bc {} {}", input, start.to(stop)); + } + } +} + + +fn read_file(file: &str) -> Vec<Line> { + let mut f = File::open(file).unwrap(); + let mut lines: Vec<Line> = Vec::new(); + + let mut buffer = [0u8; 100]; + while let Ok(_) = f.read_exact(&mut buffer) { + let mut key: [u8; 10] = [0; 10]; + key.clone_from_slice(&buffer[0..10]); + + let mut index: [u8; 32] = [0; 32]; + index.clone_from_slice(&buffer[12..44]); + + let mut value: [u8; 52] = [0; 52]; + value.clone_from_slice(&buffer[46..98]); + + lines.push(Line { key: key, index: index, value: value }); + } + lines +} |