mpsc.rs 796 B

123456789101112131415161718192021222324252627282930313233
  1. #![feature(test)]
  2. extern crate ralloc;
  3. extern crate test;
  4. #[global_allocator]
  5. static ALLOCATOR: ralloc::Allocator = ralloc::Allocator;
  6. use std::sync::mpsc;
  7. use std::thread;
  8. #[bench]
  9. fn bench_mpsc(b: &mut test::Bencher) {
  10. b.iter(|| {
  11. let (tx, rx) = mpsc::channel::<Box<u64>>();
  12. thread::spawn(move || {
  13. tx.send(Box::new(0xBABAFBABAF)).unwrap();
  14. tx.send(Box::new(0xDEADBEAF)).unwrap();
  15. tx.send(Box::new(0xDECEA5E)).unwrap();
  16. tx.send(Box::new(0xDEC1A551F1E5)).unwrap();
  17. });
  18. let (ty, ry) = mpsc::channel();
  19. for _ in 0..0xFF {
  20. let ty = ty.clone();
  21. thread::spawn(move || {
  22. ty.send(Box::new(0xFA11BAD)).unwrap();
  23. });
  24. }
  25. (rx, ry)
  26. });
  27. }