Python transpiler chain → 11l → C ++[для ускорения Python-кода и не только]
3r33800. 3r33818.
3r3r6806. 3r33800. 3r33818.
Replacing the "slices" slices on the ranks ranges
3r33818.
3r33818. 3r3804. Python 3r3807. 3r33818. 3r3804. 11l 3r3807. 3r33818. 3r3809. 3r33818.
3r33818. 3r3804. 3r3667. 3r3658. s[-1]3r33818. s[-2]3r33818. s[:-1]3r33818. s[1:]3r33818. s[:1:]3r33818. s[1:2]3r33818. s[::2]3r33818. s[3:10:2]3r33818. s[3:10:]3r33818. 3r3673.
3r33818. 3r3804. 3r3667. 3r3658. s.last
s[(len)-2]3r33818. s[0<(len)-1]3r33818. s[1]3r33818. s[0<1]3r33818. s[1<2]3r33818. s[(0).step(2)]3r33818. s[(3<10).step(2)]3r33818. s[3<10]3r33818. 3r3673.
3r33818. 3r3809. 3r33818. 3r33811. Explicit indication for indexing from the end of the array
s[(len)-2]3r3673. instead of just 3r3638. s[-2]3r3673. needed to eliminate the following errors: 3r30000. 3r33818.
3r33818. When you want for example to get the previous character on 3r3638. s[i-1]3r3673. , but if i = ? this /this record instead of an error will silently return the last character of the string [и я на практике сталкивался с такой ошибкой — коммит]3r3772. . 3r33818. Expression 3r3638. s[i:]3r3673. after 3r3638. i = s.find (":")
will work incorrectly when the character is not found in line [вместо ‘‘часть строки начиная с первого символа :
и далее’’ будет взят последний символ строки]3r3772. (and generally, return 3r3633. -1 function 3r3638. find () 3r3672. In Python, I consider it also wrong 3r3771.[следует возвращать null/None [а если требуется -1, то следует писать явно: i = s.find(":") ?? -1
]3rr77772. 3r3771. 3r33818. Record 3r3638. s[-n:]3r3673. for 3r3638. n the last characters of the string will not work correctly when n = 0. 3r33818. 3r33800. 3r33818. Chains of comparison operators
3r33800. 3r33818. At first glance, it’s an outstanding feature of the Python language, but in practice it can easily be discarded /dispensed with by the operator 3r3638. in and ranges: 3r30000. 3r33818.- 3r33818.
- 3r337. 3r33737. In all places where I met Python's list comprehension, you can easily get away with the functions `filter ()` and `map ()`. 3r33712. 3r33737. 3r3667. 3r3658. dirs[:]=[d for d in dirs if d[0]! = '.' and d! = exclude_dir]
dirs[:]= filter (lambda d: d[0]! = '.' and d! = exclude_dir, dirs)
3r33818. '[' + ', '.join(python_types_to_11l[ty]for ty in self.type_args) + ']'
'[' + ', '.join(map(lambda ty: python_types_to_11l[ty], self.type_args)) + ']'
3r33818. # Nested list comprehension:
matrix =[
[1, 2, 3, 4], 3r33818.[5, 6, 7, 8], 3r33818.[9, 10, 11, 12], 3r33818. ]3r33818.[[row[i]for row in matrix]for i in range (4)]
list (map (lambda i: list (map (lambda row: row[i], matrix)), range (4)))
3r3673. 3r33838. 3r33838. 3r33818. - 3r337. 3r33737. `filter ()` and `map ()` in 11l look prettier than in Python [/b] 3r33737. 3r3667. 3r3668. dirs[:]= filter (lambda d: d[0]! = '.' and d! = exclude_dir, dirs)
dirs = dirs.filter (d -> d[0]! = ‘.’ & d! = @ exclude_dir)
3r33818. '[' + ', '.join(map(lambda ty: python_types_to_11l[ty], self.type_args)) + ']'
‘W2w2w241. ) .join (‘,’)) ‘]’ 3r3-3818. 3r33818. outfile.write ("n" .join (x[1]for x in fileslist if x[0]))
outfile.write ("n" .join (map (lambda x: x[1], filter (lambda x: x[0], fileslist))))
outfile.write (fileslist.filter (x -> x[0]) .map (x -> x[1]) .join ("n"))
3r3673. 3r33838. 3r33838. and therefore the need for list comprehensions in 11l actually disappears [замена list comprehension наfilter()
и/илиmap()
выполняется в процессе преобразования Python-кода в 11l автоматически]3r3772. . 3r33818.
Convert the if-elif-else chain to switch
3r33800. 3r33818. While Python does not contain a switch statement, this is one of the most beautiful constructions in the 11l language, and so I decided to insert the switch automatically:3r33818. с точки зрения производительности]3r3772. but it is very convenient. 3r33800. 3r33818. 3r33800. 3r33818. In 11l, the same line corresponding to this line is 3r3771.[и полученная транспайлером Python → 11l]3r3772. Record not only comfortable [впрочем, не настолько изящная как в Python]3r3772. , but also fast:
3r33818. 3r3667. 3r3668. var tag = switch prev_char () {‘*’ {‘b’}; ‘_’ {‘U’}; ‘-’ {‘s’}; ‘~’ {‘I’}} 3-333818. 3r3673. 3r33800. 3r33818. The above line is shipped to: 3r30000. 3r33818. 3r3667. 3r3668. auto tag =[&](const auto & a) {return a == u '*'? u'b'_C: a == u'_ '? u'u'_C: a == u'- '? u's'_C: a == u '~'? u'i'_C: throw KeyError (a);} (prev_char ()); 3r33818. 3r3673. [Вызов лямбда-функции компилятор C++ встроитinline в процессе оптимизации и останется только цепочка операторов
?/:
.]3r3772. 3r33800. 3r33818. 3r33800. 3r33818. In the case when assignment is made to a variable, the dictionary is left as it is: 3r30000. 3r33818. Capture Ca pture of external variables [/h3] 3r33800. 3r33818. In Python, to indicate that a variable is not local, but must be taken outside [от текущей функции]3r3772. , the keyword nonlocal is used.[в противном случае к примеру found = True
будет трактоваться как создание новой локальной переменной found
, а не присваивание значения уже существующей внешней переменной]3r3772. . 3r33800. 3r33818. In 11l, the prefix @: 3r33800 is used for this. 3r33818.
[посредством ключевого слова global]3r3772. , then you get an inconspicuous bug:3r33818. [справа]3r3772. unlike python [слева]3r3772. will generate an error at compile time ‘undeclared variable
break_label_index
’. 3r33800. 3r33818. 3r33800. 3r33818. The index /number of the current item in the
container. 3r33800. 3r33818. I always forget the order of the variables that the Python function returns enumerate
{first comes the value, and then the index or vice versa}. Similar behavior in Ruby - 3r3638. each.with_index - it is much easier to remember: with index means that index comes after value, and not before. But in 11l, the logic is even easier to remember: 3r30000. 3r33818.3r33818.
3r33818. 3r3804. Python 3r3807. 3r33818. 3r3804. 11l 3r3807. 3r33818. 3r3809. 3r33818.
3r33818. 3r3804. 3r3667. 3r3658. items =['A', 'B', 'C']3r33818. for index, item in enumerate (items):
print (str (index) + '=' + item)
3r3673.
3r33818. 3r3804. 3r3667. 3r3668. var items =[‘A’, ‘B’, ‘C’]3r33818. loop (item) items
print (loop.index ‘=’ item)
3r3673.
3r33818. 3r3809. 3r33818. 3r33811. 3r33800. 3r33818.
Performance 3r38282. 3r33800. 3r33818. As a test used
a program for converting pc markup to HTML [/leech] , and the source data is taken source articles on pc markup
[так как эта статья на данный момент — самая большая из написанных на пк-разметке]3r3772. , and repeated 10 times, that is, a 488 KB file is obtained from a 48.8 kilobyte article. 3r33800. 3r33818. 3r33800. 3r33818. Here is a diagram showing how many times the corresponding method of executing Python code is faster than the original implementation of 3r3771.[CPython]3r3772. : 3r33800. 3r33818.

