From 8d0d7de38a97f5c7e8f37b423aab804978406838 Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Fri, 19 Aug 2016 14:53:37 +0200 Subject: Initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Johannes Löthberg --- src/main.rs | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/main.rs (limited to 'src') 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 { + 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 = 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 = 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 { + let mut f = File::open(file).unwrap(); + let mut lines: Vec = 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 +} -- cgit v1.2.3-70-g09d2