Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. fn main() {
  2. let width = 500;
  3. let height = 5000;
  4. let mut total = 0.0;
  5. let mut collection =vec![255;width*height*4];
  6. for i in 0..20 {
  7. println!("round {}",i);
  8. let now = SystemTime::now();
  9. for j in 0..height {
  10. for i in 0..width {
  11. if i > width/4 && i < width*3/4 {
  12. collection[i + j*width*4] = 0;
  13. collection[i+j*width*4 + 1] = 0;
  14. collection[i+j*width*4 +2] = 0;
  15. }
  16. }
  17. }
  18. total += now.elapsed().unwrap().as_millis() as f64;
  19. }
  20. println!("20 runs took {} total for each {}",total,total/20.0) ;
  21.  
  22. println!("merge 20 20 {:?}",merge(20,20));
  23. for i in 0..20 {
  24. // merge height lines
  25. let mut collection = vec![255; width * height * 4]; //rgba for each pixel
  26. println!("round {}",i);
  27. let now = SystemTime::now();
  28. // skips four lines takes the next 8
  29. //for pixel in collection.chunks_mut(4 * width).skip(4).take(8).flat_map(|line| line[4 * 4 .. 12 * 4].chunks_mut(4)) {
  30. for pixel in collection.chunks_mut(4 * width).flat_map(|line| line[width/4 * 4 .. width*3/4 * 4].chunks_mut(4)) {
  31. pixel[.. 3].copy_from_slice(&[0, 0, 0]);
  32. }
  33. total +=now.elapsed().unwrap().as_millis() as f64;
  34. }
  35. println!("20 runs took {} total for each {}",total,total/20.0) ;
  36. // make a black square in the middle
  37. // canvas is 16x16 go from 4 to 12 for each
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement