Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hdgarrood/purescript-benchotron
Straightforward benchmarking for PureScript/JavaScript.
https://github.com/hdgarrood/purescript-benchotron
Last synced: 16 days ago
JSON representation
Straightforward benchmarking for PureScript/JavaScript.
- Host: GitHub
- URL: https://github.com/hdgarrood/purescript-benchotron
- Owner: hdgarrood
- License: mit
- Created: 2015-05-16T20:08:17.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-09-23T22:37:23.000Z (over 1 year ago)
- Last Synced: 2024-12-07T04:12:17.278Z (about 1 month ago)
- Language: PureScript
- Homepage:
- Size: 69.3 KB
- Stars: 32
- Watchers: 4
- Forks: 16
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-purescript - purescript-benchotron - Straightforward benchmarking for PureScript/JavaScript. (Testing)
README
# purescript-benchotron
[![Build Status](https://travis-ci.org/hdgarrood/purescript-benchotron.svg?branch=master)](https://travis-ci.org/hdgarrood/purescript-benchotron)
Straightforward benchmarking via [Benchmark.js][]. I am sorry about the name
(purescript-benchmark was taken).## usage
Suppose you want to find out which is faster out of `foldr (+) 0` and
`runAdditive <<< foldMap Additive`. Let's also do the same for `(*)` for good
measure. Start by creating some `Benchmark` values:```purescript
module Main whereimport Prelude
import Control.Monad.Eff (Eff)
import Data.Array ((..))
import Data.Foldable (foldMap, foldr)
import Data.Monoid.Additive (Additive(..))
import Data.Monoid.Multiplicative (Multiplicative(..))
import Data.Newtype (ala)
import Test.QuickCheck.Arbitrary (arbitrary)
import Test.QuickCheck.Gen (vectorOf)
import Benchotron.Core (Benchmark, benchFn, mkBenchmark)
import Benchotron.UI.Console (runSuite)benchSum :: Benchmark
benchSum = mkBenchmark
{ slug: "sum"
, title: "Finding the sum of an array"
, sizes: (1..5) <#> (_ * 1000)
, sizeInterpretation: "Number of elements in the array"
, inputsPerSize: 1
, gen: \n -> vectorOf n arbitrary
, functions: [ benchFn "foldr" (foldr (+) 0)
, benchFn "foldMap" (ala Additive foldMap)
]
}benchProduct :: Benchmark
benchProduct = mkBenchmark
{ slug: "product"
, title: "Finding the product of an array"
, sizes: (1..5) <#> (_ * 1000)
, sizeInterpretation: "Number of elements in the array"
, inputsPerSize: 1
, gen: \n -> vectorOf n arbitrary
, functions: [ benchFn "foldr" (foldr (*) 1)
, benchFn "foldMap" (ala Multiplicative foldMap)
]
}
main :: Effect Unit
main = runSuite [benchSum, benchProduct]
```Now, run them with `runSuite`; this will save the results data for each
benchmark to `tmp/sum.json` and `tmp/product.json` respectively.```purescript
main = runSuite [benchSum, benchProduct]
```You can now generate SVG graphs of these results by visiting
.Further information, such as the meaning of each of the fields of a
`Benchmark` value, is available in the
[documentation on Pursuit](https://pursuit.purescript.org/packages/purescript-benchotron).[Benchmark.js]: http://benchmarkjs.com