PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/codebench/views/codebench.php

https://bitbucket.org/seyar/kinda.local
PHP | 258 lines | 162 code | 38 blank | 58 comment | 20 complexity | 1c366a978a143c594a41edf5e4f528e7 MD5 | raw file
  1. <?php defined('SYSPATH') or die('No direct access allowed.');
  2. /**
  3. * Codebench — A benchmarking module.
  4. *
  5. * @package Kohana
  6. * @author Kohana Team
  7. * @copyright (c) 2009 Kohana Team
  8. * @license http://kohanaphp.com/license.html
  9. */
  10. ?>
  11. <!DOCTYPE html>
  12. <html lang="en">
  13. <head>
  14. <meta charset="utf-8" />
  15. <title><?php if ($class !== '') echo $class, ' · ' ?>Codebench</title>
  16. <style>
  17. /* General styles*/
  18. body { position:relative; margin:1em 2em; font:12px monaco,monospace; }
  19. h1 { font-size:24px; letter-spacing:-0.05em; }
  20. h2 { font-size:18px; letter-spacing:-0.1em; }
  21. input, code { font:inherit; }
  22. code { background:#e5e5e5; }
  23. caption { display:none; }
  24. /* Form */
  25. #runner { margin-bottom:2em; }
  26. #runner input[type="text"] { letter-spacing:-0.05em; }
  27. /* Expand/Collapse all */
  28. #toggle_all { position:absolute; top:0; right:0; margin:0; padding:0 4px; background:#000; font-size:18px; color:#fff; cursor:pointer; -moz-border-radius:2px; -webkit-border-radius:2px; }
  29. /* Benchmark main graphs */
  30. #bench { margin:2em 0; padding:0; list-style:none; }
  31. #bench > li { margin:6px 0; }
  32. #bench h2 { position:relative; margin:0; padding:2px; background:#ccc; border:1px solid #999; cursor:pointer; -moz-border-radius:3px; -webkit-border-radius:3px; }
  33. #bench h2 > span { display:block; min-width:1px; height:33px; background:#fff; -moz-border-radius:2px; -webkit-border-radius:2px; }
  34. #bench h2 .method { position:absolute; top:6px; left:8px; text-shadow:0 -1px 0 rgba(255,255,255,0.6); }
  35. #bench h2 .method:before { content:'▸ '; }
  36. #bench h2 .percent { position:absolute; top:6px; right:6px; padding:0 4px; background:#000; color:#fff; font-weight:normal; letter-spacing:0; -moz-border-radius:2px; -webkit-border-radius:2px; }
  37. #bench h2:hover .method { left:10px; }
  38. #bench h2.expanded { margin:12px 0 0; -moz-border-radius-bottomleft:0; -moz-border-radius-bottomright:0; -webkit-border-bottom-left-radius:0; -webkit-border-bottom-right-radius:0; }
  39. #bench h2.expanded .method:before { content:'▾ '; }
  40. /* Colorization of the bars */
  41. #bench .grade-A { background:#3f0; }
  42. #bench .grade-B { background:#fc0; }
  43. #bench .grade-C { background:#f90; }
  44. #bench .grade-D { background:#f60; }
  45. #bench .grade-E { background:#f30; }
  46. #bench .grade-F { background:#f00; }
  47. /* Benchmark details */
  48. #bench > li > div { display:none; margin:0 0 12px; padding:0 0 2px; background:#eee; border:1px solid #999; border-top:0; -moz-border-radius-bottomleft:3px; -moz-border-radius-bottomright:3px; -webkit-border-bottom-left-radius:3px; -webkit-border-bottom-right-radius:3px; }
  49. #bench > li > div table { width:100%; background:#eee; border-collapse:collapse; }
  50. #bench > li > div th { padding:6px; background:#ddd url(data:image/gif;base64,R0lGODlhAQASALMAAMfHx8TExM7Oztvb29jY2NbW1tPT09DQ0MrKygAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAAAAAAALAAAAAABABIAAAQNMAQAEBLiHGNKIcQwRAA7) repeat-x 0 1px; text-align:left; }
  51. #bench > li > div td { padding:6px; border-top:1px solid #ccc; vertical-align:top; }
  52. #bench .numeric { padding-left:18px; text-align:right; }
  53. #bench .numeric span { position:relative; display:block; height:16px; }
  54. #bench .numeric span span { position:absolute; top:0; right:0; min-width:1px; background:#ccc; -moz-border-radius:2px; -webkit-border-radius:2px; }
  55. #bench .numeric span span span { top:0; right:0; background:none; }
  56. #bench tbody tr:hover { background:#fff; }
  57. #bench tbody tr.highlight { background:#ffc; }
  58. /* Footer */
  59. #footer { margin-top:2em; padding-top:1em; border-top:1px solid #ccc; color:#999; }
  60. #footer a { color:inherit; }
  61. /* Misc text styles */
  62. .alert { padding:0 0.5em; background:#900; font-weight:normal; color:#fff; -moz-border-radius:3px; -webkit-border-radius:3px; }
  63. .quiet { color:#999; }
  64. .help { cursor:help; }
  65. </style>
  66. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  67. <script>
  68. $(document).ready(function() {
  69. // Insert "Toggle All" button
  70. var expand_all_text = '▸ Expand all';
  71. var collapse_all_text = '▾ Collapse all';
  72. $('#bench').before('<p id="toggle_all">'+expand_all_text+'</p>');
  73. // Cache these selection operations
  74. var $runner = $('#runner');
  75. var $toggle_all = $('#toggle_all');
  76. var $bench_titles = $('#bench > li > h2');
  77. var $bench_rows = $('#bench > li > div > table > tbody > tr');
  78. // Runner form
  79. $(':input:first', $runner).focus();
  80. $runner.submit(function() {
  81. $(':submit', this).attr('value', 'Running…').attr('disabled', 'disabled');
  82. $('.alert', this).remove();
  83. });
  84. // Toggle details for all benchmarks
  85. $('#toggle_all').click(function() {
  86. if ($(this).data('expanded')) {
  87. $(this).data('expanded', false);
  88. $(this).text(expand_all_text);
  89. $bench_titles.removeClass('expanded').siblings().hide();
  90. }
  91. else {
  92. $(this).data('expanded', true);
  93. $(this).text(collapse_all_text);
  94. $bench_titles.addClass('expanded').siblings().show();
  95. }
  96. });
  97. <?php if (Kohana::config('codebench')->expand_all) { ?>
  98. // Expand all benchmark details by default
  99. $toggle_all.click();
  100. <?php } ?>
  101. // Toggle details for a single benchmark
  102. $bench_titles.click(function() {
  103. $(this).toggleClass('expanded').siblings().toggle();
  104. // Counts of bench titles
  105. var total_bench_titles = $bench_titles.length;
  106. var expanded_bench_titles = $bench_titles.filter('.expanded').length;
  107. // If no benchmark details are expanded, change "Collapse all" to "Expand all"
  108. if (expanded_bench_titles == 0 && $toggle_all.data('expanded')) {
  109. $toggle_all.click();
  110. }
  111. // If all benchmark details are expanded, change "Expand all" to "Collapse all"
  112. else if (expanded_bench_titles == total_bench_titles && ! $toggle_all.data('expanded')) {
  113. $toggle_all.click();
  114. }
  115. });
  116. // Highlight clicked rows
  117. $bench_rows.click(function() {
  118. $(this).toggleClass('highlight');
  119. // Highlight doubleclicked rows globally
  120. }).dblclick(function() {
  121. var nth_row = $(this).parent().children().index(this) + 1;
  122. if ($(this).hasClass('highlight')) {
  123. $bench_rows.filter(':nth-child('+nth_row+')').removeClass('highlight');
  124. }
  125. else {
  126. $bench_rows.filter(':nth-child('+nth_row+')').addClass('highlight');
  127. }
  128. });
  129. });
  130. </script>
  131. </head>
  132. <body>
  133. <!--[if IE]><p class="alert">This page is not meant to be viewed in Internet Explorer. Get a better browser.</p><![endif]-->
  134. <form id="runner" method="post" action="<?php echo URL::site('codebench') ?>">
  135. <h1>
  136. <input name="class" type="text" value="<?php echo ($class !== '') ? $class : 'Bench_' ?>" size="25" title="Name of the Codebench library to run" />
  137. <input type="submit" value="Run" />
  138. <?php if ( ! empty($class)) { ?>
  139. <?php if (empty($codebench)) { ?>
  140. <strong class="alert">Library not found</strong>
  141. <?php } elseif (empty($codebench['benchmarks'])) { ?>
  142. <strong class="alert">No methods found to benchmark</strong>
  143. <?php } ?>
  144. <?php } ?>
  145. </h1>
  146. </form>
  147. <?php if ( ! empty($codebench)) { ?>
  148. <?php if (empty($codebench['benchmarks'])) { ?>
  149. <p>
  150. <strong>
  151. Remember to prefix the methods you want to benchmark with bench.<br />
  152. You might also want to overwrite <code>Codebench->method_filter()</code>.
  153. </strong>
  154. </p>
  155. <?php } else { ?>
  156. <ul id="bench">
  157. <?php foreach ($codebench['benchmarks'] as $method => $benchmark) { ?>
  158. <li>
  159. <h2 title="<?php printf('%01.6f', $benchmark['time']) ?>s">
  160. <span class="grade-<?php echo $benchmark['grade']['time'] ?>" style="width:<?php echo $benchmark['percent']['slowest']['time'] ?>%">
  161. <span class="method"><?php echo $method ?></span>
  162. <span class="percent">+<?php echo (int) $benchmark['percent']['fastest']['time'] ?>%</span>
  163. </span>
  164. </h2>
  165. <div>
  166. <table>
  167. <caption>Benchmarks per subject for <?php echo $method ?></caption>
  168. <thead>
  169. <tr>
  170. <th style="width:50%">subject return</th>
  171. <th class="numeric" style="width:25%" title="Total method memory"><?php echo Text::bytes($benchmark['memory'], 'MB', '%01.6f%s') ?></th>
  172. <th class="numeric" style="width:25%" title="Total method time"><?php printf('%01.6f', $benchmark['time']) ?>s</th>
  173. </tr>
  174. </thead>
  175. <tbody>
  176. <?php foreach ($benchmark['subjects'] as $subject_key => $subject) { ?>
  177. <tr>
  178. <td>
  179. <strong class="help" title="(<?php echo gettype($codebench['subjects'][$subject_key]) ?>) <?php echo HTML::chars(var_export($codebench['subjects'][$subject_key], TRUE)) ?>">
  180. [<?php echo HTML::chars($subject_key) ?>]
  181. </strong>
  182. <span class="quiet">(<?php echo gettype($subject['return']) ?>)</span>
  183. <?php echo HTML::chars(var_export($subject['return'], TRUE)) ?>
  184. </td>
  185. <td class="numeric">
  186. <span title="+<?php echo (int) $subject['percent']['fastest']['memory'] ?>% memory">
  187. <span style="width:<?php echo $subject['percent']['slowest']['memory'] ?>%">
  188. <span><?php echo Text::bytes($subject['memory'], 'MB', '%01.6f%s') ?></span>
  189. </span>
  190. </span>
  191. </td>
  192. <td class="numeric">
  193. <span title="+<?php echo (int) $subject['percent']['fastest']['time'] ?>% time">
  194. <span style="width:<?php echo $subject['percent']['slowest']['time'] ?>%">
  195. <span><?php printf('%01.6f', $subject['time']) ?>s</span>
  196. </span>
  197. </span>
  198. </td>
  199. </tr>
  200. <?php } ?>
  201. </tbody>
  202. </table>
  203. </div>
  204. </li>
  205. <?php } ?>
  206. </ul>
  207. <?php } ?>
  208. <?php if ( ! empty($codebench['description'])) { ?>
  209. <?php echo Text::auto_p(Text::auto_link($codebench['description']), FALSE) ?>
  210. <?php } ?>
  211. <?php // echo '<h2>Raw output:</h2>', Kohana::debug($codebench) ?>
  212. <?php } ?>
  213. <p id="footer">
  214. Page executed in <strong><?php echo round(microtime(TRUE) - KOHANA_START_TIME, 2) ?>&nbsp;s</strong>
  215. using <strong><?php echo Text::widont(Text::bytes(memory_get_usage(), 'MB')) ?></strong> of memory.<br />
  216. <a href="http://github.com/kohana/codebench">Codebench</a>, a <a href="http://kohanaframework.org/">Kohana</a> module
  217. by <a href="http://www.geertdedeckere.be/article/introducing-codebench">Geert De Deckere</a>.
  218. </p>
  219. </body>
  220. </html>