#![feature(test)] #![allow(non_snake_case)] extern crate test; use test::Bencher; extern crate retro_pixel; use retro_pixel::*; #[bench] fn bench_vga_u8_clear(b: &mut Bencher) { let mut dest: VecImage = VecImage::new(640, 480); let mut src: VecImage = VecImage::new(640, 480); for (x, y, p_mut_ref) in src.iter_mut() { if x % 2 == 0 || y % 2 == 0 { *p_mut_ref = 1; } } b.iter(|| dest.set_all(0)); } #[bench] fn bench_vga_u8_clear_blit1(b: &mut Bencher) { let mut dest: VecImage = VecImage::new(640, 480); let mut src: VecImage = VecImage::new(640, 480); for (x, y, p_mut_ref) in src.iter_mut() { if x % 2 == 0 || y % 2 == 0 { *p_mut_ref = 1; } } b.iter(|| { dest.set_all(0); dest.blit_generic(&src, (0, 0), |src, dest| if src > 0 { src } else { dest }) }); } #[bench] fn bench_vga_u8_clear_blit2(b: &mut Bencher) { let mut dest: VecImage = VecImage::new(640, 480); let mut src: VecImage = VecImage::new(640, 480); for (x, y, p_mut_ref) in src.iter_mut() { if x % 2 == 0 || y % 2 == 0 { *p_mut_ref = 1u8; } } b.iter(|| { dest.set_all(0); dest.blit_generic(&src, (0, 0), |src, dest| if src > 0 { src } else { dest }); dest.blit_generic(&src, (0, 0), |src, dest| if src > 0 { src } else { dest }) }); } #[bench] fn bench_1080p_u8_clear_blit5(b: &mut Bencher) { let mut dest: VecImage = VecImage::new(1920, 1080); let mut src: VecImage = VecImage::new(1920, 1080); for (x, y, p_mut_ref) in src.iter_mut() { if x % 2 == 0 || y % 2 == 0 { *p_mut_ref = 1; } } b.iter(|| { dest.set_all(0); dest.blit_generic(&src, (0, 0), |src, dest| if src > 0 { src } else { dest }); dest.blit_generic(&src, (0, 0), |src, dest| if src > 0 { src + 1 } else { dest }); dest.blit_generic(&src, (0, 0), |src, dest| if src > 0 { src * 3 } else { dest }); dest.blit_generic(&src, (0, 0), |src, dest| if src > 0 { 0 } else { dest }); dest.blit_generic(&src, (0, 0), |src, dest| if src > 0 { src } else { dest }) }); } #[bench] fn bench_1080p_u32_clear_blit5(b: &mut Bencher) { let mut dest: VecImage = VecImage::new(1920, 1080); let mut src: VecImage = VecImage::new(1920, 1080); for (x, y, p_mut_ref) in src.iter_mut() { if x % 2 == 0 || y % 2 == 0 { *p_mut_ref = 1; } } b.iter(|| { dest.set_all(0xff00ff00u32); dest.blit_blend_rectilinear(&src, (1, 0)); dest.blit_blend_rectilinear(&src, (1, 0)); dest.blit_blend_rectilinear(&src, (1, 0)); dest.blit_blend_rectilinear(&src, (1, 0)); dest.blit_blend_rectilinear(&src, (1, 0)) }); } #[bench] fn bench_vga_u32_clear(b: &mut Bencher) { let mut dest: VecImage = VecImage::new(640, 480); b.iter(|| dest.set_all(0xff00ff00u32)); } #[bench] fn bench_vga_u32_clear_blit1(b: &mut Bencher) { let mut dest: VecImage = VecImage::new(640, 480); let mut src: VecImage = VecImage::new(640, 480); for (x, y, p_mut_ref) in src.iter_mut() { if x % 2 == 0 || y % 2 == 0 { *p_mut_ref = 1; } } b.iter(|| { dest.set_all(0xff00ff00); dest.blit_blend_rectilinear(&src, (0, 0)) }); } #[bench] fn bench_vga_u32_clear_blit2(b: &mut Bencher) { let mut dest: VecImage = VecImage::new(640, 480); let mut src: VecImage = VecImage::new(640, 480); for (x, y, p_mut_ref) in src.iter_mut() { if x % 2 == 0 || y % 2 == 0 { *p_mut_ref = 1; } } b.iter(|| { dest.set_all(0xff00ff00u32); dest.blit_blend_rectilinear(&src, (1, 0)); dest.blit_blend_rectilinear(&src, (1, 0)) }); } #[bench] fn bench_vga_u32_clear_blit5(b: &mut Bencher) { let mut dest: VecImage = VecImage::new(640, 480); let mut src: VecImage = VecImage::new(640, 480); for (x, y, p_mut_ref) in src.iter_mut() { if x % 2 == 0 || y % 2 == 0 { *p_mut_ref = 1; } } b.iter(|| { dest.set_all(0xff00ff00u32); dest.blit_blend_rectilinear(&src, (1, 0)); dest.blit_blend_rectilinear(&src, (1, 0)); dest.blit_blend_rectilinear(&src, (1, 0)); dest.blit_blend_rectilinear(&src, (1, 0)); dest.blit_blend_rectilinear(&src, (1, 0)) }); } #[bench] fn bench_gba_u16_clear_blit5(b: &mut Bencher) { let mut dest: VecImage = VecImage::new(240, 160); let mut src: VecImage = VecImage::new(240, 160); for (x, y, p_mut_ref) in src.iter_mut() { if x % 2 == 0 || y % 2 == 0 { *p_mut_ref = p_mut_ref.wrapping_neg(); } } b.iter(|| { dest.set_all(0xff00u16); dest.blit_rgba16(&src, (0, 0)); dest.blit_rgba16(&src, (0, 0)); dest.blit_rgba16(&src, (0, 0)); dest.blit_rgba16(&src, (0, 0)); dest.blit_rgba16(&src, (0, 0)) }); }