From aed9762638b9b619b6239367c9368bfa79096cf0 Mon Sep 17 00:00:00 2001 From: ChaiShushan Date: Fri, 9 May 2014 14:34:50 -0700 Subject: [PATCH] test/bench/shootout: support windows 1. fix executable extension (a.out -> a.exe). 2. fix pthread build error on mingw 3. if depends lib messing, skip the test LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://golang.org/cl/100210043 --- test/bench/shootout/threadring.c | 12 ++- test/bench/shootout/timing.sh | 157 ++++++++++++++++++------------- 2 files changed, 105 insertions(+), 64 deletions(-) diff --git a/test/bench/shootout/threadring.c b/test/bench/shootout/threadring.c index a518134ba6..606db71dc9 100644 --- a/test/bench/shootout/threadring.c +++ b/test/bench/shootout/threadring.c @@ -41,8 +41,12 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#define THREADS (503) +// PTHREAD_STACK_MIN undeclared on mingw +#ifndef PTHREAD_STACK_MIN +#define PTHREAD_STACK_MIN 65535 +#endif +#define THREADS (503) struct stack { char x[PTHREAD_STACK_MIN]; @@ -94,7 +98,13 @@ int main(int argc, char **argv) pthread_mutex_init(mutex + i, NULL); pthread_mutex_lock(mutex + i); +#if defined(__MINGW32__) || defined(__MINGW64__) + pthread_attr_setstackaddr(&stack_attr, &stacks[i]); + pthread_attr_setstacksize(&stack_attr, sizeof(struct stack)); +#else pthread_attr_setstack(&stack_attr, &stacks[i], sizeof(struct stack)); +#endif + pthread_create(&cthread, &stack_attr, thread, (void*)(uintptr_t)i); } diff --git a/test/bench/shootout/timing.sh b/test/bench/shootout/timing.sh index 2db895c263..a06c326c3e 100755 --- a/test/bench/shootout/timing.sh +++ b/test/bench/shootout/timing.sh @@ -18,6 +18,33 @@ case "$O" in gccm=-m64;; esac +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 + PATH=.:$PATH havegccgo=false @@ -34,11 +61,11 @@ X-test) esac gc() { - $GC $1.go; $LD $1.$O + $GC $1.go; $LD -o $O.$EXE $1.$O } gc_B() { - $GC -B $1.go; $LD $1.$O + $GC -B $1.go; $LD -o $O.$EXE $1.$O } runonly() { @@ -86,122 +113,126 @@ run() { fasta() { runonly echo 'fasta -n 25000000' - run "gcc $gccm -O2 fasta.c" a.out 25000000 - run 'gccgo -O2 fasta.go' a.out -n 25000000 #commented out until WriteString is in bufio - run 'gc fasta' $O.out -n 25000000 - run 'gc_B fasta' $O.out -n 25000000 + 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 + run 'gc fasta' $O.$EXE -n 25000000 + run 'gc_B fasta' $O.$EXE -n 25000000 } revcomp() { runonly gcc -O2 fasta.c - runonly a.out 25000000 > x + runonly a.$EXE 25000000 > x runonly echo 'reverse-complement < output-of-fasta-25000000' - run "gcc $gccm -O2 reverse-complement.c" a.out < x - run 'gccgo -O2 reverse-complement.go' a.out < x - run 'gc reverse-complement' $O.out < x - run 'gc_B reverse-complement' $O.out < x + run "gcc $gccm -O2 reverse-complement.c" a.$EXE < x + run 'gccgo -O2 reverse-complement.go' a.$EXE < x + run 'gc reverse-complement' $O.$EXE < x + run 'gc_B reverse-complement' $O.$EXE < x rm x } nbody() { runonly echo 'nbody -n 50000000' - run "gcc $gccm -O2 nbody.c -lm" a.out 50000000 - run 'gccgo -O2 nbody.go' a.out -n 50000000 - run 'gc nbody' $O.out -n 50000000 - run 'gc_B nbody' $O.out -n 50000000 + run "gcc $gccm -O2 nbody.c -lm" a.$EXE 50000000 + run 'gccgo -O2 nbody.go' a.$EXE -n 50000000 + run 'gc nbody' $O.$EXE -n 50000000 + run 'gc_B nbody' $O.$EXE -n 50000000 } binarytree() { runonly echo 'binary-tree 15 # too slow to use 20' - run "gcc $gccm -O2 binary-tree.c -lm" a.out 15 - run 'gccgo -O2 binary-tree.go' a.out -n 15 - run 'gccgo -O2 binary-tree-freelist.go' a.out -n 15 - run 'gc binary-tree' $O.out -n 15 - run 'gc binary-tree-freelist' $O.out -n 15 + 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 + run 'gc binary-tree' $O.$EXE -n 15 + run 'gc binary-tree-freelist' $O.$EXE -n 15 } fannkuch() { runonly echo 'fannkuch 12' - run "gcc $gccm -O2 fannkuch.c" a.out 12 - run 'gccgo -O2 fannkuch.go' a.out -n 12 - run 'gccgo -O2 fannkuch-parallel.go' a.out -n 12 - run 'gc fannkuch' $O.out -n 12 - run 'gc fannkuch-parallel' $O.out -n 12 - run 'gc_B fannkuch' $O.out -n 12 + 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 + run 'gc fannkuch' $O.$EXE -n 12 + run 'gc fannkuch-parallel' $O.$EXE -n 12 + run 'gc_B fannkuch' $O.$EXE -n 12 } regexdna() { runonly gcc -O2 fasta.c - runonly a.out 100000 > x + runonly a.$EXE 100000 > x runonly echo 'regex-dna 100000' - run "gcc $gccm -O2 regex-dna.c -lpcre" a.out x # should be using 25000000 + runonly a.$EXE 1000000 > x # should be using 25000000 runonly echo 'k-nucleotide 1000000' - if [ $mode = run ]; then - run "gcc -O2 k-nucleotide.c $(pkg-config glib-2.0 --cflags --libs)" a.out