From 4b0ec1a437cdb84c74beead105da57e39b3da0bd Mon Sep 17 00:00:00 2001 From: Nilstrieb Date: Sun, 6 Jun 2021 21:23:40 +0200 Subject: [PATCH] lmao python --- primes/README.md | 9 ++++++--- primes/python/primes.py | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 primes/python/primes.py diff --git a/primes/README.md b/primes/README.md index 7808140..74b33f6 100644 --- a/primes/README.md +++ b/primes/README.md @@ -3,10 +3,13 @@ Find all primes from 0 to 10 000 000. Printing time is not included. -There are probably some issues in the code since this result seems a bit *questionable* +There are probably some issues in the code since this result seems a bit *questionable* +Although I can understand that JS is extremly fast, this is the perfect benchmark for JS, +and we should never forget that V8 is... **fast**. | Language | Time | | ---------| -------| | Java | 1836ms | -| Javascript | 1778.2ms | -| Rust | 1818ms | \ No newline at end of file +| Javascript | 1778ms | +| Rust | 1818ms | +| python3 | 34361ms | \ No newline at end of file diff --git a/primes/python/primes.py b/primes/python/primes.py new file mode 100644 index 0000000..2408c2d --- /dev/null +++ b/primes/python/primes.py @@ -0,0 +1,27 @@ +import time +from math import sqrt + + +def primes(max): + primes_list = [2] + + for i in range(3, max): + is_prime = True + for prime in primes_list: + if prime > sqrt(i): + break + if i % prime == 0: + is_prime = False + break + + if is_prime: + primes_list.append(i) + + return primes_list + + +start_millis = round(time.time() * 1000) +primes(10_000_000) +total_millis = round(time.time() * 1000) - start_millis + +print(total_millis)