Advertisement
Guest User

Untitled

a guest
Oct 17th, 2022
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import timeit
  2.  
  3. def change_path():
  4. database_id = 'database-dsadsa213432314'
  5. collection_id = 'collection-dsadjk23143k0fdsf'
  6. key = 'key-231321dsaq'
  7. path = '/databases/{databaseId}/collections/{collectionId}/index/{key}'
  8. path = path.replace('{databaseId}', database_id)
  9. path = path.replace('{collectionId}', collection_id)
  10. path = path.replace('{key}', key)
  11.  
  12. return path
  13.  
  14. def format_with_assingment_path():
  15. database_id = 'database-dsadsa213432314'
  16. collection_id = 'collection-dsadjk23143k0fdsf'
  17. key = 'key-231321dsaq'
  18. path = '/databases/{databaseId}/collections/{collectionId}/index/{key}'.format(databaseId=database_id, collectionId=collection_id, key=key)
  19. return path
  20.  
  21. def format_with_index():
  22. database_id = 'database-dsadsa213432314'
  23. collection_id = 'collection-dsadjk23143k0fdsf'
  24. key = 'key-231321dsaq'
  25. path = '/databases/{0}/collections/{1}/index/{2}'.format(database_id, collection_id, key)
  26. return path
  27.  
  28. def fstring_path():
  29. databaseId = 'database-dsadsa213432314'
  30. collectionId = 'collection-dsadjk23143k0fdsf'
  31. key = 'key-231321dsaq'
  32. path = f'/databases/{databaseId}/collections/{collectionId}/index/{key}'
  33. return path
  34.  
  35. time1 = timeit.timeit(change_path)
  36. time2 = timeit.timeit(format_with_assingment_path)
  37. time3 = timeit.timeit(format_with_index)
  38. time4 = timeit.timeit(fstring_path)
  39.  
  40. print('replace path: ', time1)
  41. print('format with assinment: ' ,time2)
  42. print('format with indexs:', time3)
  43. print('fstring path: ' ,time4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement