memory.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <cassert>
  2. #ifdef __APPLE__
  3. #include<mach/mach.h>
  4. #endif
  5. #include <xlnt/xlnt.hpp>
  6. #include "../tests/helpers/path_helper.hpp"
  7. int calc_memory_usage()
  8. {
  9. #ifdef __APPLE__
  10. struct task_basic_info t_info;
  11. mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
  12. if (KERN_SUCCESS != task_info(mach_task_self(),
  13. TASK_BASIC_INFO, (task_info_t)&t_info,
  14. &t_info_count))
  15. {
  16. return 0;
  17. }
  18. return t_info.virtual_size;
  19. #endif
  20. return 0;
  21. }
  22. void test_memory_use()
  23. {
  24. // Naive test that assumes memory use will never be more than 120 % of
  25. // that for first 50 rows
  26. auto current_folder = PathHelper::GetExecutableDirectory();
  27. auto src = current_folder + "rks/files/very_large.xlsx";
  28. xlnt::workbook wb;
  29. wb.load(src);
  30. auto ws = wb.get_active_sheet();
  31. int initial_use = 0;
  32. int n = 0;
  33. for (auto line : ws.rows())
  34. {
  35. if (n % 50 == 0)
  36. {
  37. auto use = calc_memory_usage();
  38. if (initial_use == 0)
  39. {
  40. initial_use = use;
  41. }
  42. assert(use / initial_use < 1.2);
  43. std::cout << n << " " << use << std::endl;
  44. }
  45. n++;
  46. }
  47. }
  48. int main()
  49. {
  50. test_memory_use();
  51. }