mirror of
				https://github.com/rust-lang/rust.git
				synced 2025-10-31 04:57:19 +00:00 
			
		
		
		
	 b440ef8cdf
			
		
	
	
		b440ef8cdf
		
	
	
	
	
		
			
			Unit tests directly inside of standard library crates require a very fragile way of building that is hard to reproduce outside of bootstrap.
		
			
				
	
	
		
			30 lines
		
	
	
		
			672 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			672 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use alloc::alloc::*;
 | |
| use alloc::boxed::Box;
 | |
| 
 | |
| extern crate test;
 | |
| use test::Bencher;
 | |
| 
 | |
| #[test]
 | |
| fn allocate_zeroed() {
 | |
|     unsafe {
 | |
|         let layout = Layout::from_size_align(1024, 1).unwrap();
 | |
|         let ptr =
 | |
|             Global.allocate_zeroed(layout.clone()).unwrap_or_else(|_| handle_alloc_error(layout));
 | |
| 
 | |
|         let mut i = ptr.as_non_null_ptr().as_ptr();
 | |
|         let end = i.add(layout.size());
 | |
|         while i < end {
 | |
|             assert_eq!(*i, 0);
 | |
|             i = i.add(1);
 | |
|         }
 | |
|         Global.deallocate(ptr.as_non_null_ptr(), layout);
 | |
|     }
 | |
| }
 | |
| 
 | |
| #[bench]
 | |
| fn alloc_owned_small(b: &mut Bencher) {
 | |
|     b.iter(|| {
 | |
|         let _: Box<_> = Box::new(10);
 | |
|     })
 | |
| }
 |