Just a small test with lists in cython

Overview

Test for lists in cython

Algorithm

  1. create a list of 10^4 lists each with 10^4 floats values (namely: 0.1) - 2 nested for
  2. iterate each list and compute the cumulative product - 2 netsted for

Implementations

  • Julia using Julia objects
  • Rust using Rust objects
  • Pure-python
  • Cython pure-python mode with no annotations
  • Cython pure-python mode with Python annotations
  • Cython pure-python mode with Cython annotations
  • Standard Cython

Setup

  • poetry install --no-root
  • poetry run python setup.py build_ext --inplace
  • poetry run python -c "import julia; julia.install()"

Results

  • poetry run python main.py

Tested on:

  • Intel Core i5-8250U - 64 bits - Quad Core L2 cache: 6 MiB
  • Linux 5.4.105-1-MANJARO x86_64
  • GCC 10.2.0
  • Python 3.9.2
  • Cython 0.29.17
  • Julia 1.6
  • Cargo 1.51
  No annotations Annotations from typing Annotations from cython
Pure Python 11.08
C++ Cython (pure-python mode) 02.25 02.81 02.96
C Cython (pure-python mode) 02.23 02.97 02.91
C Cython (.pyx)
02.77
Julia (pyjulia) 03.50
Julia (pyjulia) parallel 02.11
Rust (Pyo3) parallel before 08.72
Rust (Pyo3) parallel after 29.17

Cython is fast, but none of these methods are able to release the GIL. Moreover, in pure-python mode, Cython effectiveness decreases while using typing annotations. Last but not least, it's hard to understand which solution is better with Cython. The average time is 2.7

Rust is not that fast beacuse it needs to copy data; using Pyo3 objects would probably lead to similar results as cython, but with an added library. Moreover, it's tricky because after having run some code its perfomance decreases.

Numba is still tricky with lists. I tried to use them, but it fails. In my experience, numba lists in nopython mode slows down the code.

Julia is fast (only 30% slower than the average Cython). With multithreading it's even faster than Cython.

Considering echosystem, multithreading and ease of use, Julia is a clear winner here.

