Code Monkey home page Code Monkey logo

purescript-benchotron's Introduction

purescript-benchotron

Build Status

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:

module Main where

import 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.

main = runSuite [benchSum, benchProduct]

You can now generate SVG graphs of these results by visiting http://harry.garrood.me/purescript-benchotron-svg-renderer.

Further information, such as the meaning of each of the fields of a Benchmark value, is available in the documentation on Pursuit.

purescript-benchotron's People

Contributors

hdgarrood avatar paf31 avatar purefunctor avatar alexmouton avatar edwardw avatar garyb avatar jordanmartinez avatar jacereda avatar kika avatar ethul avatar thimoteus avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.