Skip to content

Prepare to V2 - #196

Draft
willbasky wants to merge 12 commits into
ghcjs865-dockerfrom
mvc
Draft

Prepare to V2#196
willbasky wants to merge 12 commits into
ghcjs865-dockerfrom
mvc

Conversation

@willbasky

@willbasky willbasky commented Jul 26, 2024

Copy link
Copy Markdown
Collaborator
  1. Follow MVC pattern
  2. Make order in common stuff

@willbasky willbasky self-assigned this Jul 26, 2024
@willbasky willbasky changed the title Mvc Prepare to V2 Jul 27, 2024
@willbasky
willbasky marked this pull request as ready for review August 7, 2024 17:31
@willbasky
willbasky marked this pull request as draft September 22, 2024 19:57
@willbasky
willbasky marked this pull request as ready for review September 23, 2024 02:04
@willbasky
willbasky marked this pull request as draft September 23, 2024 02:12
@willbasky

willbasky commented Sep 23, 2024

Copy link
Copy Markdown
Collaborator Author

Due to benchmarks of nubWith and unionWith from commit works worse than expected.
Need to revert it before merge or refactor them better.

module Main (main) where

import Criterion
import Criterion.Main (defaultMain)
import Data.List (nubBy, unionBy)
import Hedgehog (MonadGen)
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
import NubAndUnion (nubWith, unionWith)

main :: IO ()
main = nubBenchmark

nubBenchmark :: IO ()
nubBenchmark =
    defaultMain
        [ bgroup "nub" [ 
            env (Gen.sample (genListOfInt 10000 1000)) $ \input ->
                bgroup
                    "10000"
                    [ bench "nubBy" $ nf (nubBy (/=)) input
                    , bench "nubWith" $ nf (nubWith id) input
                    ] 
             ]
        , bgroup "union" [ 
            env (Gen.sample (genListOfInt2 10000 1000)) $ \x ->
                bgroup
                    "10000"
                    [ bench "unionBy" $ nf (uncurry (unionBy (/=))) x
                    , bench "unionWith" $ nf (uncurry (unionWith id)) x
                    ]
            ]
        ]

genListOfInt :: (MonadGen m) => Int -> Int -> m [Int]
genListOfInt l i = Gen.list (Range.singleton l) $ Gen.int (Range.constant 0 i)

genListOfInt2 :: (MonadGen m) => Int -> Int -> m ([Int], [Int])
genListOfInt2 l i = do 
    l1 <- Gen.list (Range.singleton l) $ Gen.int (Range.constant 0 (i+i))
    l2 <- Gen.list (Range.singleton l) $ Gen.int (Range.constant 0 i)
    pure (l1,l2)

it returns:

Benchmark tarea-benchmark: RUNNING...
benchmarking nub/10000/nubBy
time                 34.52 μs   (32.89 μs .. 35.59 μs)
                     0.991 R²   (0.988 R² .. 0.995 R²)
mean                 34.80 μs   (34.09 μs .. 35.35 μs)
std dev              2.421 μs   (1.921 μs .. 2.743 μs)
variance introduced by outliers: 71% (severely inflated)
                   
benchmarking nub/10000/nubWith
time                 839.1 μs   (823.5 μs .. 857.3 μs)
                     0.997 R²   (0.996 R² .. 0.999 R²)
mean                 828.8 μs   (821.0 μs .. 839.3 μs)
std dev              28.23 μs   (22.98 μs .. 35.66 μs)
variance introduced by outliers: 24% (moderately inflated)
                   
benchmarking union/10000/unionBy
time                 122.7 μs   (116.9 μs .. 128.3 μs)
                     0.973 R²   (0.956 R² .. 0.984 R²)
mean                 118.7 μs   (112.9 μs .. 130.5 μs)
std dev              24.94 μs   (16.11 μs .. 39.26 μs)
variance introduced by outliers: 95% (severely inflated)
                   
benchmarking union/10000/unionWith
time                 2.231 ms   (2.193 ms .. 2.277 ms)
                     0.992 R²   (0.984 R² .. 0.996 R²)
mean                 2.295 ms   (2.251 ms .. 2.350 ms)
std dev              162.9 μs   (110.5 μs .. 215.4 μs)
variance introduced by outliers: 51% (severely inflated)
                   
Benchmark tarea-benchmark: FINISH

@willbasky

Copy link
Copy Markdown
Collaborator Author

See solution here https://github.com/nh2/haskell-ordnub

@willbasky

willbasky commented Nov 22, 2024

Copy link
Copy Markdown
Collaborator Author

Well, my solution is the same by performance as haskell-ordnub. So, I guess Ord adds extra time. One has to research it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant