Discussion about this post

User's avatar
Nick E.'s avatar

Cool how you outlined your thinking and your experiment steps!

Expand full comment
Marc Enriquez's avatar

Would you mind trying this Rust code instead? Although a bit less naive than your first approach, it avoids a lot of the unnecessary allocations existing in your code

fn main() {

let before = Instant::now();

let source_file = File::open("divvy-tripdata.csv").expect("can't open file");

let mut reader = BufReader::new(source_file);

let destination_file = File::create("divvy-biketrip.tsv").expect("problem with file");

let mut writer = BufWriter::new(destination_file);

let mut buffer = String::new();

loop {

buffer.clear();

let read_count = reader.read_line(&mut buffer).expect("something went wrong reading the file");

if read_count == 0 {

break;

}

let replaced = buffer.replace(",", "\t");

writer.write(replaced.as_bytes()).expect("problem writing lines");

}

println!("Elapsed time: {:.2?}", before.elapsed());

}

Expand full comment
3 more comments...

No posts