Skip to content

Compare the speed between your potential solutions. Repeatedly runs a command to accurately gauge the elapsed time.

License

Notifications You must be signed in to change notification settings

bpm-rocks/bench

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BPM Library: Bench

Run a function repeatedly in order to gauge its performance. Compare the results against other functions.

Installation

Add to your bpm.ini file the following development dependency. It is unlikely that you will rely on this library for non-development systems.

[devDependencies]
bench=*

Run bpm install to add the library. Finally, use it in your testing scripts.

#!/usr/bin/env bash
. bpm
bpm::include bench

# Add tests here
bench::test::a-descriptive-name-here() {
    # Do something
    ls some-file &> /dev/null
}

# Trigger all of the bench test functions that have been loaded.
bench::auto

API

bench::auto()

Automatically benchmark functions that start with bench::test::* and writes the results to stdout.

Examples

 bench::test::echo-nothing() {
     echo -n ""
 }
 bench::auto

Returns nothing, even if there are no functions to test.

bench::test()

Benchmark shell functions or commands, running them repeatedly until an accurate measurement of their execution time is available.

  • $1 - Name of variable to get the results. This is an array with the amount of seconds (floating point) as the first value and the operations per second (another floating point number) as the second element in the array.
  • $2-@ - The command to run. This can be an alias, function, or another shell command.

Examples

# Determining which one is faster.
method1() {
    if [[ -f some-file ]]; then
        return 1
    fi
    return 0
}
method2() {
    [[ ! -f some-file ]]
}
bench::test result method1
echo "Method 1: ${result[0]} seconds, ${result[1]} op/sec"
bench::test result method2
echo "Method 2: ${result[0]} seconds, ${result[1]} op/sec"

Returns nothing. Even if the function returns errors, this continues to trudge on and will ignore the return code of the function being called.

License

This project is placed under an MIT License.

About

Compare the speed between your potential solutions. Repeatedly runs a command to accurately gauge the elapsed time.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages