forked from Haskell-Things/ImplicitCAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Benchmark.hs
62 lines (53 loc) · 1.64 KB
/
Benchmark.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import Criterion.Main
import Graphics.Implicit
import Graphics.Implicit.Export.SymbolicObj2
import Graphics.Implicit.Export.SymbolicObj3
import Graphics.Implicit.Primitives
obj2d_1 :: SymbolicObj2
obj2d_1 =
union
[ circle 10
, translate (22,0) $ circle 10
, translate (0,22) $ circle 10
, translate (-22,0) $ circle 10
, translate (0,-22) $ circle 10
]
object1 :: SymbolicObj3
object1 = extrudeRM 0 (Just twist) Nothing Nothing obj2d_1 (Left 40)
where twist h = 35*cos(h*2*pi/60)
object2 :: SymbolicObj3
object2 = squarePipe (10,10,10) 1 100
where squarePipe (x,y,z) diameter precision =
union
$ map (\start-> translate start
$ rect3R 0 (0,0,0) (diameter,diameter,diameter)
)
$ zip3 (map (\n->(n/precision)*x) [0..precision])
(map (\n->(n/precision)*y) [0..precision])
(map (\n->(n/precision)*z) [0..precision])
object3 :: SymbolicObj3
object3 =
difference
[ rect3R 1 (-1,-1,-1) (1,1,1)
, rect3R 1 (0,0,0) (2,2,2)
]
obj2Benchmarks :: String -> SymbolicObj2 -> Benchmark
obj2Benchmarks name obj =
bgroup name
[ bench "SVG write" $ writeSVG 1 "benchmark.svg" obj
, bench "PNG write" $ writePNG2 1 "benchmark.png" obj
, bench "Get contour" $ nf (symbolicGetContour 1) obj
]
obj3Benchmarks :: String -> SymbolicObj3 -> Benchmark
obj3Benchmarks name obj =
bgroup name
[ --bench "PNG write" $ writePNG3 1 "benchmark.png" obj
bench "STL write" $ writeSTL 1 "benchmark.stl" obj
, bench "Get mesh" $ nf (symbolicGetMesh 1) obj
]
benchmarks =
[ obj3Benchmarks "Object 1" object1
, obj3Benchmarks "Object 2" object2
, obj3Benchmarks "Object 3" object3
]
main = defaultMain benchmarks