diff --git a/.gitignore b/.gitignore index 70ba25f..246b2d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.log -copy-test.txt +node_modules/ .vagrant/ diff --git a/dev/benchmark-report.js b/dev/benchmark-report.js new file mode 100644 index 0000000..6e25142 --- /dev/null +++ b/dev/benchmark-report.js @@ -0,0 +1,28 @@ +const fs = require('fs') +const path = require('path') +const { promisify } = require('util') + +const chunk = require('lodash.chunk') + +const readFile = promisify(fs.readFile) + +const extractTimestamp = line => Number(line.match(/\d+$/)[0]) + +const avg = list => list.reduce((value, item) => value += item, 0) / list.length + +async function main () { + const lines = (await readFile(path.resolve(__dirname, '../benchmark.log'))).toString().split('\n') + + lines.pop() + + const times = chunk(lines, 2).map(([start, end]) => { + return extractTimestamp(end) - extractTimestamp(start) + }); + + console.log(`samples:\t${times.length}`); + console.log(`avg:\t\t${avg(times)}\tms`); + console.log(`best:\t\t${Math.min(...times)}\tms`); + console.log(`worst:\t\t${Math.max(...times)}\tms`); +} + +main() diff --git a/dev/package.json b/dev/package.json new file mode 100644 index 0000000..0917d42 --- /dev/null +++ b/dev/package.json @@ -0,0 +1,12 @@ +{ + "name": "tmux-fingers-dev-stuff", + "version": "0.0.1", + "description": "tools to develop tmux-fingers shite", + "main": "index.js", + "repository": "https://github.com/morantron/tmux-fingers", + "author": "Morantron", + "license": "MIT", + "dependencies": { + "lodash.chunk": "^4.2.0" + } +} diff --git a/dev/yarn.lock b/dev/yarn.lock new file mode 100644 index 0000000..2384430 --- /dev/null +++ b/dev/yarn.lock @@ -0,0 +1,8 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +lodash.chunk@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/lodash.chunk/-/lodash.chunk-4.2.0.tgz#66e5ce1f76ed27b4303d8c6512e8d1216e8106bc" + integrity sha1-ZuXOH3btJ7QwPYxlEujRIW6BBrw= diff --git a/test/benchmark.sh b/test/benchmark.sh index 2dbb59c..c5443af 100755 --- a/test/benchmark.sh +++ b/test/benchmark.sh @@ -12,6 +12,8 @@ function snippet_for { echo "echo \"\$(cat /tmp/benchmark-execution-id) $1 \$((\$(date +%s%N)/1000000))\" >> ~/shared/benchmark.log" } +SAMPLES=${SAMPLES:=50} + function setup_benchmark_repo() { echo "Setting up benchmark repo ..." rm -rf "$benchmark_repo_path" @@ -33,10 +35,14 @@ if [[ "$target" == "within-vm" ]]; then setup_benchmark_repo set_execution_id + cat /dev/null > ~/shared/benchmark.log + + echo "Will run benchmark $SAMPLES times" + pushd "$benchmark_repo_path" &> /dev/null for benchmark in $(ls $benchmark_repo_path/test/benchmarks/*.sh); do - for i in {1..50}; do + for i in $(seq 1 "$SAMPLES"); do echo "* Running $benchmark [ $i ]" sleep 1 $benchmark @@ -46,5 +52,6 @@ if [[ "$target" == "within-vm" ]]; then elif [[ -z "$target" ]]; then echo "Running benchmarks" vagrant up "$target" &>> /dev/null - vagrant ssh "$target" -c "cd shared && ./test/benchmark.sh within-vm" 2> /dev/null + vagrant ssh "$target" -c "cd shared && SAMPLES=$SAMPLES ./test/benchmark.sh within-vm" 2> /dev/null + node dev/benchmark-report.js fi