A simple and lightweight benchmark tool in native JavaScript.
LightBenchmark.js is written in native JavaScript, so it doesn't need any dependency.
Just include lightbenchmark.js or lightbenchmark.min.js in <head></head> or just before </body> (recommended).
<script src="/your-custom-path/lightbenchmark.min.js"></script>
<script src="/another-path/your-script.js"></script>
</body>Then, you can call the lightbenchmark function in different ways.
The most complete and useful way is :
var options = {name: 'name of the timer', loops: 'default'};
lightbenchmark(options, function (lbIncrement, lbOptions) {
// Your instructions.
});name must be a string. Default value : 'Default'.
loops must be a integer or a predefined string :
'low':1000loops.'default':10000loops. Default value.'high':100000loops.
You don't necessarily have to specify name or loops, but they will be replaced by default values.
You can also access some additional datas by specify them as arguments of the function you give to lightbenchmark(). You can give them the names you want :
lightbenchmark(function (lbIncrement, lbOptions) {});lbIncrement: increment variable.lbOptions: options you gave, composed oflbOptions.nameandlbOptions.loops.
So, the minimal way to call lightbenchmark() is :
lightbenchmark(function () {
// Your instructions.
});-
See testing/playground.html for some examples.
-
More the
loopsvalue is high, more the results will be precise and accurate. -
The execution time may vary depending on the computer and the browser used.
-
If you like LightBenchmark.js, please
this repository so it can easily be found and help other developers.
Thank you ! 😉
LightBenchmark.js is released under the MIT License.
