0.3.16 • Published 3 years ago

racepacks v0.3.16

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
3 years ago

racepacks

racepacks can reliably determine the fastest running set of instructions. racepacks will run, measure, record output and display in a human readable format the race results after performing the tests indicated.

When running with Node.js, racepacks will redirect output and errors of the code being tested to a file located in the system temporary folder i.e. '/tmp/racepacks/racepacks_20201120_25101PM' (OS dependant). If required you can further analyze the output if any.

When running in browser extra content may appear in the console.

racepacks itself runs single threaded and in order to ensure the fairness of the tests a custom rotational order is used. This means that the functions being tested are rotated in such a way that multiple runs of each test are executed and for each of these runs the order of the functions is changed. If the tests time difference obtained after running Racepacks is small or comparable, it is recommended to run it a couple of times more. This is because even if special provisions are in place Racepacks cannot ensure constant processor time for the tests. If you know how to do this please contact the author :)

racepacks has nanosecond precision when running with Node.js, and microsecond or millisecond precision when running in the browser.

Examples

The constructor is expecting a special setup object formatted as per examples below:

racepacks in Node.js

const { Racepacks } = require('racepacks')

const setup = {
  packs: {
    // racing function 'op1'
    op1: (x) => {
      // racing content
      Math.sqrt(x)
      // ...
    },

    // racing function 'op2'
    op2: (x) => {
      // racing content
      Math.sqrt(Math.sqrt(x))
      // ...
    },

    // racing function 'op3'
    op3: (x) => {
      // racing content
      Math.sqrt(Math.sqrt(Math.sqrt(x)))
      // ...
    },

    // racing function 'op4'
    op4: (x) => {
      // racing content
      Math.sqrt(Math.sqrt(Math.sqrt(Math.sqrt(x))))
      // ...
    }
  },
  tests: [1, 2, 55, 190]
}

const example1 = new Racepacks(
    // the setup object
    setup, 

    // output results per test in table format (the summary is always in table format)
    // default: true
    true, 

    // a value for 'this' when used within the functions called in 'setup'
    // default: null
    null, 

    // keep silent
    // default: false
    false)

Sample output:

` * racepacks Results * ` Nanosecond precision ( * fastest )

` * racepacks Summary * ` Nanosecond precision ( * fastest )

racepacks in browser

...
<head>
    ...
    <script src="./racepacks.bundle.js"></script>
    ...
...
    <script>
        const Racepacks = racepacksBundled.Racepacks;
        const setup = {
            packs: {
              op1: (x) => {
                Math.sqrt(x)
              },
              op2: (x) => {
                Math.sqrt(Math.sqrt(x))
              },
              op3: (x) => {
                Math.sqrt(Math.sqrt(Math.sqrt(x)))
              },
              op4: (x) => {
                Math.sqrt(Math.sqrt(Math.sqrt(Math.sqrt(x))))
              }
            },
            tests: [1, 2, 55, 190]
        };
        
        const raceResults = new Racepacks(setup)
        console.log(raceResults.podium)
    </script>
...

For more examples see 'examples' folder.

Others

racepacks itself runs single threaded and was meant to handle directly synchronous instructions only. While testing multithreading and/or async instructions might work, it's not guaranteed that the results will be accurate at this stage.

racepacks is © Copyright 2020 Nicolae Iotu, nicolae.g.iotu@gmail.com

0.3.16

3 years ago

0.3.14

3 years ago

0.2.9

3 years ago

0.1.0

3 years ago