Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nschloe/python-vs-cpp
https://github.com/nschloe/python-vs-cpp
Last synced: 22 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/nschloe/python-vs-cpp
- Owner: nschloe
- License: mit
- Created: 2019-12-04T15:57:18.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-11T18:05:37.000Z (over 4 years ago)
- Last Synced: 2024-10-10T09:26:34.374Z (about 1 month ago)
- Language: C++
- Size: 115 KB
- Stars: 13
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# 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,
```c++
double out = 0.0
for (int k=0; k < n; k++) {
out += u[k] * v[k];
}
```
than in Python:
```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
```python
import numpyout = numpy.dot(u, v)
```
anyway. For C/C++,
[Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page),
[CBLAS](http://www.netlib.org/blas/#_cblas), and [Boost](https://www.boost.org/) 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](https://en.wikipedia.org/wiki/MIT_License).