Does creating separate functions instead of one big one slow processing time?

function, google-app-engine, performance, python

Solution

Focus on being able to read and easily understand your code.

Once you've done this, if you have a performance problem, then look into what might be causing it.

Most languages, python included, tend to have fairly low overhead for making method calls. Putting this code into a single function is not going to (dramatically) change the performance metrics - I'd guess that your random number generation will probably be the bulk of the time, not having 2 functions.

That being said, splitting functions does have a (very, very minor) impact on performance. However, I'd think of it this way - it may take you from going 80 mph on the highway to 79.99mph (which you'll never really notice). The important things to watch for are avoiding stoplights and traffic jams, since they're going to make you have to stop altogether...

Problem

I'm working in the Google App Engine environment and programming in Python. I am creating a function that essentially generates a random number/letter string and then stores to the memcache. ``` def generate_random_string(): # return a random 6-digit long string def check_and_store_to_memcache(): randomstring = generate_random_string() #check against memcache #if ok, then store key value with another value #if not ok, run generate_random_string() again and check again. ``` Does creating two functions instead of just one big one affect performance? I prefer two, as it better matches how I think, but don't mind combining them if that's "best practice".

Original source