GithubHelp home page GithubHelp logo

jackeown / pythonisnotslow Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 13 KB

Simple program to benchmark C vs pure Python vs Numpy vs Cython.

Makefile 7.68% C 19.15% Shell 14.11% Python 31.18% Fortran 9.56% Cython 18.33%
python slow numpy cython

pythonisnotslow's Introduction

Compare the speed of C, pure Python, Numpy, Cython, and Fortran.

First build the C code, Cython, and Fortran by running make

Next run ./benchmark.sh

Remove built files using make clean

The C code is in benchmark.c
The pure Python code is in naiveBenchmark.py
The numpy Python code is in numpyBenchmark.py
The Cython code is in cythonHelpers.pyx and is imported/run from cythonBenchmark.py
The Fortran code is in benchmark.f90

Here are the results from running ./benchmark.sh on my workstation:

C code:

real    0m0.024s
user    0m0.019s
sys     0m0.005s
#####################################
Naive python:

real    2m16.430s
user    2m15.398s
sys     0m0.676s
#####################################
Numpy python:

real    0m0.793s
user    0m0.213s
sys     0m0.080s
#####################################
Cython python:

real    0m0.036s
user    0m0.028s
sys     0m0.004s
#####################################
(Modern) Fortran code (gfortran):

real    0m0.066s
user    0m0.043s
sys     0m0.006s
#####################################
(Modern) Fortran code (Intel):

real    0m0.114s
user    0m0.110s
sys     0m0.002s
#####################################

pythonisnotslow's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

mefuller

pythonisnotslow's Issues

your C code is unoptimized

the reason your C code is slower is because numpy and cython compiles into vectorized instructions. try convert your C code with high performance linear algebra libraries such as Eigen and you'll see very similar performances between the C version and your cython version. (because they would be using the same thing)

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.