Open
Description
I tried this code:
use std::collections::VecDeque;
fn huge_queue() -> VecDeque<usize> {
const HUGE: usize = 1000000;
let mut queue = VecDeque::with_capacity(HUGE);
for i in 0..HUGE {
queue.push_back(i);
}
queue
}
const CHUNK: usize = 123;
const FAST: bool = false;
fn main() {
let mut queue = huge_queue();
if FAST {
while queue.len() > CHUNK {
queue.rotate_left(CHUNK);
let rest = queue.split_off(queue.len() - CHUNK);
println!("Chunk of {}", rest.len());
}
} else {
while queue.len() > CHUNK {
let rest = queue.split_off(CHUNK);
println!("Chunk of {}", queue.len());
queue = rest;
}
}
println!("Remaining: {}", queue.len());
}
I expected the FAST
branch and the else
branch to have comparable performance, instead it seems VecDeque::split_off
from the front is much slower than expected (as one would expect of e.g. Vec::split_off
which needs to shift all the elements).