mpsc.rs 727 B

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