Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::time::Instant;
- use rand::distributions::Standard;
- use rand::{thread_rng, Rng};
- fn main() {
- // make some sample pixels
- let rng = thread_rng();
- // 1080p ARGB image
- let mut v: Vec<u8> = rng.sample_iter(&Standard).take(1920 * 1080 * 4).collect();
- // set alpha to 255
- v.iter_mut().step_by(4).for_each(|x| *x = 255);
- // ARGBARGBARGB -> AAARRRGGGBBB
- let mut pixel_order = (0..4).cycle();
- // AoS -> SoA
- let timer = Instant::now();
- v.sort_by_cached_key(|_| pixel_order.next());
- println!("{:#?}", timer.elapsed());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement