Giter Site home page Giter Site logo

kata-one-beyond-2022-node's Introduction

The kata benchmarker

Why

This repo is just a proof of concept of using benchmark.js to measure the performance of different solutions to a same problem. We want to use it to create a kata challenge in our organization and let our program get the winner.

How

To add a new solution, you just have to create a node file with your name inside the folder functions. That JS file should be like:

module.exports = (misteryMessage) => {
  //...your code goes here...
}

Standalone run

To run a test function created in a standalone way, you can use index.js:

node index.js [functionName]

i.e.

node index.js test-function-2022

With this command, you'll run the file functions/test-function-2022.js

Benchmark.js run

To run the benchmarker, once all the solutions are added to the folder, just run:

node benchmark.js

With this command, you will run the benchmark for all the solutions inside the functions folder (one per file).

And you'll get stats and standings like:

@MacBoo ➜  benchmark  node index.js
betisman x 101,306 ops/sec ±0.51% (94 runs sampled)
cesar x 1,002,139 ops/sec ±2.42% (92 runs sampled)
matteo x 8,099 ops/sec ±0.50% (95 runs sampled)
Fastest is cesar
[
  { name: 'cesar', opsPerSecond: 1002139.327019037 },
  { name: 'betisman', opsPerSecond: 101306.48491351385 },
  { name: 'matteo', opsPerSecond: 8099.064104895205 }
]
┌─────────┬───────────────┬─────────────┬─────────────────────┬──────────────┬─────────────────┬─────────────────────┐
│ (index) │     name      │    mean     │ diffWithFastestMean │ opsPerSecond │ diffWithFastest │      result         │
├─────────┼───────────────┼─────────────┼─────────────────────┼──────────────┼─────────────────┼─────────────────────┤
│    0    │    'cesar''13.353 μs''1.00x''74,887.845''1.00x''this is a message' │
│    1    │   'betisman''14.131 μs''1.058x''70,765.865''1.058x''this is a message' │
│    2    │   'matteo''15.748 μs''1.179x''63,499.611''1.179x''this is a message' │
└─────────┴───────────────┴─────────────┴─────────────────────┴──────────────┴─────────────────┴─────────────────────┘

Traditional benchmark run

We have also implemented a traditional stopwatch benchmark just for fun and comparison, it can be run this way:

node traditional.js

With this command, you will run the benchmark for all the solutions inside the functions folder (one per file).

And you'll get stats and standings like:

@MacBoo ➜  benchmark  node index.js
testing betisman
testing cesar
testing matteo
Fastest is cesar
┌─────────┬───────────────┬────────────┬────────────┬─────────────────────────┬─────────┬─────────────────────┐
│ (index) │     name      │    mean    │   micro    │     diffWithFastest     │ samples │      result         │
├─────────┼───────────────┼────────────┼────────────┼─────────────────────────┼─────────┼─────────────────────┤
│    1    │  'betisman''0.002 ms''2.019 μs''11.185x - 1,018.485% ' │ 100000  │ 'this is a message' │
│    2    │    'matteo''0.002 ms''2.028 μs''11.235x - 1,023.474% ' │ 100000  │ 'this is a message' │
│    3    │    'cesar''0.002 ms''2.091 μs''11.585x - 1,058.514% ' │ 100000  │ 'this is a message' │
└─────────┴───────────────┴────────────┴────────────┴─────────────────────────┴─────────┴─────────────────────┘

Take in mind

Don't forget to run

nvm use

and

npm install

before trying to run the scripts.

The mapping from Morse to alphanumerical is:

".-"    = 'a',
"-..."  = 'b',
"-.-."  = 'c',
"-.."   = 'd',
"."     = 'e',
"..-."  = 'f',
"--."   = 'g',
"...."  = 'h',
".."    = 'i',
".---"  = 'j',
"-.-"   = 'k',
".-.."  = 'l',
"--"    = 'm',
"-."    = 'n',
"---"   = 'o',
".--."  = 'p',
"--.-"  = 'q',
".-."   = 'r',
"..."   = 's',
"-"     = 't',
"..-"   = 'u',
"...-"  = 'v',
".--"   = 'w',
"-..-"  = 'x',
"-.--"  = 'y',
"--.."  = 'z',
".----" = '1',
"..---" = '2',
"...--" = '3',
"....-" = '4',
"....." = '5',
"-...." = '6',
"--..." = '7',
"---.." = '8',
"----." = '9',
"-----" = '0',

kata-one-beyond-2022-node's People

Contributors

betisman avatar danielcolas93 avatar hamsaaldrobi avatar jgleal avatar jonatan-martinez avatar nanotower avatar xexuline avatar

Watchers

 avatar  avatar  avatar  avatar  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.