mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add a microbenchmark for simple block layout
R=eseidel@chromium.org, ojan@chromium.org Review URL: https://codereview.chromium.org/701813004
This commit is contained in:
parent
fb8f678d27
commit
cbd29450ff
44
benchmarks/layout/simple-blocks.html
Normal file
44
benchmarks/layout/simple-blocks.html
Normal file
@ -0,0 +1,44 @@
|
||||
<sky>
|
||||
<import src="../resources/runner.sky" as="PerfRunner" />
|
||||
<style>
|
||||
div {
|
||||
height: 10px;
|
||||
}
|
||||
span {
|
||||
display: inline;
|
||||
}
|
||||
</style>
|
||||
<div id='content'></div>
|
||||
<script>
|
||||
var content = document.getElementById('content');
|
||||
|
||||
var out = [];
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
var div = document.createElement('div');
|
||||
div.appendChild(document.createElement('span')).appendChild(document.createTextNode('foo'));
|
||||
div.appendChild(document.createTextNode(' '));
|
||||
div.appendChild(document.createElement('span')).appendChild(document.createTextNode('bar'));
|
||||
content.appendChild(div);
|
||||
}
|
||||
|
||||
var b = document.querySelector('sky');
|
||||
|
||||
var runner = new PerfRunner({
|
||||
setup: function() {
|
||||
b.style.width = '210px';
|
||||
getComputedStyle(b).color;
|
||||
b.offsetHeight;
|
||||
|
||||
b.style.width = '200px';
|
||||
getComputedStyle(b).color;
|
||||
},
|
||||
iterations: 10,
|
||||
unit: 'ms',
|
||||
});
|
||||
|
||||
runner.runAsync(function(done) {
|
||||
b.offsetHeight;
|
||||
done();
|
||||
});
|
||||
</script>
|
||||
</sky>
|
||||
@ -3,6 +3,7 @@ function PerfRunner(options) {
|
||||
this.unit_ = options.unit || "ms";
|
||||
this.iterationsRemaining_ = options.iterations || 10;
|
||||
this.results_ = [];
|
||||
this.setup_ = options.setup;
|
||||
}
|
||||
|
||||
PerfRunner.prototype.log = function(line) {
|
||||
@ -17,9 +18,15 @@ PerfRunner.prototype.recordResult = function(result) {
|
||||
PerfRunner.prototype.runAsync = function(test) {
|
||||
var self = this;
|
||||
window.setTimeout(function() {
|
||||
if (self.setup_) {
|
||||
var setup = self.setup_;
|
||||
setup();
|
||||
}
|
||||
|
||||
var startTime = Date.now();
|
||||
test(function() {
|
||||
var endTime = Date.now();
|
||||
|
||||
self.recordResult(endTime - startTime);
|
||||
if (--self.iterationsRemaining_ > 0)
|
||||
self.runAsync(test);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user