testify-benchmark

simple sync/async benchmarking

Usage no npm install needed!

<script type="module">
  import testifyBenchmark from 'https://cdn.skypack.dev/testify-benchmark';
</script>

README

Testify Benchmark

npm install testify-benchmark

Benchmark = require("../src/benchmark")

saneTimeout = (ms, fn) ->
  setTimeout(fn, ms)

async_benchmark = Benchmark.measure "asynchronousness", (bm) ->

  bm.measure "composite", (context) ->
    saneTimeout 13, ->
      context.measure "composite sync", ->
        string = ""
        for i in [1..3000]
          string += i.toString()

      context.measure "composite inner", (context) ->
        saneTimeout 8, ->
          context.finish()

async_benchmark.run {iterations: 12}, (results) ->
  for key, value of results.data
    console.log key, JSON.stringify(value.data.summarize(), null, 2)


Output:


Iteration: 1...5....10..
composite {
  "sample_size": 12,
  "mean": 24123.583333333332,
  "max": 32436,
  "median": 23347.5,
  "min": 22442,
  "stdDev": 2578.911639249308
}
composite sync {
  "sample_size": 12,
  "mean": 1012.4166666666666,
  "max": 8158,
  "median": 307,
  "min": 229,
  "stdDev": 2159.6584397512697
}
composite inner {
  "sample_size": 12,
  "mean": 8340.25,
  "max": 9304,
  "median": 8202,
  "min": 7946,
  "stdDev": 365.9925147230929
}