realloc.rs 770 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. extern crate ralloc;
  2. #[global_allocator]
  3. static ALLOCATOR: ralloc::Allocator = ralloc::Allocator;
  4. mod util;
  5. #[test]
  6. fn realloc_vec() {
  7. util::multiply(|| {
  8. let mut vec = Vec::new();
  9. vec.reserve(1);
  10. vec.reserve(2);
  11. util::acid(|| {
  12. vec.reserve(3);
  13. vec.reserve(100);
  14. vec.reserve(600);
  15. });
  16. vec.reserve(1000);
  17. vec.reserve(2000);
  18. vec.push(1);
  19. vec.push(2);
  20. });
  21. }
  22. #[test]
  23. fn realloc_vec_2() {
  24. util::multiply(|| {
  25. let mut vec = Vec::with_capacity(4);
  26. vec.push(1);
  27. vec.push(2);
  28. vec.push(101);
  29. for x in 0..300 {
  30. util::acid(|| {
  31. vec.reserve_exact(x);
  32. });
  33. }
  34. });
  35. }