[это время включает в себя полноценный [т.е. не просто работу Shed Skin but it does not support local functions. 3r33800. 3r33818. Numba also failed (yields an error ‘Use of unknown opcode LOAD_BUILD_CLASS’). 3r33800. 3r33818. 3r33737. Here is the archive 3r3806. with the program used to compare performance 3r3771.[под Windows]3r3772. (Requires installed Python 3.6 or higher and the following Python packages: pywin3? cython). 3r33800. 3r33818. 3r33838. 3r33838. 3r33800. 3r33818. Python source and output of Python transpilers → 11l and 11l → C ++:
3r33818.
3r33818.
3r33818. 3r3804. Python
3r33818. 3r3804. Generated 11l 3r33800. 3r33818. (with keywords instead of letters)
3r33818. 3r3804. 11l 3r3806. 3r33800. 3r33818. (with letters)
3r33818. 3r3804. 3r3805. Generated C ++
3r33818. 3r3809. 3r33818. 3r33811. 3r33838. 3r33818. 3r33818. 3r33818. 3r33816. ! function (e) {function t (t, n) {if (! (n in e)) {for (var, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r33817. 3r33818. 3r33838.
It may be interesting
weber
Author28-11-2018, 07:38
Publication DatePython / Abnormal programming / C#
Category- Comments: 1
- Views: 1 527
Comments
I know your aptitude on this. I should say we ought to have an online discourse on this. Composing just remarks will close the talk straight away! What's more, will confine the advantages from this data. 審計 報告
Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. There tend to be not many people who can certainly write not so simple posts that artistically. Continue the nice writing香港利得稅
I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. 먹튀
If you are looking for more information about flat rate locksmith Las Vegas check that right away. best front load washing machine in india
Here we introduce our top coupons that will help you for online shopping at discountable prices.Revounts bring you the best deals that slash the bills.If you are intrested in online shopping and want to save your savings then visit our site for best experience.