Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import timeit
- def change_path():
- database_id = 'database-dsadsa213432314'
- collection_id = 'collection-dsadjk23143k0fdsf'
- key = 'key-231321dsaq'
- path = '/databases/{databaseId}/collections/{collectionId}/index/{key}'
- path = path.replace('{databaseId}', database_id)
- path = path.replace('{collectionId}', collection_id)
- path = path.replace('{key}', key)
- return path
- def format_with_assingment_path():
- database_id = 'database-dsadsa213432314'
- collection_id = 'collection-dsadjk23143k0fdsf'
- key = 'key-231321dsaq'
- path = '/databases/{databaseId}/collections/{collectionId}/index/{key}'.format(databaseId=database_id, collectionId=collection_id, key=key)
- return path
- def format_with_index():
- database_id = 'database-dsadsa213432314'
- collection_id = 'collection-dsadjk23143k0fdsf'
- key = 'key-231321dsaq'
- path = '/databases/{0}/collections/{1}/index/{2}'.format(database_id, collection_id, key)
- return path
- def fstring_path():
- databaseId = 'database-dsadsa213432314'
- collectionId = 'collection-dsadjk23143k0fdsf'
- key = 'key-231321dsaq'
- path = f'/databases/{databaseId}/collections/{collectionId}/index/{key}'
- return path
- time1 = timeit.timeit(change_path)
- time2 = timeit.timeit(format_with_assingment_path)
- time3 = timeit.timeit(format_with_index)
- time4 = timeit.timeit(fstring_path)
- print('replace path: ', time1)
- print('format with assinment: ' ,time2)
- print('format with indexs:', time3)
- print('fstring path: ' ,time4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement