diff options
author | Joe Crayne <joe@jerkface.net> | 2019-06-14 20:11:19 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-06-14 20:18:32 -0400 |
commit | b6a8060c9b9744b421b012802b62d3250536ad9f (patch) | |
tree | a9e9f886a07dbbb47d2cffad8ba243eb742b4b6c | |
parent | bc7855492d8bdb21437c6d6b94a9c1872da45f1f (diff) |
crayne parser: add full-parse benchmark.
-rw-r--r-- | test/bench.hs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/test/bench.hs b/test/bench.hs index 3c4cf1e..a8ba239 100644 --- a/test/bench.hs +++ b/test/bench.hs | |||
@@ -23,6 +23,8 @@ import qualified Graphics.WaveFront.Parse as Parse | |||
23 | import qualified Graphics.WaveFront.Parse.Common as Parse | 23 | import qualified Graphics.WaveFront.Parse.Common as Parse |
24 | 24 | ||
25 | import Wavefront.Lex | 25 | import Wavefront.Lex |
26 | import qualified Data.Wavefront as C | ||
27 | import Wavefront as C | ||
26 | 28 | ||
27 | import Criterion.Main | 29 | import Criterion.Main |
28 | #ifdef WEIGH | 30 | #ifdef WEIGH |
@@ -39,7 +41,7 @@ cube_obj = L.fromChunks . pure . unsafePerformIO $ do | |||
39 | {-# NOINLINE cube_obj #-} | 41 | {-# NOINLINE cube_obj #-} |
40 | 42 | ||
41 | cube_objT :: Text | 43 | cube_objT :: Text |
42 | cube_objT = decodeASCII $ L.toStrict cube_obj | 44 | cube_objT = decodeUtf8 $ L.toStrict cube_obj |
43 | {-# NOINLINE cube_objT #-} | 45 | {-# NOINLINE cube_objT #-} |
44 | 46 | ||
45 | countVerticesSabadie :: Text -> Int | 47 | countVerticesSabadie :: Text -> Int |
@@ -63,6 +65,13 @@ countVerticesCrayne bs = execState (parseOBJ builder (ObjConfig IntMap.empty) bs | |||
63 | { vertex = \_ -> modify succ | 65 | { vertex = \_ -> modify succ |
64 | } | 66 | } |
65 | 67 | ||
68 | countVerticesCrayneFull :: L.ByteString -> Int | ||
69 | countVerticesCrayneFull ts = V.length vs | ||
70 | where | ||
71 | obj = C.parse ts | ||
72 | vs = C.objLocations obj | ||
73 | |||
74 | |||
66 | sabadie :: Text -> Either String WavefrontOBJ | 75 | sabadie :: Text -> Either String WavefrontOBJ |
67 | sabadie = fmap (ctxtToWavefrontOBJ . lexer) . tokenize | 76 | sabadie = fmap (ctxtToWavefrontOBJ . lexer) . tokenize |
68 | 77 | ||
@@ -78,6 +87,7 @@ main = do | |||
78 | defaultMain [ | 87 | defaultMain [ |
79 | bgroup "count vertices" | 88 | bgroup "count vertices" |
80 | [ bench "crayne" $ whnf countVerticesCrayne cube_obj | 89 | [ bench "crayne" $ whnf countVerticesCrayne cube_obj |
90 | , bench "crayneFull" $ whnf countVerticesCrayneFull cube_obj | ||
81 | , bench "sabadie" $ whnf countVerticesSabadie cube_objT | 91 | , bench "sabadie" $ whnf countVerticesSabadie cube_objT |
82 | , bench "sundqvist" $ whnf countVerticesSundqvist cube_objT | 92 | , bench "sundqvist" $ whnf countVerticesSundqvist cube_objT |
83 | ] | 93 | ] |
@@ -85,6 +95,7 @@ main = do | |||
85 | #ifdef WEIGH | 95 | #ifdef WEIGH |
86 | Weigh.mainWith $ do | 96 | Weigh.mainWith $ do |
87 | func "crayne" countVerticesCrayne cube_obj | 97 | func "crayne" countVerticesCrayne cube_obj |
98 | func "crayneFull" countVerticesCrayneFull cube_obj | ||
88 | func "sabadie" countVerticesSabadie cube_objT | 99 | func "sabadie" countVerticesSabadie cube_objT |
89 | func "sundqvist" countVerticesSundqvist cube_objT | 100 | func "sundqvist" countVerticesSundqvist cube_objT |
90 | #endif | 101 | #endif |