|
| 1 | +{-# OPTIONS -fno-warn-orphans #-} |
| 2 | +module Main (main) where |
| 3 | + |
| 4 | +import Control.DeepSeq (NFData (..)) |
| 5 | +import Control.Exception (evaluate) |
| 6 | +import Criterion.Main (bench, bgroup, defaultMain, nf) |
| 7 | + |
| 8 | +import qualified Data.Algorithm.Diff as Diff |
| 9 | + |
| 10 | +import Data.TreeDiff.List (diffBy) |
| 11 | + |
| 12 | +smallA :: [Int] |
| 13 | +smallB :: [Int] |
| 14 | + |
| 15 | +smallA = [0, 5 .. 100] |
| 16 | +smallB = [0, 3 .. 72] |
| 17 | + |
| 18 | +bigA :: [Int] |
| 19 | +bigA = [0, 5 .. 10000] |
| 20 | + |
| 21 | +bigB :: [Int] |
| 22 | +bigB = [0, 3 .. 7200] |
| 23 | + |
| 24 | +main :: IO () |
| 25 | +main = do |
| 26 | + evaluate (rnf smallA) |
| 27 | + evaluate (rnf smallB) |
| 28 | + |
| 29 | + evaluate (rnf bigA) |
| 30 | + evaluate (rnf bigB) |
| 31 | + |
| 32 | + defaultMain |
| 33 | + [ bgroup "same" |
| 34 | + [ bgroup "small" |
| 35 | + [ bench "lib" $ nf (uncurry (diffBy (==))) (smallA, smallA) |
| 36 | + , bench "Diff" $ nf (uncurry (Diff.getDiffBy (==))) (smallA, smallA) |
| 37 | + ] |
| 38 | + , bgroup "big" |
| 39 | + [ bench "lib" $ nf (uncurry (diffBy (==))) (bigA, bigA) |
| 40 | + , bench "Diff" $ nf (uncurry (Diff.getDiffBy (==))) (bigA, bigA) |
| 41 | + ] |
| 42 | + ] |
| 43 | + , bgroup "different" |
| 44 | + [ bgroup "small" |
| 45 | + [ bench "lib" $ nf (uncurry (diffBy (==))) (smallA, smallB) |
| 46 | + , bench "Diff" $ nf (uncurry (Diff.getDiffBy (==))) (smallA, smallB) |
| 47 | + ] |
| 48 | + , bgroup "big" |
| 49 | + [ bench "lib" $ nf (uncurry (diffBy (==))) (bigA, bigB) |
| 50 | + , bench "Diff" $ nf (uncurry (Diff.getDiffBy (==))) (bigA, bigB) |
| 51 | + ] |
| 52 | + ] |
| 53 | + ] |
| 54 | + |
| 55 | +------------------------------------------------------------------------------- |
| 56 | +-- Orphans |
| 57 | +------------------------------------------------------------------------------- |
| 58 | + |
| 59 | +instance (NFData a, NFData b) => NFData (Diff.PolyDiff a b) where |
| 60 | + rnf (Diff.First x) = rnf x |
| 61 | + rnf (Diff.Second y) = rnf y |
| 62 | + rnf (Diff.Both x y) = rnf x `seq` rnf y |
0 commit comments