Merge: Byte data type
[nit.git] / benchmarks / polygons / java / 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 nbpts"
34 echo " sort_vertices: sort the vertices of the polygon"
35 echo " - usage : sort_vertices nbpts"
36 echo " intersection: bench the intersection between two polygons"
37 echo " - usage : intersection nbpts"
38 echo " convex_hull: bench creating the convex hull of a set of points"
39 echo " - usage : convex_hull nbpts"
40 echo " convexity : bench the verification of the convexity of a polygon"
41 echo " - usage : convexity nbpts"
42 echo " contain : bench the point in polygon check"
43 echo " - usage : contain nbpts"
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
55 cd add_vertex
56
57 javac ../code/*.java -d .
58
59 prepare_res add_vertex.out add_vertex add_vertex
60
61 bench_command add_vertex add_vertex java BenchPolygon add_vertex $((points / 2))
62 }
63
64 function bench_sorting()
65 {
66 if [ -d sort_vertices ]; then
67 rm sort_vertices/*
68 else
69 mkdir sort_vertices
70 fi
71 cd sort_vertices
72
73 javac ../code/*.java -d .
74
75 prepare_res sort_vertices.out sort_vertex sort_vertices
76
77 bench_command sort_vertices sort_vertices java BenchPolygon sort_vertices $((points * 20))
78
79 }
80
81 function bench_intersection()
82 {
83 if [ -d intersection ]; then
84 rm intersection/*
85 else
86 mkdir intersection
87 fi
88 cd intersection
89
90 javac ../code/*.java -d .
91
92 prepare_res intersection.out intersection intersection
93
94 bench_command intersection intersection java BenchPolygon intersection $((points / 10))
95 }
96
97 function bench_convex_hull()
98 {
99 echo Bench way too long, skipping it
100
101 return
102
103 if [ -d convex_hull ]; then
104 rm convex_hull/*
105 else
106 mkdir convex_hull
107 fi
108 cd convex_hull
109
110 javac ../code/*.java -d .
111
112 prepare_res convex_hull.out convex_hull convex_hull
113
114 bench_command convex_hull convex_hull java BenchPolygon convex_hull $((points * 30))
115 }
116
117 function bench_convexity()
118 {
119 if [ -d convexity ]; then
120 rm convexity/*
121 else
122 mkdir convexity
123 fi
124 cd convexity
125
126 javac ../code/*.java -d .
127
128 prepare_res convexity.out convexity convexity
129
130 bench_command convexity convexity java BenchPolygon convexity $((points * 40))
131 }
132
133
134 function bench_contain()
135 {
136 if [ -d contain ]; then
137 rm contain/*
138 else
139 mkdir contain
140 fi
141 cd contain
142
143 javac ../code/*.java -d .
144
145 prepare_res contain.out contain contain
146
147 bench_command contain contain java BenchPolygon contain $((points * 50))
148 }
149
150 stop=false
151 while [ "$stop" = false ]; do
152 case "$1" in
153 -h) usage; exit;;
154 -n) count="$2"; shift; shift;;
155 -p) points="$2"; shift;shift;;
156 *) stop=true
157 esac
158 done
159
160 if test $# -lt 1; then
161 usage
162 exit
163 fi
164
165 case "$1" in
166 add_vertex) shift; bench_add_vertex $@ ;;
167 sort_vertices) shift; bench_sorting $@ ;;
168 intersection) shift; bench_intersection $@ ;;
169 convex_hull) shift; bench_convex_hull $@ ;;
170 convexity) shift; bench_convexity $@;;
171 contain) shift; bench_contain $@;;
172 *) usage; exit;;
173 esac