requirejs try/catch

Benchmark created by ben hockey on


Preparation HTML

<script>
  var iterations = 1000,
      a,
      // simulate an AMD factory
      factory = function () {
          return {
              inc: function (it) {
                  it += 1;
              }
          };
      },
      // simulate the module as the return value from the factory
      module;
  
</script>

Setup

a = 0;
    module = null;

Test runner

Ready to run.

Testing in
TestOps/sec
try/catch
// if the module hasn't been defined
if (!module) {
    // define the module using try/catch
    try {
        module = factory();
    }
    catch (e) { }
}
var i = iterations;
// use the module
while (i--) {
    module.inc(a);
}
ready
plain
// if the module hasn't been defined
if (!module) {
    // define the module without try/catch
    module = factory();
}
var i = iterations;
// use the module
while (i--) {
    module.inc(a);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by ben hockey on