Posted at

Pythonインストール時の最適化

More than 1 year has passed since last update.

Python-3.6.3 のインストールにおいて、--enable-optimizations オプションがどれくらい効いているのか、CPU が Core i7-8700K のマシンで比較。

$ ./configure

$ make
$ ./python Tools/pybench/pybench.py
-------------------------------------------------------------------------------
PYBENCH 2.1
-------------------------------------------------------------------------------
* using CPython 3.6.3 (default, Dec 15 2017, 15:49:30) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
* disabled garbage collection
* system check interval set to maximum: 2147483647
* using timer: time.perf_counter
* timer: resolution=1e-09, implementation=clock_gettime(CLOCK_MONOTONIC)

Calibrating tests. Please wait... done.

Running 10 round(s) of the suite at warp factor 10:

* Round 1 done in 1.161 seconds.
* Round 2 done in 1.161 seconds.
* Round 3 done in 1.164 seconds.
* Round 4 done in 1.159 seconds.
* Round 5 done in 1.160 seconds.
* Round 6 done in 1.159 seconds.
* Round 7 done in 1.166 seconds.
* Round 8 done in 1.159 seconds.
* Round 9 done in 1.163 seconds.
* Round 10 done in 1.162 seconds.

-------------------------------------------------------------------------------
Benchmark: 2017-12-15 15:51:28
-------------------------------------------------------------------------------

Rounds: 10
Warp: 10
Timer: time.perf_counter

Machine Details:
Platform ID: Linux-3.10.0-693.11.1.el7.x86_64-x86_64-with-centos-7.4.1708-Core
Processor: x86_64

