github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/test/bench/shootout/timing.sh (about) 1 #!/usr/bin/env bash 2 # Copyright 2009 The Go Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style 4 # license that can be found in the LICENSE file. 5 6 set -e 7 8 eval $(go tool dist env) 9 O=$GOCHAR 10 GC="go tool ${O}g" 11 LD="go tool ${O}l" 12 13 gccm="" 14 case "$O" in 15 8) 16 gccm=-m32;; 17 6) 18 gccm=-m64;; 19 esac 20 21 PATH=.:$PATH 22 23 havegccgo=false 24 if which gccgo >/dev/null 2>&1 25 then 26 havegccgo=true 27 fi 28 29 mode=run 30 case X"$1" in 31 X-test) 32 mode=test 33 shift 34 esac 35 36 gc() { 37 $GC $1.go; $LD $1.$O 38 } 39 40 gc_B() { 41 $GC -B $1.go; $LD $1.$O 42 } 43 44 runonly() { 45 if [ $mode = run ] 46 then 47 "$@" 48 fi 49 } 50 51 run() { 52 if [ $mode = test ] 53 then 54 if echo $1 | grep -q '^gc ' 55 then 56 $1 # compile the program 57 program=$(echo $1 | sed 's/gc //') 58 shift 59 echo $program 60 $1 <fasta-1000.out > /tmp/$$ 61 case $program in 62 chameneosredux) 63 # exact numbers may vary but non-numbers should match 64 grep -v '[0-9]' /tmp/$$ > /tmp/$$x 65 grep -v '[0-9]' chameneosredux.txt > /tmp/$$y 66 cmp /tmp/$$x /tmp/$$y 67 rm -f /tmp/$$ /tmp/$$x /tmp/$$y 68 ;; 69 *) 70 cmp /tmp/$$ $program.txt 71 rm -f /tmp/$$ 72 esac 73 fi 74 return 75 fi 76 if ! $havegccgo && echo $1 | grep -q '^gccgo ' 77 then 78 return 79 fi 80 echo -n ' '$1' ' 81 $1 82 shift 83 84 echo $((time -p $* >/dev/null) 2>&1) | awk '{print $4 "u " $6 "s " $2 "r"}' 85 } 86 87 fasta() { 88 runonly echo 'fasta -n 25000000' 89 run "gcc $gccm -O2 fasta.c" a.out 25000000 90 run 'gccgo -O2 fasta.go' a.out -n 25000000 #commented out until WriteString is in bufio 91 run 'gc fasta' $O.out -n 25000000 92 run 'gc_B fasta' $O.out -n 25000000 93 } 94 95 revcomp() { 96 runonly gcc -O2 fasta.c 97 runonly a.out 25000000 > x 98 runonly echo 'reverse-complement < output-of-fasta-25000000' 99 run "gcc $gccm -O2 reverse-complement.c" a.out < x 100 run 'gccgo -O2 reverse-complement.go' a.out < x 101 run 'gc reverse-complement' $O.out < x 102 run 'gc_B reverse-complement' $O.out < x 103 rm x 104 } 105 106 nbody() { 107 runonly echo 'nbody -n 50000000' 108 run "gcc $gccm -O2 nbody.c -lm" a.out 50000000 109 run 'gccgo -O2 nbody.go' a.out -n 50000000 110 run 'gc nbody' $O.out -n 50000000 111 run 'gc_B nbody' $O.out -n 50000000 112 } 113 114 binarytree() { 115 runonly echo 'binary-tree 15 # too slow to use 20' 116 run "gcc $gccm -O2 binary-tree.c -lm" a.out 15 117 run 'gccgo -O2 binary-tree.go' a.out -n 15 118 run 'gccgo -O2 binary-tree-freelist.go' a.out -n 15 119 run 'gc binary-tree' $O.out -n 15 120 run 'gc binary-tree-freelist' $O.out -n 15 121 } 122 123 fannkuch() { 124 runonly echo 'fannkuch 12' 125 run "gcc $gccm -O2 fannkuch.c" a.out 12 126 run 'gccgo -O2 fannkuch.go' a.out -n 12 127 run 'gccgo -O2 fannkuch-parallel.go' a.out -n 12 128 run 'gc fannkuch' $O.out -n 12 129 run 'gc fannkuch-parallel' $O.out -n 12 130 run 'gc_B fannkuch' $O.out -n 12 131 } 132 133 regexdna() { 134 runonly gcc -O2 fasta.c 135 runonly a.out 100000 > x 136 runonly echo 'regex-dna 100000' 137 run "gcc $gccm -O2 regex-dna.c -lpcre" a.out <x 138 run 'gccgo -O2 regex-dna.go' a.out <x 139 run 'gccgo -O2 regex-dna-parallel.go' a.out <x 140 run 'gc regex-dna' $O.out <x 141 run 'gc regex-dna-parallel' $O.out <x 142 run 'gc_B regex-dna' $O.out <x 143 rm x 144 } 145 146 spectralnorm() { 147 runonly echo 'spectral-norm 5500' 148 run "gcc $gccm -O2 spectral-norm.c -lm" a.out 5500 149 run 'gccgo -O2 spectral-norm.go' a.out -n 5500 150 run 'gc spectral-norm' $O.out -n 5500 151 run 'gc_B spectral-norm' $O.out -n 5500 152 } 153 154 knucleotide() { 155 runonly gcc -O2 fasta.c 156 runonly a.out 1000000 > x # should be using 25000000 157 runonly echo 'k-nucleotide 1000000' 158 if [ $mode = run ]; then 159 run "gcc -O2 k-nucleotide.c $(pkg-config glib-2.0 --cflags --libs)" a.out <x 160 fi 161 run 'gccgo -O2 k-nucleotide.go' a.out <x 162 run 'gccgo -O2 k-nucleotide-parallel.go' a.out <x 163 run 'gc k-nucleotide' $O.out <x 164 run 'gc k-nucleotide-parallel' $O.out <x 165 run 'gc_B k-nucleotide' $O.out <x 166 rm x 167 } 168 169 mandelbrot() { 170 runonly echo 'mandelbrot 16000' 171 run "gcc $gccm -O2 mandelbrot.c" a.out 16000 172 run 'gccgo -O2 mandelbrot.go' a.out -n 16000 173 run 'gc mandelbrot' $O.out -n 16000 174 run 'gc_B mandelbrot' $O.out -n 16000 175 } 176 177 meteor() { 178 runonly echo 'meteor 2098' 179 run "gcc $gccm -O2 meteor-contest.c" a.out 2098 180 run 'gccgo -O2 meteor-contest.go' a.out -n 2098 181 run 'gc meteor-contest' $O.out -n 2098 182 run 'gc_B meteor-contest' $O.out -n 2098 183 } 184 185 pidigits() { 186 runonly echo 'pidigits 10000' 187 run "gcc $gccm -O2 pidigits.c -lgmp" a.out 10000 188 run 'gccgo -O2 pidigits.go' a.out -n 10000 189 run 'gc pidigits' $O.out -n 10000 190 run 'gc_B pidigits' $O.out -n 10000 191 } 192 193 threadring() { 194 runonly echo 'threadring 50000000' 195 run "gcc $gccm -O2 threadring.c -lpthread" a.out 50000000 196 run 'gccgo -O2 threadring.go' a.out -n 50000000 197 run 'gc threadring' $O.out -n 50000000 198 } 199 200 chameneos() { 201 runonly echo 'chameneos 6000000' 202 run "gcc $gccm -O2 chameneosredux.c -lpthread" a.out 6000000 203 run 'gccgo -O2 chameneosredux.go' a.out 6000000 204 run 'gc chameneosredux' $O.out 6000000 205 } 206 207 case $# in 208 0) 209 run="fasta revcomp nbody binarytree fannkuch regexdna spectralnorm knucleotide mandelbrot meteor pidigits threadring chameneos" 210 ;; 211 *) 212 run=$* 213 esac 214 215 for i in $run 216 do 217 $i 218 runonly echo 219 done