GHC 2018-01-21

1 comment.

, https://git.io/vN2EP in Homebrew/homebrew-core
I simplified the test (drop inconsequential threads, and make it run faster), and ran benchmarks against pythons compiled with different versions of llvm (`llvm`, `llvm@4`, `[email protected]`):

```py
import time

def f(n):
    while n > 0:
        n -= 1

start = time.time()
f(50000000)
stop = time.time()
print(stop - start)
```

```console
$ ./bench
/usr/bin/python2.7
2.0681180954

/usr/local/bin/python2.7
7.83331799507

dist/python27-apple-clang-900.0.38/bin/python2.7
8.31766891479

dist/python27-clang-3.9.1/bin/python2.7
9.04964900017

dist/python27-clang-4.0.1/bin/python2.7
8.45596003532

dist/python27-clang-5.0.1/bin/python2.7
1.64623904228

/usr/local/bin/python3.6
3.268683910369873

dist/python-master-apple-clang-900.0.38/bin/python3
3.1528470516204834

dist/python-master-clang-3.9.1/bin/python3
3.045478105545044

dist/python-master-clang-4.0.1/bin/python3
2.9801700115203857

dist/python-master-clang-5.0.1/bin/python3
3.0513551235198975

```

Not sure what's the problem. I suggest creating a [bpo](https://bugs.python.org/) issue to solicit opinions from Python core developers.

Here is the complete script to set up my benchmarking environment and run the benchmarks:

```zsh
#!/usr/bin/env zsh
setopt xtrace errexit

ROOTDIR=/tmp/python-benchmark

brew install python2 python3 llvm llvm@4 [email protected]

mkdir -p $ROOTDIR
cd $ROOTDIR
[[ -d cpython ]] || git clone https://github.com/python/cpython.git

cd cpython

# build <CC> <prefix>
build () {
    [[ -d $2 ]] && return
    CC=$1 ./configure --prefix=$2
    make install -j8
    make distclean
}

git checkout 2.7
build /usr/bin/clang $ROOTDIR/dist/python27-apple-clang-900.0.38
build /usr/local/Cellar/llvm/5.0.1/bin/clang-5.0 $ROOTDIR/dist/python27-clang-5.0.1
build /usr/local/Cellar/llvm@4/4.0.1/bin/clang-4.0 $ROOTDIR/dist/python27-clang-4.0.1
build /usr/local/Cellar/[email protected]/3.9.1_1/bin/clang-3.9 $ROOTDIR/dist/python27-clang-3.9.1

git checkout master
build /usr/bin/clang $ROOTDIR/dist/python27-apple-clang-900.0.38
build /usr/local/Cellar/llvm/5.0.1/bin/clang-5.0 $ROOTDIR/dist/python-master-clang-5.0.1
build /usr/local/Cellar/llvm@4/4.0.1/bin/clang-4.0 $ROOTDIR/dist/python-master-clang-4.0.1
build /usr/local/Cellar/[email protected]/3.9.1_1/bin/clang-3.9 $ROOTDIR/dist/python-master-clang-3.9.1

cd ..

[[ -f test.py ]] || cat >test.py <<'EOF'
import time

def f(n):
    while n > 0:
        n -= 1

start = time.time()
f(50000000)
stop = time.time()
print(stop - start)
EOF

[[ -f bench ]] || cat >bench <<'EOF'
#!/usr/bin/env zsh

pythons=(
    /usr/bin/python2.7
    /usr/local/bin/python2.7
    dist/python27-apple-clang-900.0.38/bin/python2.7
    dist/python27-clang-3.9.1/bin/python2.7
    dist/python27-clang-4.0.1/bin/python2.7
    dist/python27-clang-5.0.1/bin/python2.7
    /usr/local/bin/python3.6
    dist/python-master-apple-clang-900.0.38/bin/python3
    dist/python-master-clang-3.9.1/bin/python3
    dist/python-master-clang-4.0.1/bin/python3
    dist/python-master-clang-5.0.1/bin/python3
)

for python in $pythons; do
    echo $python
    $python test.py
    echo
done
EOF
chmod +x bench

./bench
```