Python:
Implementation: CPython
Executable: /home/ichy/project/daddy/tmp/Python-3.6.3/python
Version: 3.6.3
Compiler: GCC 4.8.5 20150623 (Red Hat 4.8.5-16)
Bits: 64bit
Build: Dec 15 2017 15:49:30 (#default)
Unicode: UCS4

Test minimum average operation overhead
-------------------------------------------------------------------------------
BuiltinFunctionCalls: 31ms 31ms 0.06us 0.062ms
BuiltinMethodLookup: 15ms 15ms 0.01us 0.069ms
CompareFloats: 18ms 18ms 0.02us 0.079ms
CompareFloatsIntegers: 22ms 22ms 0.02us 0.059ms
CompareIntegers: 29ms 29ms 0.02us 0.119ms
CompareInternedStrings: 16ms 16ms 0.01us 0.313ms
CompareLongs: 17ms 17ms 0.02us 0.069ms
CompareStrings: 14ms 14ms 0.01us 0.202ms
ComplexPythonFunctionCalls: 25ms 25ms 0.13us 0.100ms
ConcatStrings: 18ms 18ms 0.04us 0.117ms
CreateInstances: 27ms 27ms 0.24us 0.097ms
CreateNewInstances: 20ms 20ms 0.24us 0.077ms
CreateStringsWithConcat: 36ms 37ms 0.04us 0.198ms
DictCreation: 17ms 17ms 0.04us 0.079ms
DictWithFloatKeys: 23ms 23ms 0.03us 0.151ms
DictWithIntegerKeys: 20ms 20ms 0.02us 0.199ms
DictWithStringKeys: 18ms 18ms 0.02us 0.201ms
ForLoops: 14ms 14ms 0.55us 0.009ms
IfThenElse: 16ms 16ms 0.01us 0.149ms
ListSlicing: 23ms 23ms 1.66us 0.013ms
NestedForLoops: 19ms 19ms 0.01us 0.001ms
NestedListComprehensions: 22ms 22ms 1.85us 0.020ms
NormalClassAttribute: 59ms 60ms 0.05us 0.105ms
NormalInstanceAttribute: 24ms 24ms 0.02us 0.105ms
PythonFunctionCalls: 22ms 22ms 0.07us 0.059ms
PythonMethodCalls: 30ms 30ms 0.14us 0.035ms
Recursion: 35ms 35ms 0.70us 0.099ms
SecondImport: 7ms 7ms 0.07us 0.039ms
SecondPackageImport: 7ms 7ms 0.07us 0.039ms
SecondSubmoduleImport: 16ms 16ms 0.16us 0.039ms
SimpleComplexArithmetic: 13ms 13ms 0.02us 0.079ms
SimpleDictManipulation: 37ms 38ms 0.03us 0.099ms
SimpleFloatArithmetic: 15ms 15ms 0.01us 0.119ms
SimpleIntFloatArithmetic: 15ms 15ms 0.01us 0.119ms
SimpleIntegerArithmetic: 15ms 15ms 0.01us 0.119ms
SimpleListComprehensions: 18ms 18ms 1.52us 0.019ms
SimpleListManipulation: 18ms 18ms 0.02us 0.129ms
SimpleLongArithmetic: 10ms 10ms 0.02us 0.059ms
SmallLists: 22ms 22ms 0.03us 0.079ms
SmallTuples: 27ms 27ms 0.05us 0.089ms
SpecialClassAttribute: 55ms 55ms 0.05us 0.105ms
SpecialInstanceAttribute: 24ms 24ms 0.02us 0.107ms
StringMappings: 49ms 49ms 0.20us 0.088ms
StringPredicates: 33ms 33ms 0.05us 0.334ms
StringSlicing: 24ms 25ms 0.04us 0.168ms
TryExcept: 13ms 13ms 0.01us 0.149ms
TryFinally: 20ms 20ms 0.12us 0.080ms
TryRaiseExcept: 8ms 8ms 0.13us 0.079ms
TupleSlicing: 28ms 29ms 0.11us 0.009ms
WithFinally: 25ms 25ms 0.16us 0.079ms
WithRaiseExcept: 23ms 23ms 0.29us 0.099ms
-------------------------------------------------------------------------------
Totals: 1148ms 1161ms

$ ./configure --enable-optimizations

$ make
$ ./python Tools/pybench/pybench.py
-------------------------------------------------------------------------------
PYBENCH 2.1
-------------------------------------------------------------------------------
* using CPython 3.6.3 (default, Dec 15 2017, 16:04:49) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
* disabled garbage collection
* system check interval set to maximum: 2147483647
* using timer: time.perf_counter
* timer: resolution=1e-09, implementation=clock_gettime(CLOCK_MONOTONIC)

Calibrating tests. Please wait... done.

Running 10 round(s) of the suite at warp factor 10:

* Round 1 done in 1.027 seconds.
* Round 2 done in 1.038 seconds.
* Round 3 done in 1.040 seconds.
* Round 4 done in 1.028 seconds.
* Round 5 done in 1.031 seconds.
* Round 6 done in 1.023 seconds.
* Round 7 done in 1.029 seconds.
* Round 8 done in 1.031 seconds.
* Round 9 done in 1.024 seconds.
* Round 10 done in 1.036 seconds.

-------------------------------------------------------------------------------
Benchmark: 2017-12-15 16:06:13
-------------------------------------------------------------------------------

Rounds: 10
Warp: 10
Timer: time.perf_counter

Machine Details:
Platform ID: Linux-3.10.0-693.11.1.el7.x86_64-x86_64-with-centos-7.4.1708-Core
Processor: x86_64

Python:
Implementation: CPython
Executable: /home/ichy/project/daddy/tmp/Python-3.6.3/python
Version: 3.6.3
Compiler: GCC 4.8.5 20150623 (Red Hat 4.8.5-16)
Bits: 64bit
Build: Dec 15 2017 16:04:49 (#default)
Unicode: UCS4

Test minimum average operation overhead
-------------------------------------------------------------------------------
BuiltinFunctionCalls: 26ms 27ms 0.05us 0.064ms
BuiltinMethodLookup: 14ms 14ms 0.01us 0.073ms
CompareFloats: 13ms 13ms 0.01us 0.084ms
CompareFloatsIntegers: 21ms 22ms 0.02us 0.063ms
CompareIntegers: 20ms 20ms 0.01us 0.127ms
CompareInternedStrings: 16ms 16ms 0.01us 0.321ms
CompareLongs: 12ms 12ms 0.01us 0.074ms
CompareStrings: 14ms 14ms 0.01us 0.214ms
ComplexPythonFunctionCalls: 22ms 22ms 0.11us 0.106ms
ConcatStrings: 19ms 19ms 0.04us 0.122ms
CreateInstances: 23ms 24ms 0.21us 0.098ms
CreateNewInstances: 18ms 18ms 0.21us 0.077ms
CreateStringsWithConcat: 27ms 27ms 0.03us 0.212ms
DictCreation: 16ms 16ms 0.04us 0.084ms
DictWithFloatKeys: 22ms 22ms 0.02us 0.159ms
DictWithIntegerKeys: 19ms 19ms 0.02us 0.212ms
DictWithStringKeys: 15ms 16ms 0.01us 0.212ms
ForLoops: 16ms 16ms 0.63us 0.010ms
IfThenElse: 16ms 16ms 0.01us 0.159ms
ListSlicing: 22ms 22ms 1.58us 0.013ms
NestedForLoops: 18ms 18ms 0.01us 0.001ms
NestedListComprehensions: 21ms 22ms 1.83us 0.021ms
NormalClassAttribute: 40ms 41ms 0.03us 0.110ms
NormalInstanceAttribute: 21ms 22ms 0.02us 0.110ms
PythonFunctionCalls: 19ms 20ms 0.06us 0.063ms
PythonMethodCalls: 25ms 25ms 0.11us 0.036ms
Recursion: 31ms 31ms 0.63us 0.106ms
SecondImport: 6ms 6ms 0.06us 0.042ms
SecondPackageImport: 7ms 7ms 0.07us 0.042ms
SecondSubmoduleImport: 14ms 15ms 0.15us 0.042ms
SimpleComplexArithmetic: 15ms 15ms 0.02us 0.084ms
SimpleDictManipulation: 33ms 33ms 0.03us 0.106ms
SimpleFloatArithmetic: 14ms 14ms 0.01us 0.128ms
SimpleIntFloatArithmetic: 15ms 15ms 0.01us 0.127ms
SimpleIntegerArithmetic: 15ms 15ms 0.01us 0.128ms
SimpleListComprehensions: 18ms 18ms 1.50us 0.021ms
SimpleListManipulation: 17ms 17ms 0.01us 0.138ms
SimpleLongArithmetic: 10ms 10ms 0.02us 0.063ms
SmallLists: 20ms 20ms 0.03us 0.084ms
SmallTuples: 22ms 23ms 0.04us 0.095ms
SpecialClassAttribute: 43ms 44ms 0.04us 0.110ms
SpecialInstanceAttribute: 21ms 22ms 0.02us 0.110ms
StringMappings: 44ms 45ms 0.18us 0.089ms
StringPredicates: 30ms 30ms 0.04us 0.336ms
StringSlicing: 21ms 21ms 0.04us 0.178ms
TryExcept: 12ms 12ms 0.01us 0.159ms
TryFinally: 18ms 18ms 0.11us 0.089ms
TryRaiseExcept: 8ms 8ms 0.12us 0.084ms
TupleSlicing: 24ms 25ms 0.10us 0.010ms
WithFinally: 22ms 22ms 0.14us 0.084ms
WithRaiseExcept: 22ms 22ms 0.27us 0.106ms
-------------------------------------------------------------------------------
Totals: 1013ms 1031ms

1161ms が 1031ms に、11% ~ 12% 程度パフォーマンスが向上したと思っていいだろうか。