Skip to content

nschloe/python-vs-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python vs. C++

It is an often reiterated statement that

Interpreted code is always slower then compiled code. We need speed! That's why we're using C/C++ in our project.

This assumption is based on the correct observation that large loops like for a dot product of two vectors u, v, are faster in C,

double out = 0.0
for (int k=0; k < n; k++) {
   out += u[k] * v[k];
}

than in Python:

out = 0.0
for k in range(n):
    out[k] += u[k] * v[k]

If you care about speed, you wouldn't do either of the above loops, though. In Python, most everyone does

import numpy

out = numpy.dot(u, v)

anyway. For C/C++, Eigen, CBLAS, and Boost come to mind.

This repository contains a comparison of some common costly numerical operations between C++ and Python.

As always, comments and suggestions are welcome!

Dot product of two vectors

Matrix-matrix product

Sum entries in a vector

Add two vectors

License

The code in this respository is published under the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published