Skip to content

Instantly share code, notes, and snippets.

@jtallieu
Last active September 12, 2016 18:35
Show Gist options
  • Save jtallieu/4c08bcf0963b9f8cd53e0dd710872dde to your computer and use it in GitHub Desktop.
Save jtallieu/4c08bcf0963b9f8cd53e0dd710872dde to your computer and use it in GitHub Desktop.
Eagle Eye Networks Inc :: Python screening sample - String handling optimization
"""
::Eagle Eye Networks Inc.:::
::Python screening::
The following script is purposley written poorly.
Improve upon the code and explain your improvements.
The id_csv method must return a unicode string of
representation of a comma separated list of uuid's
"""
import uuid
import string
import cProfile
def id_csv(limit):
"""Generates a comma separated list of uuid's"""
id_list = u""
while limit:
limit -= 1
id_list += str(uuid.uuid4())
if limit:
id_list += ", "
return id_list
if __name__ == "__main__":
print id_csv(10)
cProfile.run("id_csv(10000)")
@jtallieu
Copy link
Author

jtallieu commented Sep 9, 2016

Output from above code.

         70003 function calls in 0.585 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.585    0.585 <string>:1(<module>)
        1    0.426    0.426    0.585    0.585 sample_1.py:13(id_csv)

Re-written output:

         80004 function calls in 0.162 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.162    0.162 <string>:1(<module>)
        1    0.011    0.011    0.162    0.162 sample_1.py:24(id_csv_fast)

@alzerid
Copy link

alzerid commented Sep 10, 2016

👍

@thartley
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment