Skip to content

Commit

Permalink
bean: Reduce memory load, and teardown slowdown by reusing handlers w…
Browse files Browse the repository at this point in the history
…here possible. [jddalton]
  • Loading branch information
jdalton committed Dec 4, 2011
1 parent 9772c5c commit 7427ba9
Showing 1 changed file with 22 additions and 34 deletions.
56 changes: 22 additions & 34 deletions tests/benchmark.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ <h1>Running Benchmark Suite</h1>
<script>

var element;
var fn = function () {};
var suite = new Benchmark.Suite;

suite
Expand Down Expand Up @@ -64,56 +63,42 @@ <h1>Running Benchmark Suite</h1>
}) }
, { 'setup': function () { element = document.createElement('div'); }
, 'teardown': function () { bean.remove(element); }
})
}
)

.add( 'remove()'
, function() { bean.remove( element ); }
, { 'setup': function () {
var i = 100;
element = document.createElement('div');
while (i--) bean.add(element, 'click', function () {});
}
, function() {
bean.add(element, 'click', function () {});
bean.remove( element );
}
)

.add( 'remove( event )'
, function() { bean.remove( element, 'click' ); }
, { 'setup': function () {
var i = 100;
element = document.createElement('div');
while (i--) bean.add(element, 'click', function () {});
}
, function() {
bean.add(element, 'click', function () {});
bean.remove( element, 'click' );
}
)

.add( 'remove( custom )'
, function() { bean.remove( element, 'fat' ); }
, { 'setup': function () {
var i = 100;
element = document.createElement('div');
while (i--) bean.add(element, 'fat', function () {});
}
, function() {
bean.add(element, 'fat', function () {});
bean.remove( element, 'fat' );
}
)

.add( 'remove( namespace )'
, function() { bean.remove( element, '.foo' ); }
, { 'setup': function () {
var i = 100;
element = document.createElement('div');
while (i--) bean.add(element, 'click.foo', function () {});
}
, function() {
bean.add(element, 'click.foo', function () {});
bean.remove( element, 'click.foo' );
}
)

.add( 'remove( event, fn )'
, function() { bean.remove( element, 'click', fn ); }
, { 'setup': function () {
var i = 99;
element = document.createElement('div');
while (i--) bean.add(element, 'click', function () {});
bean.add(element, 'click', fn);
}
, function() {
var fn = function () {};
bean.add(element, 'click', fn);
bean.remove( element, 'click', fn );
}
)

Expand All @@ -124,6 +109,7 @@ <h1>Running Benchmark Suite</h1>
element = document.createElement('div');
while (i--) bean.add(element, 'click', function () {});
}
, 'teardown': function () { bean.remove(element); }
}
)

Expand All @@ -134,16 +120,18 @@ <h1>Running Benchmark Suite</h1>
element = document.createElement('div');
while (i--) bean.add(element, 'fat', function () {});
}
, 'teardown': function () { bean.remove(element); }
}
)

.add( 'fire( namespace )'
, function() { bean.fire( element, '.foo' ); }
, function() { bean.fire( element, 'click.foo' ); }
, { 'setup': function () {
var i = 100;
element = document.createElement('div');
while (i--) bean.add(element, 'click.foo', function () {});
}
, 'teardown': function () { bean.remove(element); }
}
)

Expand Down

0 comments on commit 7427ba9

Please sign in to comment.