forked from paulocoutinhox/gonotin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·235 lines (190 loc) · 5.81 KB
/
run.sh
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#! /bin/bash
################################################################################
echo ""
# variables
GO_INSTALLED=0
CPP_INSTALLED=0
PYTHON_INSTALLED=0
PHP_INSTALLED=0
NODEJS_INSTALLED=0
TEMP_FOLDER=temp
# functions
startTimer() {
if [[ "$OSTYPE" == "darwin"* ]]; then
start=$(gdate +%s.%N)
else
start=$(date +%s.%N)
fi
}
endTimer() {
if [[ "$OSTYPE" == "darwin"* ]]; then
dur=$(echo "$(gdate +%s.%N) - $start" | bc);
else
dur=$(echo "$(date +%s.%N) - $start" | bc);
fi
printf "> Execution time: %.6f seconds\n\n" $dur
}
checkGoInstalled() {
if [ -x "$(command -v go)" ]; then
GO_INSTALLED=1
fi
}
checkCppInstalled() {
if [[ "$OSTYPE" == "darwin"* ]]; then
if [ -x "$(command -v clang++)" ]; then
CPP_INSTALLED=1
fi
else
if [ -x "$(command -v g++)" ]; then
CPP_INSTALLED=1
fi
fi
}
checkPythonInstalled() {
if [ -x "$(command -v python2)" ]; then
PYTHON_INSTALLED=1
python() { python2 "$@"; }
else
if [ -x "$(command -v python)" ]; then
PYTHON_INSTALLED=1
fi
fi
}
checkPhpInstalled() {
if [ -x "$(command -v php)" ]; then
PHP_INSTALLED=1
fi
}
checkNodeJsInstalled() {
if [ -x "$(command -v node)" ]; then
NODEJS_INSTALLED=1
fi
}
################################################################################
# check installed apps
checkGoInstalled
checkCppInstalled
checkPythonInstalled
checkPhpInstalled
checkNodeJsInstalled
################################################################################
# get total of files
totalFilesGo=$(find go-version/*.go -maxdepth 1 -type f | wc -l)
totalFilesCpp=$(find cpp-version/*.cpp -maxdepth 1 -type f | wc -l)
totalFilesPython=$(find python-version/*.py -maxdepth 1 -type f | wc -l)
#totalFilesPhp=$(find php-version/*.php -maxdepth 1 -type f | wc -l)
#totalFilesNodeJs=$(find nodejs-version/*.js -maxdepth 1 -type f | wc -l)
################################################################################
echo "> Removing old temporary files..."
rm -rf temp
mkdir temp
echo ""
################################################################################
if [ $GO_INSTALLED -eq 1 ]; then
echo "> Compiling Go files..."
for i in `seq 1 $totalFilesGo`; do
echo "> Compiling file $i..."
rm -rf $TEMP_FOLDER/go-gonotin-$i
go build -o $TEMP_FOLDER/go-gonotin-$i go-version/gonotin$i.go
done
echo ""
else
echo "> ERROR: Go is not installed!"
echo ""
fi
################################################################################
if [ $CPP_INSTALLED -eq 1 ]; then
echo "> Compiling C++ files..."
for i in `seq 1 $totalFilesCpp`; do
echo "> Compiling file $i..."
rm -rf $TEMP_FOLDER/cpp-gonotin-$i
# OSX and Linux compiling method
if [[ "$OSTYPE" == "darwin"* ]]; then
clang++ -g cpp-version/gonotin$i.cpp -o $TEMP_FOLDER/cpp-gonotin-$i -lm -std=c++11 -O2
else
g++ -g -pthread cpp-version/gonotin$i.cpp -o $TEMP_FOLDER/cpp-gonotin-$i -lm -std=c++11 -O2
fi
done
echo ""
else
echo "> ERROR: C++ is not installed!"
echo ""
fi
################################################################################
CWD=$(pwd)
SIZE=$1
FILE_A=$CWD/data/fileA-$SIZE.txt
FILE_B=$CWD/data/fileB-$SIZE.txt
SUFFIX=.txt
EXECUTABLE=gonotin
echo "> Processing $SIZE files..."
echo ""
################################################################################
if [ $GO_INSTALLED -eq 1 ]; then
for i in `seq 1 $totalFilesGo`; do
echo "> Executing Go (mode = $i, size = $SIZE) version..."
startTimer
$TEMP_FOLDER/go-$EXECUTABLE-$i $FILE_A $FILE_B $i > $TEMP_FOLDER/go-$SIZE-mode-$i$SUFFIX
endTimer
echo ""
done
else
echo "> ERROR: Go is not installed!"
echo ""
fi
################################################################################
if [ $CPP_INSTALLED -eq 1 ]; then
for i in `seq 1 $totalFilesCpp`; do
echo "> Executing C++ (mode = $i, size = $SIZE) version..."
startTimer
$TEMP_FOLDER/cpp-$EXECUTABLE-$i $FILE_A $FILE_B $i > $TEMP_FOLDER/cpp-$SIZE-mode-$i$SUFFIX
endTimer
echo ""
done
else
echo "> ERROR: G++ is not installed!"
echo ""
fi
################################################################################
if [ $PYTHON_INSTALLED -eq 1 ]; then
for i in `seq 1 $totalFilesPython`; do
echo "> Executing Python (mode = $i, size = $SIZE) version..."
startTimer
MODE=$i python python-version/$EXECUTABLE$i.py $FILE_A $FILE_B > $TEMP_FOLDER/python-$SIZE-mode-$i$SUFFIX
endTimer
echo ""
done
else
echo "> ERROR: Python is not installed!"
echo ""
fi
################################################################################
#if [ $PHP_INSTALLED -eq 1 ]; then
# for i in `seq 1 $totalFilesPhp`; do
# echo "> Executing PHP (mode = $i, size = $SIZE) version..."
# startTimer
# php php-version/$EXECUTABLE$i.php $FILE_A $FILE_B $i > $TEMP_FOLDER/php-$SIZE-mode-$i$SUFFIX
# endTimer
# echo ""
# done
#else
# echo "> ERROR: Php is not installed!"
# echo ""
#fi
################################################################################
#if [ $NODEJS_INSTALLED -eq 1 ]; then
# for i in `seq 1 $totalFilesNodeJs`; do
# echo "> Executing Node (mode = $i, size = $SIZE) version..."
# startTimer
# node nodejs-version/$EXECUTABLE$i.js $FILE_A $FILE_B > $TEMP_FOLDER/nodejs-$SIZE-mode-$i$SUFFIX
# endTimer
# echo ""
# done
#
#else
# echo "> ERROR: NodeJs is not installed!"
# echo ""
#fi
################################################################################
echo "> Finished!"
echo ""