bench_freebusygenerator.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. include __DIR__.'/../vendor/autoload.php';
  3. if ($argc < 2) {
  4. echo 'sabre/vobject ', Sabre\VObject\Version::VERSION, " freebusy benchmark\n";
  5. echo "\n";
  6. echo "This script can be used to measure the speed of generating a\n";
  7. echo "free-busy report based on a calendar.\n";
  8. echo "\n";
  9. echo "The process will be repeated 100 times to get accurate stats\n";
  10. echo "\n";
  11. echo 'Usage: '.$argv[0]." inputfile.ics\n";
  12. exit();
  13. }
  14. list(, $inputFile) = $argv;
  15. $bench = new Hoa\Bench\Bench();
  16. $bench->parse->start();
  17. $vcal = Sabre\VObject\Reader::read(fopen($inputFile, 'r'));
  18. $bench->parse->stop();
  19. $repeat = 100;
  20. $start = new \DateTime('2000-01-01');
  21. $end = new \DateTime('2020-01-01');
  22. $timeZone = new \DateTimeZone('America/Toronto');
  23. $bench->fb->start();
  24. for ($i = 0; $i < $repeat; ++$i) {
  25. $fb = new Sabre\VObject\FreeBusyGenerator($start, $end, $vcal, $timeZone);
  26. $results = $fb->getResult();
  27. }
  28. $bench->fb->stop();
  29. echo $bench,"\n";
  30. function formatMemory($input)
  31. {
  32. if (strlen($input) > 6) {
  33. return round($input / (1024 * 1024)).'M';
  34. } elseif (strlen($input) > 3) {
  35. return round($input / 1024).'K';
  36. }
  37. }
  38. unset($input, $splitter);
  39. echo 'peak memory usage: '.formatMemory(memory_get_peak_usage()), "\n";
  40. echo 'current memory usage: '.formatMemory(memory_get_usage()), "\n";