fork(1) download
  1. #include <iostream>
  2. #include <chrono>
  3. #include <vector>
  4. #include <type_traits>
  5.  
  6. struct S {
  7. int hui;
  8. double pizda;
  9. short dzhigurda;
  10. };
  11.  
  12. template <typename T> struct uninitialized_allocator {
  13. using value_type = T;
  14.  
  15. template<typename U, typename... Args>
  16. void construct(U * const ptr, Args&&... args) {}
  17.  
  18. T* allocate(size_t n) {
  19. return allocator.allocate(n);
  20. }
  21.  
  22. void deallocate(T* const ptr, size_t n) {
  23. allocator.deallocate(ptr, n);
  24. }
  25.  
  26. std::allocator<T> allocator;
  27. };
  28.  
  29. int main() {
  30.  
  31. auto t = std::chrono::system_clock::now();
  32. std::vector<S> v1(1000000);
  33. std::cout << std::chrono::duration<double, std::milli>(std::chrono::system_clock::now() - t).count() << std::endl;
  34.  
  35. t = std::chrono::system_clock::now();
  36.  
  37. std::vector<S, uninitialized_allocator<S>> v2(1000000);
  38. std::cout << std::chrono::duration<double, std::milli>(std::chrono::system_clock::now() - t).count() << std::endl;
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0.02s 26396KB
stdin
Standard input is empty
stdout
10.205
0.008616