Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# OPTIONS_GHC -threaded -O2 #-}
- {-# LANGUAGE OverloadedStrings #-}
- -- This benchmark was executed with the following options:
- -- -s 100 +RTS -N1 -RTS
- import Criterion.Main
- import Graphics.Implicit
- import Graphics.Implicit.Export.TextBuilderUtils
- import Graphics.Implicit.Definitions
- import Graphics.Implicit.Export.Definitions
- import Graphics.Implicit.Export.SymbolicObj2
- import Graphics.Implicit.Export.SymbolicObj3
- import qualified Data.Text.Lazy.IO as TextIO
- formatWithLazyText triangles = toLazyText $ stlHeader <> mconcat (map triangle triangles) <> stlFooter
- where
- stlHeader = "solid ImplictCADExport\n"
- stlFooter = "endsolid ImplictCADExport\n"
- vertex :: ℝ3 -> Builder
- vertex (x,y,z) = mconcat ["vertex "
- ,bf x , " "
- ,bf y , " "
- ,bf z]
- triangle :: (ℝ3, ℝ3, ℝ3) -> Builder
- triangle (a,b,c) = "facet normal 0 0 0\nouter loop\n"
- <> vertex a <> "\n"
- <> vertex b <> "\n"
- <> vertex c
- <> "\nendloop\nendfacet\n"
- formatWithString triangles = text
- where
- stlHeader = "solid ImplictCADExport\n"
- stlFooter = "endsolid ImplictCADExport\n"
- vertex :: ℝ3 -> String
- vertex (x,y,z) = "vertex " ++ show x ++ " " ++ show y ++ " " ++ show z
- stlTriangle :: (ℝ3, ℝ3, ℝ3) -> String
- stlTriangle (a,b,c) =
- "facet normal 0 0 0\n"
- ++ "outer loop\n"
- ++ vertex a ++ "\n"
- ++ vertex b ++ "\n"
- ++ vertex c ++ "\n"
- ++ "endloop\n"
- ++ "endfacet\n"
- text = stlHeader
- ++ (concat $ map stlTriangle triangles)
- ++ stlFooter
- model = union [
- rect3R 0 (0,0,0) (20,20,20),
- translate (30,30,30) (rect3R 0 (0,0,0) (40,40,40))
- ]
- main = defaultMain [
- bgroup "writing stl" [
- bench "with Text.Lazy" $ nfIO $ TextIO.writeFile "/dev/null" $ formatWithLazyText $ discreteAprox 1 model,
- bench "with String" $ nfIO $ writeFile "/dev/null" $ formatWithString $ discreteAprox 1 model
- ]
- ]
Add Comment
Please, Sign In to add comment