Skip to content

Commit

Permalink
add benchmark.html + benchmark.js
Browse files Browse the repository at this point in the history
  • Loading branch information
fat committed Nov 28, 2011
1 parent 6564c28 commit 6bd6861
Show file tree
Hide file tree
Showing 2 changed files with 2,977 additions and 0 deletions.
163 changes: 163 additions & 0 deletions tests/benchmark.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<!DOCTYPE HTML>
<html lang="en-us">
<head>
<title>Bean Benchmarks</title>
<script src="benchmark.js"></script>
<script src="../src/bean.js"></script>
<script>

var suite = new Benchmark.Suite

suite

.add( 'add( element, event, fn )'
, function() { bean.add(element, 'click', function () {}) }
, { 'setup': function () { var element = document.createElement('div') }
, 'teardown': function () { bean.remove(element); element = null; }
}
)

.add( 'add( element, custom, fn )'
, function() { bean.add(element, 'fat', function () {}) }
, { 'setup': function () { var element = document.createElement('div') }
, 'teardown': function () { bean.remove(element); element = null; }
}
)

.add( 'add( element, event.namespace, fn )'
, function() { bean.add(element, 'click.fat', function () {}) }
, { 'setup': function () { var element = document.createElement('div') }
, 'teardown': function () { bean.remove(element); element = null; }
}
)

.add( 'add( element, selector, event, fn )'
, function() { bean.add(element, 'a.close', 'click', function () {}) }
, { 'setup': function () { var element = document.createElement('div') }
, 'teardown': function () { bean.remove(element); element = null; }
}
)

.add( 'add( element, selector, event, fn )'

This comment has been minimized.

Copy link
@jdalton

jdalton Dec 5, 2011

Contributor

Just noticed this is a double benchmark of line 34 (It also made its way into the recent tweaks too).

This comment has been minimized.

Copy link
@fat

fat Dec 5, 2011

Author Owner

gotcha, i'll be sure to clean that up, thanks!

, function() { bean.add(element, 'a.close', 'click', function () {}) }
, { 'setup': function () { var element = document.createElement('div') }
, 'teardown': function () { bean.remove(element); element = null; }
}
)

.add( 'add( {} )'
, function() { bean.add(element, {
'click': function () {}
, 'mouseover': function () {}
, 'mouseout': function () {}
}) }
, { 'setup': function () { var element = document.createElement('div') }
, 'teardown': function () { bean.remove(element); element = null; }
})

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

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

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

.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 () {})
}
, 'teardown': function () { element = null; }
}
)

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

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

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

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

.on( 'cycle'
, function(e, benchmark) {
if (benchmark.error) throw benchmark.error
var item = document.createElement('div')
item.innerHTML = benchmark.name + ': ' + (Math.round(benchmark.hz * 100) / 100) + ' ops/sec'
document.body.appendChild(item)
}
)

.on( 'complete'
, function(e, benchmark) {
var item = document.createElement('h3')
item.innerHTML = 'benchmarking complete!'
document.body.appendChild(item)
}
)

.run({ 'async': true });

</script>
</head>
<body>
<h1>Running Benchmark Suite</h1>
</body>
</html>
Loading

0 comments on commit 6bd6861

Please sign in to comment.