summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-06-14 20:11:19 -0400
committerJoe Crayne <joe@jerkface.net>2019-06-14 20:18:32 -0400
commitb6a8060c9b9744b421b012802b62d3250536ad9f (patch)
treea9e9f886a07dbbb47d2cffad8ba243eb742b4b6c
parentbc7855492d8bdb21437c6d6b94a9c1872da45f1f (diff)
crayne parser: add full-parse benchmark.
-rw-r--r--test/bench.hs13
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
23import qualified Graphics.WaveFront.Parse.Common as Parse 23import qualified Graphics.WaveFront.Parse.Common as Parse
24 24
25import Wavefront.Lex 25import Wavefront.Lex
26import qualified Data.Wavefront as C
27import Wavefront as C
26 28
27import Criterion.Main 29import 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
41cube_objT :: Text 43cube_objT :: Text
42cube_objT = decodeASCII $ L.toStrict cube_obj 44cube_objT = decodeUtf8 $ L.toStrict cube_obj
43{-# NOINLINE cube_objT #-} 45{-# NOINLINE cube_objT #-}
44 46
45countVerticesSabadie :: Text -> Int 47countVerticesSabadie :: 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
68countVerticesCrayneFull :: L.ByteString -> Int
69countVerticesCrayneFull ts = V.length vs
70 where
71 obj = C.parse ts
72 vs = C.objLocations obj
73
74
66sabadie :: Text -> Either String WavefrontOBJ 75sabadie :: Text -> Either String WavefrontOBJ
67sabadie = fmap (ctxtToWavefrontOBJ . lexer) . tokenize 76sabadie = 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