1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00
semantic/bench/Main.hs

68 lines
2.2 KiB
Haskell
Raw Normal View History

{-# LANGUAGE DeriveAnyClass, FlexibleInstances #-}
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 Arguments
2016-05-31 16:27:00 +03:00
import Criterion.Main
2016-06-06 22:32:38 +03:00
import Data.Function
import Data.List (genericLength)
import Data.String
2016-06-06 22:32:16 +03:00
import Patch
2016-05-31 16:27:00 +03:00
import Prologue
2016-10-06 02:17:46 +03:00
import qualified Renderer as R
import SemanticDiff (fetchDiffs)
2016-10-06 02:17:46 +03:00
import qualified SemanticDiffPar
import SES
2016-10-06 02:17:46 +03:00
import System.Directory (makeAbsolute)
2016-05-31 16:27:00 +03:00
main :: IO ()
2017-01-10 22:46:07 +03:00
main = defaultMain
[ bgroup "ses"
[ bench "0,0" (nf (uncurry benchmarkSES) ([], []))
, bench "1,1, =" (nf (uncurry benchmarkSES) ([lower], [lower]))
, bench "1,1, ≠" (nf (uncurry benchmarkSES) ([lower], [upper]))
, bench "10,10, =" (nf (uncurry benchmarkSES) (replicate 10 lower, replicate 10 lower))
, bench "10,10, ≠" (nf (uncurry benchmarkSES) (replicate 10 lower, replicate 10 upper))
, bench "100,100, =" (nf (uncurry benchmarkSES) (replicate 100 lower, replicate 100 lower))
, bench "100,100, ≠" (nf (uncurry benchmarkSES) (replicate 100 lower, replicate 100 upper))
]
, syncAsyncBenchmark
]
where lower = ['a'..'z']
upper = ['A'..'Z']
2016-06-07 00:16:52 +03:00
benchmarkSES :: [String] -> [String] -> [Either String (Patch String)]
benchmarkSES = ses compare cost
2016-06-06 22:32:38 +03:00
where compare a b = if a == b then Just (Left a) else Nothing
cost = either (const 0) (sum . fmap genericLength)
2016-06-06 22:32:38 +03:00
2016-06-06 22:32:16 +03:00
instance NFData a => NFData (Patch a)
2016-10-06 02:17:46 +03:00
syncAsyncBenchmark :: Benchmark
syncAsyncBenchmark =
bgroup "async vs par" [
bench "async" . whnfIO $ SemanticDiff.fetchDiffs =<< theArgs,
bench "par" . whnfIO $ SemanticDiffPar.fetchDiffs =<< theArgs
]
theArgs :: IO Arguments
theArgs = do
jqueryPath <- makeAbsolute "test/repos/jquery"
pure $ args jqueryPath sha1 sha2 files R.Patch
where
sha1 = "70526981916945dc4093e116a3de61b1777d4718"
sha2 = "e5ffcb0838c894e26f4ff32dfec162cf624d8d7d"
files = [
"src/manipulation/getAll.js",
"src/manipulation/support.js",
"src/manipulation/wrapMap.js",
"src/offset.js",
"test/unit/css.js",
"test/unit/deferred.js",
"test/unit/deprecated.js",
"test/unit/effects.js",
"test/unit/event.js",
"test/unit/offset.js",
"test/unit/wrap.js"
]