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

refactor: PyTorchInference initialization #1571

Closed
wants to merge 2 commits into from

Conversation

arjun-234
Copy link

In this version, I have modified the code by combining two loops into a single loop within the same method. This enhancement has resulted in improved efficiency.

In this version, I have modified the code by combining two loops into a single loop within the same method. This enhancement has resulted in improved efficiency.
@ExtReMLapin
Copy link

Source : It was revealed to me in a dream

Jokes aside, list comprehensions are faster in python, unless the iterator costs a lot, I doubt it will be faster

@arjun-234
Copy link
Author

Hello @ExtReMLapin,
I appreciate your question. While list comprehensions are faster in python, I consolidated two loops into one to improve time complexity from O(2) to O(1). This should notably reduce overhead and improve performance, especially with larger inputs.
Thanks :)

@threeal
Copy link

threeal commented Sep 1, 2023

@arjun-234 your code lacks another thing that may make it slower than just using list comprehension.

Basically this:

arr = [0] * length
for i in range(length):
    arr[i] = input[i]

Is faster than this:

arr = []
for i in range(length):
    arr.append(input[i])

But still, list comprehension is the fastest of them all. And not only that, it also looks cleaner 👌.

@arjun-234
Copy link
Author

Greetings @threeal,
Yeah, you're correct that list comprehensions are always faster, but especially with larger inputs, having fewer iterations is always good, which improves performance in terms of time complexity.
Thanks :)

@itsRoman
Copy link

itsRoman commented Sep 8, 2023

Hello @ExtReMLapin, I appreciate your question. While list comprehensions are faster in python, I consolidated two loops into one to improve time complexity from O(2) to O(1). This should notably reduce overhead and improve performance, especially with larger inputs. Thanks :)

O(2) == O(1) 🤔

@jongwook jongwook closed this Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants