| OLD | NEW |
| 1 <head> | 1 <head> |
| 2 <style> | 2 <style> |
| 3 tr { | 3 tr { |
| 4 white-space: nowrap; | 4 white-space: nowrap; |
| 5 } | 5 } |
| 6 .results { | 6 .results { |
| 7 text-align: right; | 7 text-align: right; |
| 8 min-width: 6em; | 8 min-width: 6em; |
| 9 color: black; | 9 color: black; |
| 10 } | 10 } |
| 11 </style> | 11 </style> |
| 12 <script> | 12 <script> |
| 13 if (!chrome.benchmarking) { |
| 14 alert("Warning: Looks like you forgot to run chrome with " + |
| 15 " --enable-benchmarking set."); |
| 16 return; |
| 17 } |
| 18 |
| 13 function setChildTextNode(elementId, text) { | 19 function setChildTextNode(elementId, text) { |
| 14 document.getElementById(elementId).innerText = text; | 20 document.getElementById(elementId).innerText = text; |
| 15 } | 21 } |
| 16 | 22 |
| 17 // Tests the roundtrip time of sendRequest(). | 23 // Tests the roundtrip time of sendRequest(). |
| 18 function testRequest() { | 24 function testRequest() { |
| 19 setChildTextNode("resultsRequest", "running..."); | 25 setChildTextNode("resultsRequest", "running..."); |
| 20 | 26 |
| 21 chrome.tabs.getSelected(null, function(tab) { | 27 chrome.tabs.getSelected(null, function(tab) { |
| 22 var timer = new chromium.Interval(); | 28 var timer = new chrome.Interval(); |
| 23 timer.start(); | 29 timer.start(); |
| 24 | 30 |
| 25 chrome.tabs.sendRequest(tab.id, {counter: 1}, function handler(response) { | 31 chrome.tabs.sendRequest(tab.id, {counter: 1}, function handler(response) { |
| 26 if (response.counter < 1000) { | 32 if (response.counter < 1000) { |
| 27 chrome.tabs.sendRequest(tab.id, {counter: response.counter}, handler); | 33 chrome.tabs.sendRequest(tab.id, {counter: response.counter}, handler); |
| 28 } else { | 34 } else { |
| 29 timer.stop(); | 35 timer.stop(); |
| 30 var usec = Math.round(timer.microseconds() / response.counter); | 36 var usec = Math.round(timer.microseconds() / response.counter); |
| 31 setChildTextNode("resultsRequest", usec + "usec"); | 37 setChildTextNode("resultsRequest", usec + "usec"); |
| 32 } | 38 } |
| 33 }); | 39 }); |
| 34 }); | 40 }); |
| 35 } | 41 } |
| 36 | 42 |
| 37 // Tests the roundtrip time of Port.postMessage() after opening a channel. | 43 // Tests the roundtrip time of Port.postMessage() after opening a channel. |
| 38 function testConnect() { | 44 function testConnect() { |
| 39 setChildTextNode("resultsConnect", "running..."); | 45 setChildTextNode("resultsConnect", "running..."); |
| 40 | 46 |
| 41 chrome.tabs.getSelected(null, function(tab) { | 47 chrome.tabs.getSelected(null, function(tab) { |
| 42 var timer = new chromium.Interval(); | 48 var timer = new chrome.Interval(); |
| 43 timer.start(); | 49 timer.start(); |
| 44 | 50 |
| 45 var port = chrome.tabs.connect(tab.id); | 51 var port = chrome.tabs.connect(tab.id); |
| 46 port.postMessage({counter: 1}); | 52 port.postMessage({counter: 1}); |
| 47 port.onMessage.addListener(function getResp(response) { | 53 port.onMessage.addListener(function getResp(response) { |
| 48 if (response.counter < 1000) { | 54 if (response.counter < 1000) { |
| 49 port.postMessage({counter: response.counter}); | 55 port.postMessage({counter: response.counter}); |
| 50 } else { | 56 } else { |
| 51 timer.stop(); | 57 timer.stop(); |
| 52 var usec = Math.round(timer.microseconds() / response.counter); | 58 var usec = Math.round(timer.microseconds() / response.counter); |
| 53 setChildTextNode("resultsConnect", usec + "usec"); | 59 setChildTextNode("resultsConnect", usec + "usec"); |
| 54 } | 60 } |
| 55 }); | 61 }); |
| 56 }); | 62 }); |
| 57 } | 63 } |
| 58 </script> | 64 </script> |
| 59 </head> | 65 </head> |
| 60 <body> | 66 <body> |
| 61 <table> | 67 <table> |
| 62 <tr> | 68 <tr> |
| 63 <td><button onclick="testRequest()">Measure sendRequest</button></td> | 69 <td><button onclick="testRequest()">Measure sendRequest</button></td> |
| 64 <td id="resultsRequest" class="results">(results)</td> | 70 <td id="resultsRequest" class="results">(results)</td> |
| 65 </tr> | 71 </tr> |
| 66 <tr> | 72 <tr> |
| 67 <td><button onclick="testConnect()">Measure postMessage</button></td> | 73 <td><button onclick="testConnect()">Measure postMessage</button></td> |
| 68 <td id="resultsConnect" class="results">(results)</td> | 74 <td id="resultsConnect" class="results">(results)</td> |
| 69 </tr> | 75 </tr> |
| 70 </table> | 76 </table> |
| 71 </body> | 77 </body> |
| OLD | NEW |