DEV Community

Ayoub Touba
Ayoub Touba

Posted on • Updated on

Release new Library to measure & compare your Code!!

Hello Guys, I hope All of you doing well.

Sometimes we want to measure our code to check how much time it took to work, Moreover, after improving the code we'd like to check if it works more efficiently than the older version, Or for academic purpose we want to compare algorithms to check the time complexity on a chart, For that reason I Present you YubaPerf

How To install it

npm i @youba/yubaperf
# OR
yarn add @youba/yubaperf
Enter fullscreen mode Exit fullscreen mode

How to use it

Measuring your code:

To measure your code, you need to use these functions:

Perf.start("Algorithm1");
//The code you want to measure
Perf.end("Algorithm1");
console.log(perf.result("Algorithm1"));
Enter fullscreen mode Exit fullscreen mode

Comparing Sync functions:

The concept here is to pass one or more than function with multiple args to measure and compare between them,

You simply need:

Perfom.setfuncsToCompareSync([addUpToFirst, addUpToSecond], args);
Perfom.generateChart(); // the chart located on perf/index.html file
Enter fullscreen mode Exit fullscreen mode

Passing Array of functions & Another one for arguments .the arguments may be a simple Array like :
[1,10,1000,1000,122] Or dimensional one for Functions who has more than input like [['yes',19],['yes',1900],['yes',19999]]

The Chart:
Chart

What's next

The lib is on development,the next version will have more features like:

  • Comparing async functions
  • setfuncsToCompareSync Return an object of the result
  • ...

For more information on the library you can check the repo HERE

Top comments (0)