on master help sign in
Get rid of obsolete benchmarking code.

--HG-- extra : convert_revision : e0ff42892aad44b2374ca4624271ff94bbc71812

commit4efa82ce9a3c334b61b605675ce715ea065cab40 authorBryan O'Sullivan <bos@serpentine.com> dateWed 2 Dec 2009, 18:40 (17 years ago) parent40f5e1b
4 files changed−409
tests/Bench.hs−171 tests/BenchUtils.hs−79 tests/EncodingBench.hs−106 tests/FusionBench.hs−53
tests/Bench.hsdeleted−171
@@ -1,171 +0,0 @@
1−import BenchUtils
2−import System.Mem
3−import Control.Concurrent
4−import Data.Char
5−import System.CPUTime
6−import System.IO
7−import System.IO.Unsafe
8−import Text.Printf
9−import Control.Exception
10−
11−import qualified Data.Text as T
12−import qualified Data.Text.Encoding as E
13−import Data.Text.Internal
14−import qualified Data.Text.Fusion as S
15−
16−import qualified Data.List as L
17−import qualified Data.ByteString.Char8 as B
18−import qualified Data.ByteString as B8
19−import Data.ByteString (ByteString)
20−import Data.Word
21−import qualified System.IO.UTF8 as UTF8
22−
23−main = do ascii_bs <- B.readFile "text/test/ascii.txt"
24− let ascii_txt = E.decodeASCII ascii_bs
25− let ascii_str = T.unpack ascii_txt
26− force (ascii_txt,ascii_str,ascii_bs)
27− printf " # Text\t\tString\tByteString\n"
28− run 1 (ascii_txt,ascii_str,ascii_bs) ascii_tests
29−
30−
31−ascii_tests = [
32− ("cons",
33− [F (app1 (T.cons '\88')),
34− F (app2 ((:) '\88') ),
35− F (app3 (B8.cons 88) )]),
36− ("head",
37− [F (app1 T.head),
38− F (app2 L.head),
39− F (app3 B.head)]),
40− ("last",
41− [F (app1 T.last),
42− F (app2 L.last),
43− F (app3 B.last)]),
44− ("tail",
45− [F (app1 T.tail),
46− F (app2 L.tail),
47− F (app3 B.tail)]),
48− ("init",
49− [F (app1 T.init),
50− Flist (app2 L.init),
51− F (app3 B.init) ]),
52− ("null",
53− [F (app1 T.null),
54− F (app2 L.null),
55− F (app3 B.null) ]),
56− ("length",
57− [F (app1 T.length),
58− F (app2 L.length),
59− F (app3 B.length)]),
60− ("map",
61− [F (app1 $ T.map succ),
62− Flist (app2 (L.map succ)),
63− F (app3 $ B.map succ)]),
64− ("filter",
65− [F $ app1 $ T.filter (/= '\101'),
66− Flist $ app2 $ L.filter (/= '\101'),
67− F $ app3 $ B8.filter (/= 101)]),
68− ("foldl'",
69− [F (app1 $ T.foldl' (\a w -> a+1::Int) 0),
70− F (app2 $ L.foldl' (\a w -> a+1::Int) 0),
71− F (app3 $ B.foldl' (\a w -> a+1::Int) 0)
72− ]),
73− ("drop",
74− [F (app1 $ T.drop 30000000),
75− Flist (app2 $ L.drop 30000000),
76− F (app3 $ B.drop 30000000)
77− ]),
78− ("take",
79− [F (app1 $ T.take 30000000),
80− Flist (app2 $ L.take 30000000),
81− F (app3 $ B.take 30000000)]),
82− ("words",
83− [F (app1 $ T.words),
84− Flist (app2 $ L.words),
85− F (app3 $ B.words)])
86− ]
87−
88−bmp_tests = [
89− ("cons",
90− [F (app1 (T.cons '\88')),
91− F (app2 ((:) '\88') )]),
92− ("head",
93− [F (app1 T.head),
94− F (app2 L.head)]),
95− ("last",
96− [F (app1 T.last),
97− F (app2 L.last)]),
98− ("tail",
99− [F (app1 T.tail),
100− F (app2 L.tail)]),
101− ("init",
102− [F (app1 T.init),
103− Flist (app2 L.init)]),
104− ("null",
105− [F (app1 T.null),
106− F (app2 L.null),
107− F (app3 B.null)]),
108− ("length",
109− [F (app1 T.length),
110− F (app2 L.length),
111− F (app3 B.length)]),
112− ("map",
113− [F (app1 $ T.map succ),
114− Flist (app2 (L.map succ))]),
115− ("filter",
116− [F $ app1 $ T.filter (/= '\101'),
117− Flist $ app2 $ L.filter (/= '\101')]),
118− ("foldl'",
119− [F (app1 $ T.foldl' (\a w -> a+1::Int) 0),
120− F (app2 $ L.foldl' (\a w -> a+1::Int) 0)]),
121− ("drop",
122− [F (app1 $ T.drop 30000000),
123− Flist (app2 $ L.drop 30000000)]),
124− ("take",
125− [F (app1 $ T.take 30000000),
126− Flist (app2 $ L.take 30000000)]),
127− ("words",
128− [F (app1 $ T.words),
129− Flist (app2 $ L.words)])
130− ]
131−
132−smp_sip_tests = [
133− ("cons",
134− [F (app1 (T.cons '\65624')),
135− F (app2 ((:) '\65624'))]),
136− ("head",
137− [F (app1 T.head),
138− F (app2 L.head)]),
139− ("last",
140− [F (app1 T.last),
141− F (app2 L.last)]),
142− ("tail",
143− [F (app1 T.tail),
144− F (app2 L.tail)]),
145− ("init",
146− [F (app1 T.init),
147− Flist (app2 L.init)]),
148− ("null",
149− [F (app1 T.null),
150− F (app2 L.null),
151− F (app3 B.null) ]),
152− ("length",
153− [F (app1 T.length ),
154− F (app2 L.length),
155− F (app3 B.length)]),
156− ("map",
157− [F (app1 $ T.map succ),
158− Flist (app2 (L.map succ))]),
159− ("filter",
160− [F $ app1 $ T.filter (/= '\65624'),
161− Flist $ app2 $ L.filter (/= '\65624')]),
162− ("foldl'",
163− [F (app1 $ T.foldl' (\a w -> a+1::Int) 0),
164− F (app2 $ L.foldl' (\a w -> a+1::Int) 0)]),
165− ("drop",
166− [F (app1 $ T.drop 30000000),
167− Flist (app2 $ L.drop 30000000)]),
168− ("take",
169− [F (app1 $ T.take 30000000),
170− Flist (app2 $ L.take 30000000)])
171− ]
tests/BenchUtils.hsdeleted−79
@@ -1,79 +0,0 @@
1−{-# LANGUAGE ExistentialQuantification #-}
2−module BenchUtils where
3−
4−import qualified Data.List as L
5−import Data.ByteString (ByteString(..))
6−import Data.Word
7−import Text.Printf
8−import System.IO
9−import Data.Text.Internal (Text(..))
10−import System.Mem
11−import System.CPUTime
12−import Control.Exception
13−import Control.Concurrent
14−
15−data Result = T | B
16−
17−data F a = forall b. F (a -> b) | forall b. Flist (a -> [b])
18−
19−class Forceable a where
20− force :: a -> IO Result
21− force v = v `seq` return T
22−
23−instance Forceable Text
24−
25−seqList = L.foldl' (flip seq) (return ())
26−instance Forceable [a] where
27− force = L.foldl' (flip seq) (return T)
28−
29−instance Forceable ByteString
30−instance Forceable Char
31−instance Forceable Bool
32−instance Forceable Int
33−instance Forceable Word8
34−
35−instance (Forceable a, Forceable b) => Forceable (a,b) where
36− force (a,b) = force a >> force b
37−
38−instance (Forceable a, Forceable b, Forceable c) => Forceable (a,b,c) where
39− force (a,b,c) = force a >> force b >> force c
40−
41−run c x tests = sequence_ $ zipWith (runTest c x) [1..] tests
42−
43−runTest :: Int -> a -> Int -> (String,[F a]) -> IO ()
44−runTest count x n (name,tests) = do
45− printf "%2d " n
46− fn tests
47− printf "\t# %-16s\n" (show name)
48− hFlush stdout
49− where fn xs = case xs of
50− [f,g,h] -> runN count f x >> putStr "\t"
51− >> runN count g x >> putStr "\t"
52− >> runN count h x >> putStr "\t"
53− [f,g] -> runN count f x >> putStr "\t"
54− >> runN count g x >> putStr "\t\t"
55− [f] -> runN count f x >> putStr "\t\t\t"
56− _ -> return ()
57− run f x = performGC >> threadDelay 100 >> time f x
58− runN 0 f x = return ()
59− runN c f x = run f x >> runN (c-1) f x
60−
61−time (Flist f) a = do
62− start <- getCPUTime
63− v <- seqList (f a)
64− end <- getCPUTime
65− let diff = (fromIntegral (end - start)) / 10^12
66− printf "%0.3f" (diff :: Double)
67− hFlush stdout
68−
69−time (F f) a = do
70− start <- getCPUTime
71− v <- evaluate (f a)
72− end <- getCPUTime
73− let diff = (fromIntegral (end - start)) / 10^12
74− printf "%0.3f" (diff :: Double)
75− hFlush stdout
76−
77−app1 f (x,y,z) = f x
78−app2 f (x,y,z) = f y
79−app3 f (x,y,z) = f z
tests/EncodingBench.hsdeleted−106
@@ -1,106 +0,0 @@
1−{-# LANGUAGE ExistentialQuantification #-}
2−
3−import BenchUtils
4−import qualified Data.Text.Utf8.Fusion as U8
5−import qualified Data.Text.Utf8.Internal as U8I
6−import qualified Data.Text.Utf32.Fusion as U32
7−import qualified Data.Text.Utf32.Internal as U32I
8−import qualified Data.Text.Fusion as S
9−import Data.Text.Fusion (bsStream,Encoding(..))
10−import qualified Data.Text as T
11−import qualified Data.ByteString as B
12−import Text.Printf
13−import System.Mem
14−
15−instance Forceable U32I.Text
16−instance Forceable U8I.Text
17−
18−data E a = forall b. E (a -> b) | EText (a -> S.Stream Char)
19−
20−main = do force (ascii_tests, smp_sip_tests)
21− ascii <- B.readFile "ascii.txt"
22− let ascii8 = U8.unstream (bsStream ascii ASCII)
23− let ascii16 = S.unstream (bsStream ascii ASCII)
24− let ascii32 = U32.unstream (bsStream ascii ASCII)
25− force (ascii8, ascii16, ascii32)
26− printf " # Utf8\t\tUtf16\tUtf32\n"
27− run 1 (ascii8, ascii16, ascii32) ascii_tests
28− performGC
29− bmp <- B.readFile "bmp.txt"
30− let bmp8 = U8.unstream (bsStream bmp Utf8)
31− let bmp16 = S.unstream (bsStream bmp Utf8)
32− let bmp32 = U32.unstream (bsStream bmp Utf8)
33− force (bmp8, bmp16, bmp32)
34− printf " # Utf8\t\tUtf16\tUtf32\n"
35− run 1 (bmp8, bmp16, bmp32) ascii_tests
36− performGC
37− smp_sip <- B.readFile "smp_sip.txt"
38− let smp_sip8 = U8.unstream (bsStream smp_sip Utf8)
39− let smp_sip16 = S.unstream (bsStream smp_sip Utf8)
40− let smp_sip32 = U32.unstream (bsStream smp_sip Utf8)
41− force (smp_sip8, smp_sip16, smp_sip32)
42− printf " # Utf8\t\tUtf16\tUtf32\n"
43− run 1 (smp_sip8, smp_sip16, smp_sip32) smp_sip_tests
44−
45−ascii_tests = [
46− ("cons" ,
47− [F $ app1 $ U8.unstream . S.cons '\88' . U8.stream,
48− F $ app2 $ S.unstream . S.cons '\88' . S.stream,
49− F $ app3 $ U32.unstream . S.cons '\88' . U32.stream]),
50− ("length",
51− [F $ app1 $ S.length . U8.stream,
52− F $ app2 $ S.length . S.stream,
53− F $ app3 $ S.length . U32.stream]),
54− ("map" ,
55− [F $ app1 $ U8.unstream . S.map succ . U8.stream,
56− F $ app2 $ S.unstream . S.map succ . S.stream,
57− F $ app3 $ U32.unstream . S.map succ . U32.stream]),
58− ("filter",
59− [F $ app1 $ U8.unstream . S.filter (/= '\101') . U8.stream,
60− F $ app2 $ S.unstream . S.filter (/= '\101') . S.stream,
61− F $ app3 $ U32.unstream . S.filter (/= '\101') . U32.stream]),
62− ("take",
63− [F $ app1 $ U8.unstream . S.take 1000000 . U8.stream,
64− F $ app2 $ S.unstream . S.take 1000000 . S.stream,
65− F $ app3 $ U32.unstream . S.take 1000000 . U32.stream]),
66− ("drop" ,
67− [F $ app1 $ U8.unstream . S.drop 1000000 . U8.stream,
68− F $ app2 $ S.unstream . S.drop 1000000 . S.stream,
69− F $ app3 $ U32.unstream . S.drop 1000000 . U32.stream]),
70− ("foldl'",
71− [F $ app1 $ S.foldl' (\a w -> a+1::Int) 0 . U8.stream,
72− F $ app2 $ S.foldl' (\a w -> a+1::Int) 0 . S.stream,
73− F $ app3 $ S.foldl' (\a w -> a+1::Int) 0 . U32.stream
74− ])
75− ]
76−
77−smp_sip_tests = [
78− ("cons" ,
79− [F $ app1 $ U8.unstream . S.cons '\88' . U8.stream,
80− F $ app2 $ S.unstream . S.cons '\88' . S.stream,
81− F $ app3 $ U32.unstream . S.cons '\88' . U32.stream]),
82− ("length",
83− [F $ app1 $ S.length . U8.stream,
84− F $ app2 $ S.length . S.stream,
85− F $ app3 $ S.length . U32.stream]),
86− ("map" ,
87− [F $ app1 $ U8.unstream . S.map succ . U8.stream,
88− F $ app2 $ S.unstream . S.map succ . S.stream,
89− F $ app3 $ U32.unstream . S.map succ . U32.stream]),
90− ("filter",
91− [F $ app1 $ U8.unstream . S.filter (/= '\101') . U8.stream,
92− F $ app2 $ S.unstream . S.filter (/= '\101') . S.stream,
93− F $ app3 $ U32.unstream . S.filter (/= '\101') . U32.stream]),
94− ("take",
95− [F $ app1 $ U8.unstream . S.take 1000000 . U8.stream,
96− F $ app2 $ S.unstream . S.take 1000000 . S.stream,
97− F $ app3 $ U32.unstream . S.take 1000000 . U32.stream]),
98− ("drop" ,
99− [F $ app1 $ U8.unstream . S.drop 1000000 . U8.stream,
100− F $ app2 $ S.unstream . S.drop 1000000 . S.stream,
101− F $ app3 $ U32.unstream . S.drop 1000000 . U32.stream]),
102− ("foldl'",
103− [F $ app1 $ S.foldl' (\a w -> a+1::Int) 0 . U8.stream,
104− F $ app2 $ S.foldl' (\a w -> a+1::Int) 0 . S.stream,
105− F $ app3 $ S.foldl' (\a w -> a+1::Int) 0 . U32.stream])
106− ]
tests/FusionBench.hsdeleted−53
@@ -1,53 +0,0 @@
1−import Prelude hiding (zip,zip3)
2−
3−import BenchUtils
4−import Data.Char
5−import qualified Data.List as L
6−import qualified Data.ByteString as B
7−import qualified Data.Text as T
8−import Data.Text.Fusion (Encoding(..))
9−import qualified Data.Text.Fusion as S
10−import Text.Printf
11−import System.IO
12−import System.Mem
13−import qualified System.IO.UTF8 as UTF8
14−
15−main = do ascii_str <- readFile "ascii.txt"
16− ascii_bs <- B.readFile "ascii.txt"
17− let ascii_txt = T.decode ASCII ascii_bs
18− force (ascii_txt,ascii_str,ascii_bs)
19− printf " # Text\t\tString\tByteString\n"
20− run 1 (ascii_txt,ascii_str,ascii_bs) ascii_tests
21−
22−trd (a,b,c) = c
23−
24−ascii_tests = [
25− ("map/map",
26− [F $ T.map pred . T.map succ . fst,
27− Flist $ L.map pred . L.map succ . snd,
28− F $ B.map pred . B.map succ . trd]),
29− ("filter/filter",
30− [F $ T.filter (/= '\101') . T.filter (/= '\102') . fst,
31− Flist $ L.filter (/= '\101') . L.filter (/= '\102') . snd,
32− F $ B.filter (/= 101) . B.filter (/= 102) . trd]),
33− ("filter/map",
34− [F $ T.filter (/= '\103') . T.map succ . fst,
35− Flist $ L.filter (/= '\103') . L.map succ . snd,
36− F $ B.filter (/= 103) . B.map succ . trd]),
37− ("map/filter",
38− [F $ T.map succ . T.filter (/= '\104') . fst,
39− Flist $ L.map succ . L.filter (/= '\104') . snd,
40− F $ B.map succ . B.filter (/= 104) . trd]),
41− ("foldl'/map",
42− [F $ T.foldl' (const . (+1)) (0 :: Int) . T.map succ . fst,
43− F $ L.foldl' (const . (+1)) (0 :: Int) . L.map succ . snd,
44− F $ B.foldl' (const . (+1)) (0 :: Int) . B.map succ . trd]),
45− ("foldl'/filter",
46− [F $ T.foldl' (const . (+2)) (0::Int) . T.filter (/= '\105') . fst,
47− F $ L.foldl' (const . (+2)) (0::Int) . L.filter (/= '\105') . snd,
48− F $ B.foldl' (const . (+2)) (0::Int) . B.filter (/= 105) . trd]),
49− ("foldl'/map/filter",
50− [F $ T.foldl' (const.(+3)) (0::Int) . T.map succ . T.filter (/='\110') . fst,
51− F $ L.foldl' (const.(+3)) (0::Int) . L.map succ . L.filter (/='\110') . snd,
52− F $ B.foldl' (const . (+3)) (0::Int) . B.map succ . B.filter (/= 110) . trd])
53− ]