Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. use std::time::Instant;
  2.  
  3. use rand::distributions::Standard;
  4. use rand::{thread_rng, Rng};
  5.  
  6. fn main() {
  7. // make some sample pixels
  8. let rng = thread_rng();
  9. // 1080p ARGB image
  10. let mut v: Vec<u8> = rng.sample_iter(&Standard).take(1920 * 1080 * 4).collect();
  11.  
  12. // set alpha to 255
  13. v.iter_mut().step_by(4).for_each(|x| *x = 255);
  14.  
  15. // ARGBARGBARGB -> AAARRRGGGBBB
  16. let mut pixel_order = (0..4).cycle();
  17.  
  18. // AoS -> SoA
  19. let timer = Instant::now();
  20. v.sort_by_cached_key(|_| pixel_order.next());
  21. println!("{:#?}", timer.elapsed());
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement