Skip to content
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

RustPython Slow to Normal Python #5178

Open
MominIqbal-1234 opened this issue Feb 22, 2024 · 3 comments
Open

RustPython Slow to Normal Python #5178

MominIqbal-1234 opened this issue Feb 22, 2024 · 3 comments

Comments

@MominIqbal-1234
Copy link

Summary

i can check the speed test rustpython and python
but result is not good i think so rustpython create to increase python code execution speed
please can you explain

Screenshot from 2024-02-22 10-18-08

@MominIqbal-1234 MominIqbal-1234 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2024
@youknowone
Copy link
Member

Currently RustPython is a lot more slower than CPython. Implementing more optimization will improve it.

@mzdk100
Copy link

mzdk100 commented Apr 5, 2024

import time

def test_list_operations():
    lst = [i for i in range(100000)]
    start_time = time.time()
    for _ in range(1000):
        lst.append(len(lst))
        lst.remove(lst[0])
    end_time = time.time()
    print("List operations took", end_time - start_time, "seconds")

def test_dict_operations():
    dct = {i: i**2 for i in range(10000)}
    # 添加键0到字典中
    dct[0] = 0**2
    start_time = time.time()
    for _ in range(1000):
        dct[len(dct)] = len(dct)**2
        # 检查键是否存在,然后删除
        if 0 in dct:
            del dct[0]
    end_time = time.time()
    print("Dictionary operations took", end_time - start_time, "seconds")

def test_loop():
    start_time = time.time()
    for _ in range(1000000):
        pass
    end_time = time.time()
    print("Loop took", end_time - start_time, "seconds")

def test_function_call():
    def dummy_function():
        pass

    start_time = time.time()
    for _ in range(1000000):
        dummy_function()
    end_time = time.time()
    print("Function call took", end_time - start_time, "seconds")

test_list_operations()
test_dict_operations()
test_loop()
test_function_call()

Comparing the running of cpython and rustpython, only function calls are very slow, which may not be tolerable.

PS E:\repositories\rust\RustPython\target\release> python a.py
List operations took 0.038018226623535156 seconds
Dictionary operations took 0.0 seconds
Loop took 0.029998302459716797 seconds
Function call took 0.07699966430664062 seconds
PS E:\repositories\rust\RustPython\target\release> ./rustpython a.py
List operations took 0.03842902183532715 seconds
Dictionary operations took 0.002158641815185547 seconds
Loop took 0.2583482265472412 seconds
Function call took 1.0768907070159912 seconds

But I really like this project because it no longer requires a runtime with cpython, which is great!

@youknowone
Copy link
Member

Thank you for sharing the insight. One of the missing optimization in RustPython is vector call. It maybe related.
https://docs.python.org/3/c-api/call.html#the-vectorcall-protocol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants