summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Cargo.toml9
-rw-r--r--parse_res.py27
-rw-r--r--src/main.rs96
4 files changed, 133 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..eb5a316
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+target
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..7368cda
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "benchsort"
+version = "0.1.0"
+authors = ["Johannes Löthberg <johannes@kyriasis.com>"]
+
+[dependencies]
+time = "0.1"
+ironsort = { path = "..//ironsort" }
+quicksort = "^1.0.0"
diff --git a/parse_res.py b/parse_res.py
new file mode 100644
index 0000000..eea2972
--- /dev/null
+++ b/parse_res.py
@@ -0,0 +1,27 @@
+from pprint import pprint
+import statistics
+
+def main():
+ results = {}
+ with open("results") as f:
+ for line in f.readlines():
+ (function, input_file, time) = line.split(" ")
+
+ if input_file not in results:
+ results[input_file] = {}
+
+ if function not in results[input_file]:
+ results[input_file][function] = []
+
+ results[input_file][function].append(float(time.split("PT")[1].split("S")[0]))
+
+ for input_file in sorted(results.keys()):
+ for function in sorted(results[input_file].keys()):
+ line = results[input_file][function]
+
+ print("{} {}:\n mean: {}\n stdev: {}\n"
+ .format(function, input_file,
+ statistics.mean(line),
+ statistics.pstdev(line)))
+
+main()
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
+}