KEMBAR78
Commit ускоривший python 2.7.11 на 30% и новое в python 3.5 | PDF
Commit ускоривший
Python 2.7 на 30%
и
новое в Python 3.5
sapronov.alexander92@gmail.com
@sapronovalex92
pynsk.nsk@gmail.com
vk.com/pynsk
facebook.com/PyNskCom
@py_nsk
Александр Сапронов:
Python 2.7.11
Vamsi Parasa of the Server Scripting Languages Optimization team at Intel posted
a patch to change the switch statement that executes Python bytecode in the
CPython interpreter to use computed gotos instead.
(http://article.gmane.org/gmane.comp.python.devel/153401)
Python 2.7.11
Vamsi Parasa of the Server Scripting Languages Optimization team at Intel posted
a patch to change the switch statement that executes Python bytecode in the
CPython interpreter to use computed gotos instead.
(http://article.gmane.org/gmane.comp.python.devel/153401)
computed goto
В отличие от switch-case: Не производит граничных проверок
#define OP_HALT 0x0
#define OP_INC 0x1
int interp_switch(unsigned char* code, int initval) {
int pc = 0;
int val = initval;
while (1) {
switch (code[pc++]) {
case OP_HALT:
return val;
case OP_INC:
val++;
break;
default:
return val;
}
}
}
computed goto
В отличие от switch-case: Не производит граничных проверок
#define OP_HALT 0x0
#define OP_INC 0x1
int interp_switch(unsigned char* code, int initval) {
int pc = 0;
int val = initval;
while (1) {
switch (code[pc++]) {
case OP_HALT:
return val;
case OP_INC:
val++;
break;
default:
return val;
}
}
}
int interp_cgoto(unsigned char* code, int initval) {
static void* dispatch_table[] = {&&do_halt, &&do_inc};
#define DISPATCH() goto *dispatch_table[code[pc++]]
int pc = 0;
int val = initval;
DISPATCH();
while (1) {
do_halt:
return val;
do_inc:
val++;
DISPATCH();
}
}
computed goto
В отличие от switch-case: CPU может лучше прогнозировать ветвления
Подробно про computed goto:
http://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables
Модуль предсказания переходов:
устройство, входящее в состав микропроцессоров, имеющих
конвейерную архитектуру, предсказывающее, будет ли
выполнен условный переход в исполняемой программе.
Новое в Python 3.5 - PEP 478
● PEP 441 , improved Python zip application support
● PEP 448 , additional unpacking generalizations
● PEP 461 , "%-formatting" for bytes and bytearray objects
● PEP 465 , a new operator ("@") for matrix multiplication
● PEP 471 , os.scandir(), a fast new directory traversal function
● PEP 475 , adding support for automatic retries of interrupted system calls
● PEP 479 , change StopIteration handling inside generators
● PEP 484 , the typing module, a new standard for type annotations
● PEP 485 , math.isclose(), a function for testing approximate equality
● PEP 486 , making the Widnows Python launcher aware of virtual environments
● PEP 488 , eliminating .pyo files
● PEP 489 , a new and improved mechanism for loading extension modules
● PEP 492 , coroutines with async and await syntax
PEP 448 - additional unpacking generalizations
>>> print(*[1], *[2], 3)
1 2 3
>>> dict(**{'x': 1}, y=2, **{'z': 3})
{'x': 1, 'y': 2, 'z': 3}
>>> *range(4), 4
(0, 1, 2, 3, 4)
>>> [*range(4), 4]
[0, 1, 2, 3, 4]
>>> {*range(4), 4}
{0, 1, 2, 3, 4}
>>> {'x': 1, **{'y': 2}}
{'x': 1, 'y': 2}
>>> {'x': 1, **{'x': 2}}
{'x': 2}
>>> {**{'x': 2}, 'x': 1}
{'x': 1}
PEP 484 - the typing module, a new standard
for type annotations
def greeting(name: str) -> str:
return 'Hello ' + name
from typing import *
T = TypeVar('T')
def filter(function: Optional[Callable[[T], Any]],
iterable: Iterable[T]) -> Iterator[T]:
...
Было
Стало
PEP 492 - coroutines with async and await syntax
async def read_data(db):
pass
async def read_data(db):
data = await db.fetch('SELECT ...')
Новые ключевые слова:
async и await
11
sapronov.alexander92@gmail.com
@sapronovalex92
pynsk.nsk@gmail.com
vk.com/pynsk
facebook.com/PyNskCom
@py_nsk
PyNSK контакты: Мои контакты:
ru.linkedin.com/in/alexsapronov
Питоны кончились…
Вопросы?

Commit ускоривший python 2.7.11 на 30% и новое в python 3.5

  • 1.
    Commit ускоривший Python 2.7на 30% и новое в Python 3.5 sapronov.alexander92@gmail.com @sapronovalex92 pynsk.nsk@gmail.com vk.com/pynsk facebook.com/PyNskCom @py_nsk Александр Сапронов:
  • 2.
    Python 2.7.11 Vamsi Parasaof the Server Scripting Languages Optimization team at Intel posted a patch to change the switch statement that executes Python bytecode in the CPython interpreter to use computed gotos instead. (http://article.gmane.org/gmane.comp.python.devel/153401)
  • 3.
    Python 2.7.11 Vamsi Parasaof the Server Scripting Languages Optimization team at Intel posted a patch to change the switch statement that executes Python bytecode in the CPython interpreter to use computed gotos instead. (http://article.gmane.org/gmane.comp.python.devel/153401)
  • 4.
    computed goto В отличиеот switch-case: Не производит граничных проверок #define OP_HALT 0x0 #define OP_INC 0x1 int interp_switch(unsigned char* code, int initval) { int pc = 0; int val = initval; while (1) { switch (code[pc++]) { case OP_HALT: return val; case OP_INC: val++; break; default: return val; } } }
  • 5.
    computed goto В отличиеот switch-case: Не производит граничных проверок #define OP_HALT 0x0 #define OP_INC 0x1 int interp_switch(unsigned char* code, int initval) { int pc = 0; int val = initval; while (1) { switch (code[pc++]) { case OP_HALT: return val; case OP_INC: val++; break; default: return val; } } } int interp_cgoto(unsigned char* code, int initval) { static void* dispatch_table[] = {&&do_halt, &&do_inc}; #define DISPATCH() goto *dispatch_table[code[pc++]] int pc = 0; int val = initval; DISPATCH(); while (1) { do_halt: return val; do_inc: val++; DISPATCH(); } }
  • 6.
    computed goto В отличиеот switch-case: CPU может лучше прогнозировать ветвления Подробно про computed goto: http://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables Модуль предсказания переходов: устройство, входящее в состав микропроцессоров, имеющих конвейерную архитектуру, предсказывающее, будет ли выполнен условный переход в исполняемой программе.
  • 7.
    Новое в Python3.5 - PEP 478 ● PEP 441 , improved Python zip application support ● PEP 448 , additional unpacking generalizations ● PEP 461 , "%-formatting" for bytes and bytearray objects ● PEP 465 , a new operator ("@") for matrix multiplication ● PEP 471 , os.scandir(), a fast new directory traversal function ● PEP 475 , adding support for automatic retries of interrupted system calls ● PEP 479 , change StopIteration handling inside generators ● PEP 484 , the typing module, a new standard for type annotations ● PEP 485 , math.isclose(), a function for testing approximate equality ● PEP 486 , making the Widnows Python launcher aware of virtual environments ● PEP 488 , eliminating .pyo files ● PEP 489 , a new and improved mechanism for loading extension modules ● PEP 492 , coroutines with async and await syntax
  • 8.
    PEP 448 -additional unpacking generalizations >>> print(*[1], *[2], 3) 1 2 3 >>> dict(**{'x': 1}, y=2, **{'z': 3}) {'x': 1, 'y': 2, 'z': 3} >>> *range(4), 4 (0, 1, 2, 3, 4) >>> [*range(4), 4] [0, 1, 2, 3, 4] >>> {*range(4), 4} {0, 1, 2, 3, 4} >>> {'x': 1, **{'y': 2}} {'x': 1, 'y': 2} >>> {'x': 1, **{'x': 2}} {'x': 2} >>> {**{'x': 2}, 'x': 1} {'x': 1}
  • 9.
    PEP 484 -the typing module, a new standard for type annotations def greeting(name: str) -> str: return 'Hello ' + name from typing import * T = TypeVar('T') def filter(function: Optional[Callable[[T], Any]], iterable: Iterable[T]) -> Iterator[T]: ... Было Стало
  • 10.
    PEP 492 -coroutines with async and await syntax async def read_data(db): pass async def read_data(db): data = await db.fetch('SELECT ...') Новые ключевые слова: async и await
  • 11.
    11 sapronov.alexander92@gmail.com @sapronovalex92 pynsk.nsk@gmail.com vk.com/pynsk facebook.com/PyNskCom @py_nsk PyNSK контакты: Моиконтакты: ru.linkedin.com/in/alexsapronov Питоны кончились… Вопросы?