From 500a6ca99eb5b878a4d79706d48f776d2bd2b450 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Wed, 12 Jun 2019 20:17:54 -0400 Subject: Optmizations, disabled weigh benchmarking. --- src/Wavefront.hs | 11 ++++++----- test/bench.hs | 9 +++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Wavefront.hs b/src/Wavefront.hs index 9e42779..d53c786 100644 --- a/src/Wavefront.hs +++ b/src/Wavefront.hs @@ -189,15 +189,15 @@ nextToken :: (L.ByteString -> L.ByteString) -> L.ByteString -> L.ByteString nextToken tok bs = tok $ L.dropWhile (not . isSpace) bs parseFloats tok bs cont = case L.splitAt 10 (tok bs) of - (ds,bs') -> case F.readSigned F.readExponential (L.toStrict ds) of + (ds,bs') -> case F.readSigned F.readDecimal (L.toStrict ds) of Just (x,b) -> parseFloats tok (reconsChunk b bs') (cont . (x :)) - Nothing -> cont [] (ds <> bs') + Nothing -> cont [] bs parseFloatsN 0 _ bs cont = cont [] bs parseFloatsN n tok bs cont = case L.splitAt 10 (tok bs) of - (ds,bs') -> case F.readSigned F.readExponential (L.toStrict ds) of + (ds,bs') -> case F.readSigned F.readDecimal (L.toStrict ds) of Just (x,b) -> parseFloatsN (n-1) tok (reconsChunk b bs') (cont . (x :)) - Nothing -> cont [] (ds <> bs') + Nothing -> cont [] bs parseInts tok bs cont = case L.splitAt 5 (tok bs) of (ds,bs') -> case I.readSigned I.readDecimal (L.toStrict ds) of @@ -210,6 +210,7 @@ parseIntsN n tok bs cont = case L.splitAt 5 (tok bs) of Just (x,b) -> parseIntsN (n-1) tok (reconsChunk b bs') (cont . (x :)) Nothing -> cont [] (ds <> bs') +-- Optimize me parseTriples :: (L.ByteString -> L.ByteString) -> L.ByteString -> ([RefTriple] -> L.ByteString -> b) -> b parseTriples tok bs cont = case L.splitAt 17 (tok bs) of (ds,bs') -> case I.readSigned I.readDecimal (L.toStrict ds) of @@ -235,7 +236,7 @@ parseTriples tok bs cont = case L.splitAt 17 (tok bs) of _ -> parseTriples tok (reconsChunk b bs') $ cont . (RefTriple v Nothing Nothing :) - Nothing -> cont [] (ds <> bs') + Nothing -> cont [] bs parseCurveSpecs :: (L.ByteString -> L.ByteString) -> L.ByteString -> ([CurveSpec] -> L.ByteString -> b) -> b parseCurveSpecs tok bs cont = parseFloatsN 2 tok bs $ \fs bs' -> case fs of diff --git a/test/bench.hs b/test/bench.hs index 9952ec2..3125ed9 100644 --- a/test/bench.hs +++ b/test/bench.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE ForeignFunctionInterface #-} import qualified Data.Attoparsec.Text as Atto import qualified Data.ByteString.Char8 as S @@ -24,7 +25,9 @@ import qualified Graphics.WaveFront.Parse.Common as Parse import Wavefront import Criterion.Main +#ifdef WEIGH import Weigh -- WARNING: weigh is incompatible with profiling. It reports much more allocations with profiling turned on. +#endif foreign import ccall "&cube_obj" cube_ptr :: Ptr Word8 cube_obj_len :: Int @@ -79,4 +82,10 @@ main = do , bench "sundqvist" $ whnf countVerticesSundqvist cube_objT ] ] +#ifdef WEIGH + Weigh.mainWith $ do + func "crayne" countVerticesCrayne cube_obj + func "sabadie" countVerticesSabadie cube_objT + func "sundqvist" countVerticesSundqvist cube_objT +#endif return () -- cgit v1.2.3