2009-11-20 09:59:11 -07:00
|
|
|
#!/usr/bin/env bash
|
2009-08-04 15:07:17 -06:00
|
|
|
# Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
set -e
|
2009-12-11 16:14:09 -07:00
|
|
|
|
2012-02-23 22:59:09 -07:00
|
|
|
eval $(go tool dist env)
|
2015-05-21 11:28:13 -06:00
|
|
|
GC="go tool compile"
|
|
|
|
LD="go tool link"
|
2012-02-23 22:59:09 -07:00
|
|
|
|
2012-10-07 13:49:56 -06:00
|
|
|
gccm=""
|
|
|
|
case "$O" in
|
|
|
|
8)
|
|
|
|
gccm=-m32;;
|
|
|
|
6)
|
|
|
|
gccm=-m64;;
|
|
|
|
esac
|
|
|
|
|
2014-05-09 15:34:50 -06:00
|
|
|
EXE="out"
|
|
|
|
havepcre=true
|
|
|
|
haveglib=true
|
|
|
|
havegmp=true
|
|
|
|
case "$(uname)" in
|
|
|
|
*MINGW* | *WIN32* | *CYGWIN*)
|
|
|
|
havepcre=false
|
|
|
|
haveglib=false
|
|
|
|
havegmp=false
|
|
|
|
if which pkg-config >/dev/null 2>&1; then
|
|
|
|
if pkg-config --cflags libpcre >/dev/null 2>&1
|
|
|
|
then
|
|
|
|
echo "havepcre"
|
|
|
|
havepcre=true
|
|
|
|
fi
|
|
|
|
if pkg-config --cflags glib-2.0 >/dev/null 2>&1
|
|
|
|
then
|
|
|
|
haveglib=true
|
|
|
|
fi
|
|
|
|
if pkg-config --cflags gmp >/dev/null 2>&1
|
|
|
|
then
|
|
|
|
havegmp=true
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
EXE=exe;;
|
|
|
|
esac
|
|
|
|
|
2009-08-09 20:18:40 -06:00
|
|
|
PATH=.:$PATH
|
2009-08-04 15:07:17 -06:00
|
|
|
|
2010-12-15 07:47:13 -07:00
|
|
|
havegccgo=false
|
|
|
|
if which gccgo >/dev/null 2>&1
|
|
|
|
then
|
|
|
|
havegccgo=true
|
|
|
|
fi
|
|
|
|
|
2009-08-09 15:31:05 -06:00
|
|
|
mode=run
|
|
|
|
case X"$1" in
|
|
|
|
X-test)
|
|
|
|
mode=test
|
|
|
|
shift
|
|
|
|
esac
|
|
|
|
|
2009-08-04 15:07:17 -06:00
|
|
|
gc() {
|
2015-05-21 11:28:17 -06:00
|
|
|
$GC $1.go; $LD -o a.$EXE $1.o
|
2009-08-04 15:07:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
gc_B() {
|
2015-05-21 11:28:17 -06:00
|
|
|
$GC -B $1.go; $LD -o a.$EXE $1.o
|
2009-08-04 15:07:17 -06:00
|
|
|
}
|
|
|
|
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly() {
|
|
|
|
if [ $mode = run ]
|
|
|
|
then
|
|
|
|
"$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-08-04 15:07:17 -06:00
|
|
|
run() {
|
2009-08-09 15:31:05 -06:00
|
|
|
if [ $mode = test ]
|
|
|
|
then
|
|
|
|
if echo $1 | grep -q '^gc '
|
|
|
|
then
|
|
|
|
$1 # compile the program
|
|
|
|
program=$(echo $1 | sed 's/gc //')
|
|
|
|
shift
|
|
|
|
echo $program
|
2015-07-30 23:57:16 -06:00
|
|
|
$1 <fasta-1000.txt > /tmp/$$
|
2009-08-09 15:31:05 -06:00
|
|
|
case $program in
|
|
|
|
chameneosredux)
|
|
|
|
# exact numbers may vary but non-numbers should match
|
|
|
|
grep -v '[0-9]' /tmp/$$ > /tmp/$$x
|
|
|
|
grep -v '[0-9]' chameneosredux.txt > /tmp/$$y
|
|
|
|
cmp /tmp/$$x /tmp/$$y
|
|
|
|
rm -f /tmp/$$ /tmp/$$x /tmp/$$y
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
cmp /tmp/$$ $program.txt
|
|
|
|
rm -f /tmp/$$
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
return
|
|
|
|
fi
|
2010-12-15 07:47:13 -07:00
|
|
|
if ! $havegccgo && echo $1 | grep -q '^gccgo '
|
|
|
|
then
|
|
|
|
return
|
|
|
|
fi
|
2009-08-04 15:07:17 -06:00
|
|
|
echo -n ' '$1' '
|
|
|
|
$1
|
|
|
|
shift
|
2009-11-20 09:59:11 -07:00
|
|
|
|
|
|
|
echo $((time -p $* >/dev/null) 2>&1) | awk '{print $4 "u " $6 "s " $2 "r"}'
|
2009-08-04 15:07:17 -06:00
|
|
|
}
|
|
|
|
|
2009-08-04 15:27:46 -06:00
|
|
|
fasta() {
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly echo 'fasta -n 25000000'
|
2014-05-09 15:34:50 -06:00
|
|
|
run "gcc $gccm -O2 fasta.c" a.$EXE 25000000
|
|
|
|
run 'gccgo -O2 fasta.go' a.$EXE -n 25000000 #commented out until WriteString is in bufio
|
2015-05-21 11:28:17 -06:00
|
|
|
run 'gc fasta' a.$EXE -n 25000000
|
|
|
|
run 'gc_B fasta' a.$EXE -n 25000000
|
2009-08-04 15:27:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
revcomp() {
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly gcc -O2 fasta.c
|
2014-05-09 15:34:50 -06:00
|
|
|
runonly a.$EXE 25000000 > x
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly echo 'reverse-complement < output-of-fasta-25000000'
|
2014-05-09 15:34:50 -06:00
|
|
|
run "gcc $gccm -O2 reverse-complement.c" a.$EXE < x
|
|
|
|
run 'gccgo -O2 reverse-complement.go' a.$EXE < x
|
2015-05-21 11:28:17 -06:00
|
|
|
run 'gc reverse-complement' a.$EXE < x
|
|
|
|
run 'gc_B reverse-complement' a.$EXE < x
|
2009-08-04 15:27:46 -06:00
|
|
|
rm x
|
|
|
|
}
|
|
|
|
|
|
|
|
nbody() {
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly echo 'nbody -n 50000000'
|
2014-05-09 15:34:50 -06:00
|
|
|
run "gcc $gccm -O2 nbody.c -lm" a.$EXE 50000000
|
|
|
|
run 'gccgo -O2 nbody.go' a.$EXE -n 50000000
|
2015-05-21 11:28:17 -06:00
|
|
|
run 'gc nbody' a.$EXE -n 50000000
|
|
|
|
run 'gc_B nbody' a.$EXE -n 50000000
|
2009-08-04 15:27:46 -06:00
|
|
|
}
|
|
|
|
|
2009-08-04 20:38:08 -06:00
|
|
|
binarytree() {
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly echo 'binary-tree 15 # too slow to use 20'
|
2014-05-09 15:34:50 -06:00
|
|
|
run "gcc $gccm -O2 binary-tree.c -lm" a.$EXE 15
|
|
|
|
run 'gccgo -O2 binary-tree.go' a.$EXE -n 15
|
|
|
|
run 'gccgo -O2 binary-tree-freelist.go' a.$EXE -n 15
|
2015-05-21 11:28:17 -06:00
|
|
|
run 'gc binary-tree' a.$EXE -n 15
|
|
|
|
run 'gc binary-tree-freelist' a.$EXE -n 15
|
2009-08-04 20:38:08 -06:00
|
|
|
}
|
|
|
|
|
2009-08-05 12:33:59 -06:00
|
|
|
fannkuch() {
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly echo 'fannkuch 12'
|
2014-05-09 15:34:50 -06:00
|
|
|
run "gcc $gccm -O2 fannkuch.c" a.$EXE 12
|
|
|
|
run 'gccgo -O2 fannkuch.go' a.$EXE -n 12
|
|
|
|
run 'gccgo -O2 fannkuch-parallel.go' a.$EXE -n 12
|
2015-05-21 11:28:17 -06:00
|
|
|
run 'gc fannkuch' a.$EXE -n 12
|
|
|
|
run 'gc fannkuch-parallel' a.$EXE -n 12
|
|
|
|
run 'gc_B fannkuch' a.$EXE -n 12
|
2009-08-05 12:33:59 -06:00
|
|
|
}
|
|
|
|
|
2009-08-05 14:03:46 -06:00
|
|
|
regexdna() {
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly gcc -O2 fasta.c
|
2014-05-09 15:34:50 -06:00
|
|
|
runonly a.$EXE 100000 > x
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly echo 'regex-dna 100000'
|
2014-05-09 15:34:50 -06:00
|
|
|
if $havepcre; then
|
|
|
|
run "gcc $gccm -O2 regex-dna.c $(pkg-config libpcre --cflags --libs)" a.$EXE <x
|
|
|
|
fi
|
|
|
|
run 'gccgo -O2 regex-dna.go' a.$EXE <x
|
|
|
|
run 'gccgo -O2 regex-dna-parallel.go' a.$EXE <x
|
2015-05-21 11:28:17 -06:00
|
|
|
run 'gc regex-dna' a.$EXE <x
|
|
|
|
run 'gc regex-dna-parallel' a.$EXE <x
|
|
|
|
run 'gc_B regex-dna' a.$EXE <x
|
2009-08-05 14:03:46 -06:00
|
|
|
rm x
|
|
|
|
}
|
|
|
|
|
2009-08-05 18:25:38 -06:00
|
|
|
spectralnorm() {
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly echo 'spectral-norm 5500'
|
2014-05-09 15:34:50 -06:00
|
|
|
run "gcc $gccm -O2 spectral-norm.c -lm" a.$EXE 5500
|
|
|
|
run 'gccgo -O2 spectral-norm.go' a.$EXE -n 5500
|
2015-05-21 11:28:17 -06:00
|
|
|
run 'gc spectral-norm' a.$EXE -n 5500
|
|
|
|
run 'gc_B spectral-norm' a.$EXE -n 5500
|
2009-08-05 18:25:38 -06:00
|
|
|
}
|
|
|
|
|
2009-08-06 14:00:26 -06:00
|
|
|
knucleotide() {
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly gcc -O2 fasta.c
|
2014-05-09 15:34:50 -06:00
|
|
|
runonly a.$EXE 1000000 > x # should be using 25000000
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly echo 'k-nucleotide 1000000'
|
2014-05-09 15:34:50 -06:00
|
|
|
if [ $mode = run ] && $haveglib; then
|
|
|
|
run "gcc -O2 k-nucleotide.c $(pkg-config glib-2.0 --cflags --libs)" a.$EXE <x
|
2012-06-24 17:23:09 -06:00
|
|
|
fi
|
2014-05-09 15:34:50 -06:00
|
|
|
run 'gccgo -O2 k-nucleotide.go' a.$EXE <x
|
|
|
|
run 'gccgo -O2 k-nucleotide-parallel.go' a.$EXE <x
|
2015-05-21 11:28:17 -06:00
|
|
|
run 'gc k-nucleotide' a.$EXE <x
|
|
|
|
run 'gc k-nucleotide-parallel' a.$EXE <x
|
|
|
|
run 'gc_B k-nucleotide' a.$EXE <x
|
2009-08-06 14:00:26 -06:00
|
|
|
rm x
|
|
|
|
}
|
|
|
|
|
2009-08-06 15:21:21 -06:00
|
|
|
mandelbrot() {
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly echo 'mandelbrot 16000'
|
2014-05-09 15:34:50 -06:00
|
|
|
run "gcc $gccm -O2 mandelbrot.c" a.$EXE 16000
|
|
|
|
run 'gccgo -O2 mandelbrot.go' a.$EXE -n 16000
|
2015-05-21 11:28:17 -06:00
|
|
|
run 'gc mandelbrot' a.$EXE -n 16000
|
|
|
|
run 'gc_B mandelbrot' a.$EXE -n 16000
|
2009-08-06 15:21:21 -06:00
|
|
|
}
|
|
|
|
|
2009-08-06 19:04:48 -06:00
|
|
|
meteor() {
|
2010-12-15 07:47:13 -07:00
|
|
|
runonly echo 'meteor 2098'
|
2014-05-09 15:34:50 -06:00
|
|
|
run "gcc $gccm -O2 meteor-contest.c" a.$EXE 2098
|
|
|
|
run 'gccgo -O2 meteor-contest.go' a.$EXE -n 2098
|
2015-05-21 11:28:17 -06:00
|
|
|
run 'gc meteor-contest' a.$EXE -n 2098
|
|
|
|
run 'gc_B meteor-contest' a.$EXE -n 2098
|
2009-08-06 19:04:48 -06:00
|
|
|
}
|
|
|
|
|
2009-08-06 19:27:15 -06:00
|
|
|
pidigits() {
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly echo 'pidigits 10000'
|
2014-05-09 15:34:50 -06:00
|
|
|
if $havegmp; then
|
|
|
|
run "gcc $gccm -O2 pidigits.c -lgmp" a.$EXE 10000
|
|
|
|
fi
|
|
|
|
run 'gccgo -O2 pidigits.go' a.$EXE -n 10000
|
2015-05-21 11:28:17 -06:00
|
|
|
run 'gc pidigits' a.$EXE -n 10000
|
|
|
|
run 'gc_B pidigits' a.$EXE -n 10000
|
2009-08-06 19:27:15 -06:00
|
|
|
}
|
|
|
|
|
2009-08-07 13:53:51 -06:00
|
|
|
threadring() {
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly echo 'threadring 50000000'
|
2014-05-09 15:34:50 -06:00
|
|
|
run "gcc $gccm -O2 threadring.c -lpthread" a.$EXE 50000000
|
|
|
|
run 'gccgo -O2 threadring.go' a.$EXE -n 50000000
|
2015-05-21 11:28:17 -06:00
|
|
|
run 'gc threadring' a.$EXE -n 50000000
|
2009-08-07 13:53:51 -06:00
|
|
|
}
|
|
|
|
|
2009-08-07 16:28:46 -06:00
|
|
|
chameneos() {
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly echo 'chameneos 6000000'
|
2014-05-09 15:34:50 -06:00
|
|
|
run "gcc $gccm -O2 chameneosredux.c -lpthread" a.$EXE 6000000
|
|
|
|
run 'gccgo -O2 chameneosredux.go' a.$EXE 6000000
|
2015-05-21 11:28:17 -06:00
|
|
|
run 'gc chameneosredux' a.$EXE 6000000
|
2009-08-07 16:28:46 -06:00
|
|
|
}
|
|
|
|
|
2009-08-04 15:27:46 -06:00
|
|
|
case $# in
|
|
|
|
0)
|
2009-08-07 16:28:46 -06:00
|
|
|
run="fasta revcomp nbody binarytree fannkuch regexdna spectralnorm knucleotide mandelbrot meteor pidigits threadring chameneos"
|
2009-08-04 15:27:46 -06:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
run=$*
|
|
|
|
esac
|
2009-08-04 15:07:17 -06:00
|
|
|
|
2009-08-04 15:27:46 -06:00
|
|
|
for i in $run
|
|
|
|
do
|
|
|
|
$i
|
2009-08-09 15:31:05 -06:00
|
|
|
runonly echo
|
2009-08-04 15:27:46 -06:00
|
|
|
done
|
2015-07-30 20:03:48 -06:00
|
|
|
|
|
|
|
rm *.o *.$EXE # Clean up
|
|
|
|
|