1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00
semantic/bench/Main.hs

30 lines
1.2 KiB
Haskell
Raw Normal View History

{-# LANGUAGE DeriveAnyClass, DeriveGeneric, FlexibleInstances, StandaloneDeriving #-}
2016-06-06 22:32:16 +03:00
{-# OPTIONS_GHC -fno-warn-orphans #-}
2016-05-31 16:23:43 +03:00
module Main where
2016-05-31 16:27:00 +03:00
import Criterion.Main
import Data.String
2016-06-06 22:32:16 +03:00
import Patch
2016-05-31 16:27:00 +03:00
import Prologue
import Test.QuickCheck hiding (Fixed)
2016-05-31 16:27:00 +03:00
main :: IO ()
2016-05-31 17:53:23 +03:00
main = do
benchmarks <- sequenceA []
2016-05-31 17:53:23 +03:00
defaultMain benchmarks
2016-06-06 22:32:16 +03:00
instance NFData a => NFData (Patch a)
2016-05-31 18:47:56 +03:00
-- | Defines a named group of n benchmarks over inputs generated by an `Arbitrary` instance.
-- |
-- | The inputs sizes at each iteration are measured by a metric function, which gives the name of the benchmark. This makes it convenient to correlate a benchmark of some function over lists with e.g. input `length`.
generativeBenchmark :: (Arbitrary a, Show m, Ord m) => String -> Int -> (a -> m) -> (a -> Benchmarkable) -> IO Benchmark
2016-05-31 18:45:17 +03:00
generativeBenchmark name n metric benchmark = do
benchmarks <- traverse measure (replicate n defaultSize)
pure $! bgroup name (snd <$> (sortOn fst benchmarks))
where measure n = do
input <- generate (resize n arbitrary)
let measurement = metric input
pure $! (measurement, bench (show measurement) (benchmark input))
defaultSize = 100