Python Can Be Faster Than C++

A trick that makes Python faster more than you can imagine with other readers review

Nuha Khaled
The Startup

--

Photo by Jake Givens on Unsplash

Python is a great versatile programming language. Even though python is used most for machine learning problem solving because of its library and high-level language, it is known to be slower than many other languages. Because of its reputation, many would decide to leave the language behind and stick with other options like C++ for program solving.

In this article, I will show you how Python is faster than C++.

Basic Speed Testing

To test the normal speed difference between Python and C++, I will test the execution time of the Generation of primes algorithm. It is a simple algorithm with clear short steps in both languages.

Generation of primes flowchart

Python Implementation

import math
from time import per_counter
def is_prime(num):
if num == 2:
return True;
if num <= 1 or not num % 2:
return False
for div in range(3,int(math.sqrt(num)+1),2)…

--

--

Nuha Khaled
The Startup

Freelance Software Engineer | Unschooling Mother of 3 | Dedicated Muslimah