Benchmarker Benchmark.js front-end

Version

use the source, young padawan!

Synopsis


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Benchmark</title>
    <script type="text/javascript" src="benchmarker.js"></script>
    <script type="text/javascript">
      new Benchmarker(
        {
          // functions to be benchmarked
          // - will be generated using the "setup" block
        },
        {
          // Benchmark options
          iterations:   -2,
          nATime:       1000,
          cooldown:     50,
          runCaps:      4000,
          responders:   'HTMLish',

          // Benchmarker options
          summary:      'my funky benchmark',
          scripts:      [ 'http://www.example.com/js/test.js',
                         'http://www.example.com/js/test2.js' ],
          css:          [ 'http://www.example.com/css/bm.css' ],
          edit:         true,   // expand benchmark editor mode
          editOptions:  false,  // don't expand benchmark options
          editHandlers: false,  // don't expand benchmark handlers
          parallel:     true,   // run methodSets in parallel
          setup: function() {   // setup code
            methodSets = [
              {
                name: 'ack/nack',
                methods: {
                  ack: function() { return true; },
                  nak: function() { return false; },
                }
              },
              {
                name: 'loops',
                methods: {
                    for_loop: function() { for (var i = 0; i != 10; i++); },
                  while_loop: function() { var i = -1; while (++i != 10); },
                }
              }
            ];
          }
        }
      );
    </script>
  </head>
  <body>
  </body>
</html>

Examples

Benchmark Creator
basic Benchmarker demo
String#split
using the setup code block
String#camelize
using methods generator
loops
using methodSets generator
DOM query
Benchmarker options show-off ;-)
Gallery:
(various Benchmarks, useful - to us - at some point in time)

Description

This gadget's goal is to be an easy-to-deploy helper for JavaScript Benchmarks.

Benchmarker modifies some default Benchmark options:

Groups

Benchmarker can create multiple Benchmark objects. Each such object will be used for benchmarking a group of functions.

All methods added through the meanings of the interactive "add method" gadget will be added to the group named "default".

In order to create additional groups, for the moment you will have to use the setup block in order to populate the methodSets array.

methodSets

This is a special "global" variable used to generate Benchmarker groups. It's structure should look like this:


set1 = {
  name: 'Methods Set Name',
  methods: { // functions to be benchmarked
    // name: code
      'ack': function() { return true; },
      'nak': function() { return false; },
  }
};
methodSets = [ set1, set2, set3, set4 ... ];

Work in Progress

AFAICT, this module will always be in a work in progress status.

Check the ToDo section for more info.

Options

No option is compulsory. The currently used options are:

scripts {Array} [[]]
load this list of scripts
css {Array} [[]]
load this list of stylesheets
summary {String} ['']
brief benchmark description
description {String} ['']
benchmark description
edit {Boolean} [false]
expand benchmark editor on page load
editOptions {Boolean} [true]
expand benchmark options when editing
editHandlers {Boolean} [false]
expand benchmark handlers when editing
parallel {Boolean} [false]
run multiple benchmarks in "parallel"
setup {Function} [function(){}]
This block is evaluated in "global" context, before any Benchmark object is even created (when you click "run benchmark")

These "global" variables have a special meaning:

  • methods // {Object} [{}] - use it to programmatically populate Benchmark's methods parameter (they are added to the group named "auto");
  • methodSets // {Array} [[]] - use it to programatically create multiple method groups.

Dependencies

Incompatibilities

None reported.

Bugs and Limitations

No bugs have been reported.

To Do

See Also

Credits

There are way too many to be credited here as I used lots of sources of inspiration for baking these toys.

Thank you all and my apologies for those missing from this enumeration.

Authors

Marius Feraru, <altblue@n0i.net>.

License and Copyright

© 2006-2007 Marius Feraru <altblue@n0i.net>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Disclaimer of Warranty

Because this software is licensed free of charge, there is no warranty for the software, to the extent permitted by applicable law. Except when otherwise stated in writing the copyright holders and/or other parties provide the software "as is" without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the software is with you. should the software prove defective, you assume the cost of all necessary servicing, repair, or correction.

In no event unless required by applicable law or agreed to in writing will any copyright holder, or any other party who may modify and/or redistribute the software as permitted by the above license, be liable to you for damages, including any general, special, incidental, or consequential damages arising out of the use or inability to use the software (including but not limited to loss of data or data being rendered inaccurate or losses sustained by you or third parties or a failure of the software to operate with any other software), even if such holder or other party has been advised of the possibility of such damages.