52895e9ed8b8c46479425f04dcaba7edefb9b40c
[nit.git] / benchmarks / polygons / nit / bench_polygon.sh
1 #!/bin/bash
2 # This file is part of NIT ( http://www.nitlanguage.org ).
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 source ../../bench_common.sh
17 source ../../bench_plot.sh
18
19 # Default number of times a command must be run with bench_command
20 # Can be overrided with 'the option -n'
21 count=5
22 points=100000
23
24 function usage()
25 {
26 echo "run_bench: [options]* bench_name args"
27 echo " -n count: number of execution for each bar (default: $count)"
28 echo " -p points: number of points used for the polygons (default: $points)"
29 echo " -h: this help"
30 echo ""
31 echo "Benches : "
32 echo " add_vertex: bench adding vertex in a polygon"
33 echo " - usage : add_vertex p"
34 echo " sort_vertices: sort the vertices of the polygon"
35 echo " - usage : sort_vertices p"
36 echo " intersection: bench the intersection between two polygons"
37 echo " - usage : intersection p"
38 echo " convex_hull: bench creating the convex hull of a set of points"
39 echo " - usage : convex_hull p"
40 echo " convexity : bench the verification of the convexity of a polygon"
41 echo " - usage : convexity p"
42 echo " contain : bench the point in polygon check"
43 echo " - usage : contain p"
44 }
45
46
47 function bench_add_vertex()
48 {
49 if [ -d add_vertex ]; then
50 rm add_vertex/*
51 else
52 mkdir add_vertex
53 fi
54 cd add_vertex
55
56 ../../../../bin/nitc --global ../bench_polygon.nit
57
58 prepare_res add_vertex.out add_vertex add_vertex
59
60 bench_command add_vertex add_vertex ./bench_polygon -m add_vertex --nbpts $((points / 2))
61 }
62
63 function bench_sorting()
64 {
65 if [ -d sort_vertices ]; then
66 rm sort_vertices/*
67 else
68 mkdir sort_vertices
69 fi
70 cd sort_vertices
71
72 ../../../../bin/nitc --global ../bench_polygon.nit
73
74 prepare_res sort_vertices.out sort_vertex sort_vertices
75
76 bench_command sort_vertices sort_vertices ./bench_polygon -m sort_vertices --nbpts $((points * 20))
77 }
78
79 function bench_intersection()
80 {
81 if [ -d intersection ]; then
82 rm intersection/*
83 else
84 mkdir intersection
85 fi
86 cd intersection
87
88 ../../../../bin/nitc --global ../bench_polygon.nit
89
90 prepare_res intersection.out intersection intersection
91
92 bench_command intersection intersection ./bench_polygon -m intersection --nbpts $((points / 10))
93 }
94
95 function bench_convex_hull()
96 {
97 if [ -d convex_hull ]; then
98 rm convex_hull/*
99 else
100 mkdir convex_hull
101 fi
102 cd convex_hull
103
104 ../../../../bin/nitc --global ../bench_polygon.nit
105
106 prepare_res convex_hull.out convex_hull convex_hull
107
108 bench_command convex_hull convex_hull ./bench_polygon -m convex_hull --nbpts $((points * 30))
109 }
110
111 function bench_convexity()
112 {
113 if [ -d convexity ]; then
114 rm convexity/*
115 else
116 mkdir convexity
117 fi
118 cd convexity
119
120 ../../../../bin/nitc --global ../bench_polygon.nit
121
122 prepare_res convexity.out convexity convexity
123
124 bench_command convexity convexity ./bench_polygon -m is_convex --nbpts $((points * 40))
125 }
126
127
128 function bench_contain()
129 {
130 if [ -d contain ]; then
131 rm contain/*
132 else
133 mkdir contain
134 fi
135 cd contain
136
137 ../../../../bin/nitc --global ../bench_polygon.nit
138
139 prepare_res contain.out contain contain
140
141 bench_command contain contain ./bench_polygon -m contain --nbpts $((points * 50))
142
143 }
144
145 stop=false
146 while [ "$stop" = false ]; do
147 case "$1" in
148 -h) usage; exit;;
149 -n) count="$2"; shift; shift;;
150 -p) points="$2"; shift;shift;;
151 *) stop=true
152 esac
153 done
154
155 if test $# -lt 1; then
156 usage
157 exit
158 fi
159
160 case "$1" in
161 add_vertex) shift; bench_add_vertex $@ ;;
162 sort_vertices) shift; bench_sorting $@ ;;
163 intersection) shift; bench_intersection $@ ;;
164 convex_hull) shift; bench_convex_hull $@ ;;
165 convexity) shift; bench_convexity $@;;
166 contain) shift; bench_contain $@;;
167 *) usage; exit;;
168 esac