Comments
  • Add 1 implementation

    Add 1 implementation

    • Add Nim implementation.

    Steps to try it

    Assuming Linux, assuming you are in the repo root folder.

    • curl https://nim-lang.org/choosenim/init.sh -sSf | sh
    • Add Nim to PATH, using ~/.bashrc, instructions provided by install process.
    • nimble install nimpy
    • nim c -d:danger --out:list_nim.so list_nim.nim
    • python main.py
    opened by juancarlospaco 7
  • Numba

    Numba

    I've done a lot with numba and found it to be a tremendous advantage. I suggest you try to tweak your numba example a bit more. I'd do it myself but I have very little free time right now. I could look into it later if you really give up.

    If there's really something that makes your example code impractical, then I must say that based on my experience, this isn't a representative example and misrepresents numba's value.

    Finally, I'd suggest submitting the problem to the numba team; I would expect them to either fix it or give a solid reason why they don't view it as a problem for the vast majority of use cases.

    opened by garyrob 4
  • Make list_cy more idiomatic

    Make list_cy more idiomatic

    This is a more idiomatic implementation of cy_list, which avoids several performance pitfalls. On my machine, this results in about a 2x improvement in performance. This PR is incompatible with #2; maybe they should be separate tests.

    opened by boothby 4
  • [numba] numba implementation

    [numba] numba implementation

    I've managed to make a numba implementation.

    Before the benchmark, it appends and pops a dummy numba list. Then your functions work as expected. Got idea from the documentation https://numba.pydata.org/numba-doc/dev/reference/pysupported.html#typed-list

    I've also added two an after warm up benchmark for Numba and Julia, as you need to call the functions first for the JIT to compile the functions. This can take half a second or so.

    I ran your benchmarks on my laptop (bar Rust as it was blowing up my RAM XD)

    For 10e3 I got:

    10000.000000171856
    Numba needed time: 0.5606226921081543
    10000.000000171856
    Numba needed time (after compile): 0.04860401153564453
    9999.999999992067
    Numba multi-threading needed time: 0.5958309173583984
    9999.999999992067
    Numba multi-threading needed time (after compile): 0.028712034225463867
    9999.99999999983
    Rust multithreading before needed time: 0.06744837760925293
    10000.000000171856
    Julia needed time: 0.7957050800323486
    10000.000000171856
    Julia needed time (after warm up): 0.05081033706665039
    10000.000000000002
    Julia multi-threading needed time: 0.5844004154205322
    10000.000000000002
    Julia multi-threading needed time (after warm up): 0.024353504180908203
    9999.99999999983
    Rust multithreading after needed time: 0.058985233306884766
    10000.000000171856
    Python needed time: 0.13445138931274414
    10000.000000171856
    C++ Cython-pure no annotations needed time: 0.027180910110473633
    10000.000000171856
    C Cython-pure no annotations needed time: 0.02731800079345703
    10000.000000171856
    C++ Cython-pure pure-annotations needed time: 0.03733682632446289
    10000.000000171856
    C Cython-pure pure-annotations needed time: 0.033501625061035156
    10000.000000171856
    C Cython needed time: 0.03557443618774414
    10000.000000171856
    C++ Cython-pure needed time: 0.03178834915161133
    10000.000000171856
    C Cython-pure needed time: 0.03287529945373535
    

    For 10e4 I got

    1000000.0007792843
    Numba needed time: 5.641289472579956
    1000000.0007792843
    Numba needed time (after compile): 4.76781153678894
    999999.9997857037
    Numba multi-threading needed time: 3.4215545654296875
    999999.9997857037
    Numba multi-threading needed time (after compile): 2.8651604652404785
    1.0000000007792843e6
    Julia needed time: 3.0554113388061523
    1.0000000007792843e6
    Julia needed time (after warm up): 1.569504737854004
    1.0e6
    Julia multi-threading needed time: 1.6075024604797363
    1.0e6
    Julia multi-threading needed time (after warm up): 1.503305196762085
    1000000.0007792843
    Python needed time: 15.476759195327759
    1000000.0007792843
    C++ Cython-pure no annotations needed time: 3.638566017150879
    1000000.0007792843
    C Cython-pure no annotations needed time: 3.711937189102173
    1000000.0007792843
    C++ Cython-pure pure-annotations needed time: 4.374421834945679
    1000000.0007792843
    C Cython-pure pure-annotations needed time: 4.278993129730225
    1000000.0007792843
    C Cython needed time: 4.220995903015137
    1000000.0007792843
    C++ Cython-pure needed time: 3.951723098754883
    1000000.0007792843
    C Cython-pure needed time: 4.254110097885132
    

    So from this, I got:

    1. Julia
    2. Numba
    3. Cython (heard this implementation isn't optimized) (Rust kills my computer)
    opened by smpurkis 2
  • Rust - Numpy

    Rust - Numpy

    This adds a closer-to-real life version of the rust version. By passing a numpy array instead of a PyList we avoid 3 copies of the python list. Looking at the generate C code for some of the other versions, they don't have to copy the python list, they are just passing references around.

    I couldn't get the julia stuff to work locally for me, so I haven't been able to compare this against the other methods.

    Last thing I'd add is that its probably not apples to apples since numpy requires the full allocation up front. Although I think it would improve the benchmark to have all the other implementations work off pre-allocated memory instead, since that's how this would be done IRL.

    opened by sstadick 2
Owner
Federico Simonetta
Musician and computer engineer.
Federico Simonetta
Um scraper feito em python que gera arquivos de excel baseados nas tier lists do site LoLalytics.

LoLalytics-scraper Um scraper feito em python que gera arquivos de excel baseados nas tier lists do site LoLalytics. Começando por um único script com

Kevin Souza 1 Feb 19, 2022
a plugin for py.test that changes the default look and feel of py.test (e.g. progressbar, show tests that fail instantly)

pytest-sugar pytest-sugar is a plugin for pytest that shows failures and errors instantly and shows a progress bar. Requirements You will need the fol

Teemu 963 Dec 28, 2022
Pynguin, The PYthoN General UnIt Test geNerator is a test-generation tool for Python

Pynguin, the PYthoN General UnIt test geNerator, is a tool that allows developers to generate unit tests automatically.

Chair of Software Engineering II, Uni Passau 997 Jan 6, 2023
Ab testing - The using AB test to test of difference of conversion rate

Facebook recently introduced a new type of offer that is an alternative to the current type of bidding called maximum bidding he introduced average bidding.

null 5 Nov 21, 2022
MultiPy lets you conveniently keep track of your python scripts for personal use or showcase by loading and grouping them into categories. It allows you to either run each script individually or together with just one click.

MultiPy About MultiPy is a graphical user interface built using Dear PyGui Python GUI Framework that lets you conveniently keep track of your python s

null 56 Oct 29, 2022
Just for testing video streaming using pytgcalls.

tgvc-video-tests Just for testing video streaming using pytgcalls. Note: The features used in this repository is highly experimental and you might not

wrench 34 Dec 27, 2022
Yet another python home automation project. Because a smart light is more than just on or off

Automate home Yet another home automation project because a smart light is more than just on or off. Overview When talking about home automation there

Maja Massarini 62 Oct 10, 2022
The pytest framework makes it easy to write small tests, yet scales to support complex functional testing

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries. An example o

pytest-dev 9.6k Jan 2, 2023
A small faсade for the standard python mocker library to make it user-friendly

unittest-mocker Inspired by the pytest-mock, but written from scratch for using with unittest and convenient tool - patch_class Installation pip insta

Vertliba V.V. 6 Jun 10, 2022
Green is a clean, colorful, fast python test runner.

Green -- A clean, colorful, fast python test runner. Features Clean - Low redundancy in output. Result statistics for each test is vertically aligned.

Nathan Stocks 756 Dec 22, 2022
splinter - python test framework for web applications

splinter - python tool for testing web applications splinter is an open source tool for testing web applications using Python. It lets you automate br

Cobra Team 2.6k Dec 27, 2022
A test fixtures replacement for Python

factory_boy factory_boy is a fixtures replacement based on thoughtbot's factory_bot. As a fixtures replacement tool, it aims to replace static, hard t

FactoryBoy project 3k Jan 5, 2023
create custom test databases that are populated with fake data

About Generate fake but valid data filled databases for test purposes using most popular patterns(AFAIK). Current support is sqlite, mysql, postgresql

Emir Ozer 2.2k Jan 4, 2023
A test fixtures replacement for Python

factory_boy factory_boy is a fixtures replacement based on thoughtbot's factory_bot. As a fixtures replacement tool, it aims to replace static, hard t

FactoryBoy project 2.4k Feb 5, 2021
splinter - python test framework for web applications

splinter - python tool for testing web applications splinter is an open source tool for testing web applications using Python. It lets you automate br

Cobra Team 2.3k Feb 5, 2021
Django test runner using nose

django-nose django-nose provides all the goodness of nose in your Django tests, like: Testing just your apps by default, not all the standard ones tha

Jazzband 880 Dec 15, 2022
A set of pytest fixtures to test Flask applications

pytest-flask An extension of pytest test runner which provides a set of useful tools to simplify testing and development of the Flask extensions and a

pytest-dev 433 Dec 23, 2022
Wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server.

WebTest This wraps any WSGI application and makes it easy to send test requests to that application, without starting up an HTTP server. This provides

Pylons Project 325 Dec 30, 2022
A complete test automation tool

Golem - Test Automation Golem is a test framework and a complete tool for browser automation. Tests can be written with code in Python, codeless using

null 486 Dec 30, 2022