Skip to content

Instantly share code, notes, and snippets.

@elbow-jason
Created February 9, 2019 19:08
Show Gist options
  • Save elbow-jason/4d46c3cae926c3ad2a754f208aef94c9 to your computer and use it in GitHub Desktop.
Save elbow-jason/4d46c3cae926c3ad2a754f208aef94c9 to your computer and use it in GitHub Desktop.
use std::thread;
use std::time as timing;
use time;
use std::fs;
use std::io;
use std::io::BufRead;
static DB_PATH: &str = "./file.db";
struct Row {
index: isize,
key: String,
value: String,
timestamp: u64,
}
pub fn read() -> io::Result<()> {
println!("init");
let start = time::precise_time_ns();
let file = fs::File::open(DB_PATH)?;
let mut rows: Vec<Row> = Vec::new();
for line in io::BufReader::new(file).lines() {
let l_string: String = line?;
let parts: Vec<&str> = l_string.split("::").collect();
let index: isize = parts[0].parse::<isize>().unwrap();
let ti: u64 = parts[3].parse::<u64>().unwrap();
rows.push(Row {
index: index,
key: parts[1].to_string(),
value: parts[2].to_string(),
timestamp: ti,
})
}
let diff = (time::precise_time_ns() - start) / 1_000_000;
println!("{:?}", rows.len());
println!("{:?}", diff);
let dur = timing::Duration::from_secs(1_000_000_000);
thread::sleep(dur);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment