Code Monkey home page Code Monkey logo

js-bench's Introduction

JS Benchmark - The easy way.

This is designed to make benchmarking changes in functions easy. This is a JS port of PHP Bench.

Installation

git clone [email protected]:steveworley/js-bench.git

Usage

To run the benchmark you will need to include the JS in your markup and create a new instance of the Benchmark

<script type="text/javascript" src="Benchmark.min.js"></script>

<script type="text/javascript">
  var b = new Benchmark();
</script>

After you have created an instance you need to add functions on which to report on.

<script type="text/javascript" src="Benchmark.min.js"></script>

<script type="text/javascript">
  var bar = function() {
    var strings = ['this', 'is', 'string'], string;
    for (var i = 0; i < strings.length; i++) {
      string += strings[i] + ' ';
    }
    return string;
  }

  var baz = function() {
    var strings = ['this', 'is', 'string'];
    return strings.join(' ');
  }

  var b = new Benchmark();

  b.report('foo', 'bar');
  b.report('baz', 'baz');
  b.bench();
</script>

Expected output:

# Browser console.
IDENTIFIER    EXECUTION TIME
foo           0.9660ms
baz           0.2200ms 

Set the iterations

If you need to perform more iterations than the default (10), you can use setIterations() to set the value or you can create a benchmark object by passing in the iteration number.

<script type="text/javascript" src="Benchmark.min.js"></script>

<script type="text/javascript">
  var a = new Benchmark(100);
  var b = new Benchmark();
  b.setIterations(1000);
</script>

js-bench's People

Contributors

steveworley avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.