Python Speed of function vs lambda calls in python

AI Thread Summary
The discussion centers on the performance difference between using a standard function definition and a lambda function within another function in Python. It highlights that defining a lambda function inside a function leads to the lambda being redefined with each iteration, which can slow down execution. In contrast, defining the lambda outside the function allows it to be reused, improving performance. The conversation references a Stack Overflow post indicating that the execution time difference is generally negligible, but emphasizes that the context of how functions are defined and called can impact speed.
ergospherical
Science Advisor
Homework Helper
Education Advisor
Insights Author
Messages
1,097
Reaction score
1,384
An observation I made earlier- something like
Python:
def f(...):
    ...
    return ...

def g:
    ... = f(...)
was quite a bit slower than doing
Python:
def g:
    f = lambda ... : ...
    ... = f(...)
any reasons why?
 
Technology news on Phys.org
ergospherical said:
any reasons why?
You're redefining the lambda ##f## in every iteration of ##g##. Put the lambda definition of ##f## outside the body of ##g## and see what happens.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
2
Views
1K
Replies
15
Views
2K
Replies
18
Views
1K
Replies
8
Views
2K
Replies
7
Views
5K
Replies
9
Views
2K
Replies
14
Views
4K
Back
Top