profiling.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8' />
  5. <link href='../../dist/fullcalendar.css' rel='stylesheet' />
  6. <link href='../../dist/fullcalendar.print.css' rel='stylesheet' media='print' />
  7. <script src='../../node_modules/moment/moment.js'></script>
  8. <script src='../../node_modules/jquery/dist/jquery.js'></script>
  9. <script src='../../dist/fullcalendar.js'></script>
  10. <script>
  11. $(document).ready(function() {
  12. var isOneTime = false;
  13. function initProfilingAction(containerEl, execFunc, teardownFunc) {
  14. containerEl.find('.profiling-action__button').on('click', function() {
  15. if (isOneTime) {
  16. containerEl.find('.profiling-action__result')
  17. .text(executeOneTime(execFunc) + 'ms');
  18. }
  19. else {
  20. executeTimes(execFunc, teardownFunc, 100).then(function(res) {
  21. containerEl.find('.profiling-action__result')
  22. .text(res + 'ms ave');
  23. });
  24. }
  25. });
  26. }
  27. function executeOneTime(execFunc) {
  28. var startMs;
  29. var totalMs;
  30. execFunc(function() {
  31. startMs = new Date().valueOf();
  32. }, function() {
  33. totalMs = new Date().valueOf() - startMs;
  34. });
  35. return totalMs;
  36. }
  37. function executeTimes(execFunc, teardownFunc, times) {
  38. var deferred = $.Deferred();
  39. var totalTotalMs = 0;
  40. var i = 0;
  41. function next() {
  42. if (i < times) {
  43. setTimeout(function() {
  44. var startMs;
  45. var totalMs;
  46. if (i && teardownFunc) {
  47. teardownFunc();
  48. }
  49. execFunc(function() {
  50. startMs = new Date().valueOf();
  51. }, function() {
  52. totalMs = new Date().valueOf() - startMs;
  53. });
  54. totalTotalMs += totalMs;
  55. i++;
  56. next();
  57. }, 0);
  58. }
  59. else {
  60. deferred.resolve(totalTotalMs / times);
  61. }
  62. }
  63. next();
  64. return deferred.promise();
  65. }
  66. function initCalendar() {
  67. $('#calendar').fullCalendar({
  68. headerToolbar: {
  69. left: 'prev,next today',
  70. center: 'title',
  71. right: 'month,week,day,listWeek'
  72. },
  73. initialDate: '2017-07-01',
  74. navLinks: true, // can click day/week names to navigate views
  75. editable: true
  76. });
  77. }
  78. function destroyCalendar() {
  79. $('#calendar').fullCalendar('destroy');
  80. }
  81. initProfilingAction($('#init-calendar'), function(start, stop) {
  82. start();
  83. initCalendar();
  84. stop();
  85. }, destroyCalendar);
  86. initProfilingAction($('#render-month-events'), function(start, stop) {
  87. initCalendar();
  88. var calendar = $('#calendar').fullCalendar('getCalendar');
  89. calendar.changeView('dayGridMonth');
  90. var date = calendar.view.start.clone();
  91. var end = calendar.view.end.clone();
  92. var events = [];
  93. while (date.isBefore(end)) {
  94. events.push({
  95. title: '3 day event',
  96. start: date.clone(),
  97. end: date.clone().add(3, 'days')
  98. }, {
  99. title: '2 day timed event',
  100. start: date.clone().time('03:00'),
  101. end: date.clone().add(1, 'day').time('20:00').format()
  102. }, {
  103. title: 'timed event',
  104. start: date.clone().time('16:00')
  105. }, {
  106. title: 'timed event',
  107. start: date.clone().time('16:00')
  108. }, {
  109. title: 'timed event',
  110. start: date.clone().time('16:00')
  111. }, {
  112. title: 'timed event',
  113. start: date.clone().time('16:00')
  114. }, {
  115. title: 'timed event',
  116. start: date.clone().time('16:00')
  117. });
  118. date.add(1, 'day');
  119. }
  120. start();
  121. calendar.renderEvents(events);
  122. stop();
  123. //console.log('rendered ' + events.length + ' events');
  124. }, destroyCalendar);
  125. initProfilingAction($('#render-timegrid-events'), function(start, stop) {
  126. initCalendar();
  127. var calendar = $('#calendar').fullCalendar('getCalendar');
  128. calendar.changeView('week');
  129. var date = calendar.view.start.clone();
  130. var end = calendar.view.end.clone();
  131. var events = [];
  132. var time;
  133. var calendar;
  134. while (date.isBefore(end)) {
  135. time = moment.duration(0);
  136. while (time < moment.duration('24:00')) {
  137. events.push({
  138. title: 'event',
  139. start: date.clone().time(time)
  140. });
  141. time.add(30, 'minutes');
  142. }
  143. date.add(1, 'day');
  144. }
  145. start();
  146. calendar.renderEvents(events);
  147. stop();
  148. //console.log('rendered ' + events.length + ' events');
  149. }, destroyCalendar);
  150. initProfilingAction($('#clear-events'), function(start, stop) {
  151. var calendar = $('#calendar').fullCalendar('getCalendar');
  152. start();
  153. calendar.removeEvents();
  154. stop();
  155. });
  156. });
  157. </script>
  158. <style>
  159. body {
  160. margin: 10px 10px;
  161. padding: 0;
  162. font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
  163. font-size: 14px;
  164. overflow: scroll;
  165. }
  166. #profiling-area {
  167. float: right;
  168. text-align: right;
  169. }
  170. #calendar {
  171. max-width: 900px;
  172. float: left;
  173. }
  174. </style>
  175. </head>
  176. <body>
  177. <div id='profiling-area'>
  178. <div class='profiling-action' id='init-calendar'>
  179. <span class='profiling-action__result'></span>
  180. <button class='profiling-action__button'>init calendar</button>
  181. </div>
  182. <div class='profiling-action' id='render-month-events'>
  183. <span class='profiling-action__result'></span>
  184. <button class='profiling-action__button'>render events for month</button>
  185. </div>
  186. <div class='profiling-action' id='render-timegrid-events'>
  187. <span class='profiling-action__result'></span>
  188. <button class='profiling-action__button'>render events for timegrid</button>
  189. </div>
  190. <div class='profiling-action' id='clear-events'>
  191. <span class='profiling-action__result'></span>
  192. <button class='profiling-action__button'>clear events</button>
  193. </div>
  194. </div>
  195. <div id='calendar'></div>
  196. <div style='clear:both'></div>
  197. </body>
  198. </html>