mpsc.rs 718 B

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