Created
August 27, 2012 06:30
-
-
Save matthewSorensen/3486254 to your computer and use it in GitHub Desktop.
Benchmarks for ImplicitCAD STL Output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment