Permalink
Browse files

add benchmark.html + benchmark.js

  • Loading branch information...
1 parent 6564c28 commit 6bd6861232321bb8a3cd20992f9e97312a7da575 @fat committed Nov 28, 2011
Showing with 2,977 additions and 0 deletions.
  1. +163 −0 tests/benchmark.html
  2. +2,814 −0 tests/benchmark.js
View
@@ -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 )'
@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).

@fat

fat Dec 5, 2011

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>
Oops, something went wrong.

0 comments on commit 6bd6861

Please sign in to comment.