-
Notifications
You must be signed in to change notification settings - Fork 4
/
Space.hs
67 lines (57 loc) · 2.53 KB
/
Space.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{-# LANGUAGE BangPatterns #-}
-- | Example uses of comparing set-like data structures.
module Main where
import Control.DeepSeq
import qualified Data.BloomFilter.Easy
import qualified Data.DAWG.Packed
import qualified Data.HashSet
import qualified Data.IntSet
import qualified Data.Set
import System.Random
import Weigh
-- | Weigh sets.
main :: IO ()
main =
mainWith (do inserts
fromlists
fromlistsSProb
fromlistsS
fromlistsSMonotonic)
inserts :: Weigh ()
inserts = do func "Data.Set.insert mempty"
(`Data.Set.insert` mempty)
(1 :: Int)
func "Data.HashSet.insert mempty"
(`Data.HashSet.insert` mempty)
(1 :: Int)
func "Data.IntSet.insert mempty"
(`Data.IntSet.insert` mempty)
(1 :: Int)
fromlists :: Weigh ()
fromlists =
do let !elems =
force (take 1000000 (randoms (mkStdGen 0) :: [Int]))
func "Data.Set.fromList (1 million ints)" Data.Set.fromList elems
func "Data.HashSet.fromList (1 million ints)" Data.HashSet.fromList elems
func "Data.IntSet.fromList (1 million ints)" Data.IntSet.fromList elems
fromlistsSProb :: Weigh ()
fromlistsSProb =
do let !elems =
force (map show (take 1000000 (randoms (mkStdGen 0) :: [Int])))
func "Data.Set.fromList (1 million strings, no false positives)" Data.Set.fromList elems
func "Data.HashSet.fromList (1 million strings, no false positives)" Data.HashSet.fromList elems
func "Data.BloomFilter.Easy.easyList (1 million strings, 0.1 false positive rate)" (Data.BloomFilter.Easy.easyList 0.1) elems
fromlistsS :: Weigh ()
fromlistsS =
do let !elems =
force (map show (take 100000 (randoms (mkStdGen 0) :: [Int])))
func "Data.Set.fromList (100 thousand strings random)" Data.Set.fromList elems
func "Data.HashSet.fromList (100 thousand strings random)" Data.HashSet.fromList elems
func "Data.DAWG.Packed.fromList (100 thousand strings random)" Data.DAWG.Packed.fromList elems
fromlistsSMonotonic :: Weigh ()
fromlistsSMonotonic =
do let !elems =
force (map show [1 :: Int .. 1000000])
func "Data.Set.fromList (1 million strings monotonic)" Data.Set.fromList elems
func "Data.HashSet.fromList (1 million strings monotonic)" Data.HashSet.fromList elems
func "Data.DAWG.Packed.fromList (1 million strings monotonic)" Data.DAWG.Packed.fromList elems