Сегодня пересобирал CPython 3.7 разными компиляторами под CentOS 7 в попытке приподнять его производительность.
Удивительно, но первая версия Python 3.7, собранная мной ранее со всеми оптимизациями, прогоняла наши тесты неприлично медленнее, чем Python 2.7 из поставки CentOS 7.
Python37, собранный мной с GCC 4.8.0 (CentOS bundled)
Параметры сборки: -march=x86_64 --enable-optimisations --with-lto
Ran 203 tests in 380.523s
Python27, входящий в стандартную поставку CentOS 7
Ran 203 tests in 288.164s
Вот что получилось из этого эксперимента.
Python37 with GCC 9.0.1 (built from scratch)
-march=native
Ran 203 tests in 239.704s
Ran 203 tests in 241.226s
Python37 with GCC 9.0.1 (built from scratch)
-march=x86_64
Ran 203 tests in 240.177s
Ran 203 tests in 237.242s
Python37 with GCC 9.0.1 (built from scratch)
-march=native --enable-optimisations --with-lto
Ran 203 tests in 224.331s
Ran 203 tests in 222.550s
Python37 with GCC 9.0.1 (built from scratch)
-march=x86_64 --enable-optimisations --with-lto
Ran 203 tests in 282.700s
Ran 203 tests in 285.279s
Python37 with GCC 8.3.1 (from devtoolset-8-gcc)
-march=x86_64
Ran 203 tests in 240.688s
Python37 with GCC 8.3.1 (from devtoolset-8-gcc)
-march=native --enable-optimisations --with-lto
Ran 203 tests in 225.621s
Python37 with GCC 8.3.1 (from devtoolset-8-gcc)
-march=x86_64 --enable-optimisations --with-lto
Ran 203 tests in 223.487s
Ran 203 tests in 227.743s
Python37 with GCC 4.8.0 (bundled with CentOS)
-march=x86_64 --enable-optimisations --with-lto
Ran 203 tests in 380.523s
Python37 with CLang 5.0 (from llvm-toolset-7)
--enable-optimisations --with-lto
Ran 203 tests in 310.007s
Python27 bundled with CentOS 7
Ran 203 tests in 288.164s
Какие выводы можно сделать?
- Чем новее у Вас компилятор, тем лучше! GCC-8 вполне норм.
- Если можете использовать -march=native, используйте! Оно реально даёт прирост совместно с PGO.
- PGO и LTO – это хорошо, но свежий компилятор важнее!