1

So i'm using Python, i'm not new to Python, but obviously not advanced. Anyway, i have an algorithm that i want to implement using Python, but I want to make it as quick as possible. My question is: can we find a benchmark comparing most operations but with different "codes"? For example, if i have a list and i want to divide all elements by 2, there are multiple ways to code it

newlist=[e/2 for e in oldlist]

or using a loop

newlist=[] for e in oldlist: newlist.append(e/2)

or even using a library (scipy, numpy etc...). Which way to code this is the fastest? This is a simple example but there are so many operations i don't know which way to code it is the best, and i may not now every way to code it either...

So i ask the question for Python, but it is also a viable question for other programming languages

Eegan
  • 11
  • 1
  • 2
    What you're asking for is a request for a resource comparing the performance of solutions to simple, common programming problems; resource requests are off-topic for Stack Overflow since whether or not a particular resource is a good answer would be a matter of opinion. That said, Stack Overflow itself might be usable as such a resource, for example if you search for `[python] performance of list comprehension vs append` you will probably find a Q&A where someone has benchmarked those. – kaya3 Apr 30 '21 at 11:22
  • https://www.kdnuggets.com/2020/06/time-complexity-measure-efficiency-algorithms.html Interesting reading for background introduction – pippo1980 Apr 30 '21 at 12:03
  • 1
    Sometimes people do answer “ how to measure running time of algorithms in python “ : https://stackoverflow.com/questions/2662140/how-to-measure-running-time-of-algorithms-in-python – pippo1980 Apr 30 '21 at 12:04

0 Answers0