Git Product home page Git Product logo

sortable's Introduction

Cython Sortable

This package includes implementations of three different sorting algorithms: insertion, quicksort, and bubble. Each exist in this repo as standard Python and as compiled Cython code to demonstrate how Cython can speedup Python code with only minimal changes.

Pure Python versions of sort algorithms can be imported from sortable.py.* and the compiled Cython version can be imported from sortable.c.* (after running the build / installation steps in setup.py)

├── src/
│   └── sortable/
│       ├── c/
│       │   ├── __init__.py
│       │   └── algorithms.pyx
│       ├── py/
│       │   ├── __init__.py
│       │   └── algorithms.py
│       ├── __init__.py
│       └── benchmark.py
└── tests/
    ├── __init__.py
    └── test_sortable.py

Installing

  • Clone repo
  • Create and activate virtual env
  • Build Cython $ python setup.py build_ext --inplace
  • Install $ python setup.py install

Running performance tests

python src/sortable/benchmark.py {path to sort algorithm} {times to run}

Examples:

$ python src/sortable/benchmark.py sortable.py.quicksort 25
0.1855695

$ python src/sortable/benchmark.py sortable.c.quicksort 25
0.070509303

$ python src/sortable/benchmark.py sortable.py.insertion 25
3.557346874

$ python src/sortable/benchmark.py sortable.c.insertion 25
1.147218161

$ python src/sortable/benchmark.py sortable.py.bubble 25
13.84022062

$ python src/sortable/benchmark.py sortable.c.bubble 25
4.789788046

Running tests

Requires installing pytest

$ pytest
============================================= test session starts =============================================
platform darwin -- Python 3.8.0, pytest-5.3.1, py-1.8.0, pluggy-0.13.1
rootdir: /Users/josh/www/sortable
collected 24 items

tests/test_sortable.py ........................                                                         [100%]

============================================= 24 passed in 0.42s ==============================================

sortable's People

Contributors

joshmaker avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.