-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List append and sum benchmark #860
Comments
Results on Intel® Core™ i5-8250U CPU @ 1.60GHz × 8 (OS: Ubuntu 22.04 LTS) $ clang++ -std=c++17 -O3 -march=native a.cpp
$ time ./a.out
5000000050000000
./a.out 0.28s user 0.25s system 99% cpu 0.532 total
$ lpython --fast a.py
$ time ./a.out
5000000050000000
./a.out 0.14s user 0.11s system 99% cpu 0.246 total
$ time python a.py
5000000050000000
python a.py 13.77s user 1.40s system 99% cpu 15.178 total |
Apple Air Mac M1 (2020) % lpython expr.py
% time ./a.out
5000000050000000
./a.out 0.50s user 0.14s system 41% cpu 1.557 total
% lpython --fast expr.py
% time ./a.out
5000000050000000
./a.out 0.13s user 0.13s system 40% cpu 0.617 total
% clang++ -std=c++17 -O3 test_cpp.cpp -o b.out
% time ./b.out
5000000050000000
./b.out 0.09s user 0.10s system 20% cpu 0.922 total
% time PYTHONPATH=$PWD/src/runtime/ltypes python expr.py
5000000050000000
PYTHONPATH=$PWD/src/runtime/ltypes python expr.py 12.13s user 2.63s system 90% cpu 16.368 total |
Comparison with
Codes from ltypes import i32, i64
def test_list(n: i32) -> i64:
a: list[i32] = [i32(0)]
i: i32
for i in range(n):
a.append(i)
s: i64 = i64(0)
for i in range(n):
s += i64(a[i])
return s
print(test_list(100000002)) def test_list(n):
a = [0]
for i in range(n):
a.append(i)
s = 0
for i in range(n):
s += a[i]
return s
print(test_list(100000002)) |
Here is the updated benchmark: from lpython import i32, i64
def test_list(n: i32) -> i64:
a: list[i32] = [0]
i: i32
for i in range(n):
a.append(i)
s: i64 = i64(0)
for i in range(n):
s += i64(a[i])
return s
print(test_list(100000002)) It still runs at the same speed for me. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This benchmark is from https://lemire.me/blog/2012/06/20/do-not-waste-time-with-stl-vectors/
Python:
and C++:
Results on Apple M1 Max:
The text was updated successfully, but these errors were encountered: