Python Fast Monochrome Bitmap

I want to implement a monochrome grid of 1024x1024, I need to read data from any cell and insert rectangles with different sizes, I tried to make a list in a list (and use it as a 2d array), what I found is a list of booleans is slower than a list of integers of numbers .... I tried a 1d list and it was slower than 2d, numpy slower about 10 times larger than the standard python list, the fastest way I found is with PIL and the monochromatic bitmap used with "load", but I want it to run much faster, by I tried to compile it using shedskin, but, unfortunately, there is no support for the pilots, do you know any way to implement such a grid rapidly, without rewriting it in c or C ++?

+3
source share
3 answers

Raph suggestin using an array is good, but it will not help on CPython, in fact I expect it to be 10-15% slower, however if you use it on PyPy (http://pypy.org/) I expect excellent results .

+2
source

One thing I could suggest is to use the Python class built-in class (http://docs.python.org/library/array.html) with type "B". Encoding will be easier if you use one byte per pixel, but if you want to save memory, you can pack 8 per byte and access it using your own bit manipulation.

0
source

I would consider Cython , which translates Python to C, which is easily compiled (or compiled for you if you use distutils). Just compiling your code in Cython will make it faster for something like that, but you can get much greater speedups by adding a few cdef statements. If you use it with Numpy , you can quickly access Numpy arrays. The speedup can be pretty big using Cython this way. However, it would be easier for you to help if you provided some sample code.

0
source

Source: https://habr.com/ru/post/1784317/


All Articles