Last active
November 6, 2023 18:10
Revisions
-
mikbuch revised this gist
Nov 6, 2023 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,9 @@ def pretty_timedelta(delta): days, seconds = divmod(seconds, 86400) hours, seconds = divmod(seconds, 3600) minutes, seconds = divmod(seconds, 60) # Skipping seconds, as the next divmod is 1, so the # seconds stay the same. _, seconds_decimal = divmod(timedelta_seconds, 1) milliseconds = '%.2f' % float(seconds_decimal*1000) print('__________________________________') print('Calculating the results has taken:') -
mikbuch revised this gist
Nov 5, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ def pretty_timedelta(delta): """ Pretty printing a `timedelta` object form `datetime` Python module Acknowledgements: -
mikbuch revised this gist
Nov 5, 2023 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ def pretty_timedelta(delta): """ Pretty printing time delta `datetime` Python object This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,4 +25,4 @@ delta = end_time - start_time # Output: pretty print the result pretty_timedelta(delta) -
mikbuch revised this gist
Nov 5, 2023 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
mikbuch revised this gist
Nov 5, 2023 . 1 changed file with 0 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,3 @@ import time from datetime import datetime @@ -25,11 +13,9 @@ # Here we use a small pause to showcase the results time.sleep(2.5) # When the cell finished executing end_time = datetime.now() print('Calculation started at: ', start_time.strftime(datetime_display_format)) print('Calculation ended at: ', end_time.strftime(datetime_display_format)) -
mikbuch created this gist
Nov 5, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ def pretty_time_delta(delta): """ Pretty printing time delta `datetime` Python object Acknowledgements: @thatalextaylor for his earlier version: https://gist.github.com/thatalextaylor/7408395 That I used to modify the script. Args: delta -- `datatime` Python time delta object Returns: None -- just a printing function -- works better with Jupyter Notebook """ timedelta_seconds = delta.total_seconds() # Seconds will be int-s, timedelta_seconds stores also decimal places seconds = timedelta_seconds # Can be negative sign_string = '-' if seconds < 0 else '' seconds = abs(int(seconds)) days, seconds = divmod(seconds, 86400) hours, seconds = divmod(seconds, 3600) minutes, seconds = divmod(seconds, 60) seconds, seconds_decimal = divmod(timedelta_seconds, 1) milliseconds = '%.2f' % float(seconds_decimal*1000) print('__________________________________') print('Calculating the results has taken:') if days > 0: print(' %s %dd %dh %dm %ds' % (sign_string, days, hours, minutes, seconds)) elif hours > 0: print(' %s %dh %dm %ds' % (sign_string, hours, minutes, seconds)) elif minutes > 0: print(' %s %dm %ds' % (sign_string, minutes, seconds)) elif seconds > 0: print(' %s %ds %sms' % (sign_string, seconds, milliseconds)) elif milliseconds > 0: print(' %s %ds' % (sign_string, milliseconds)) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ ''' Example output of this test script ``` Calculation started at: 2023-11-05 14:43:45 Calculation ended at: 2023-11-05 14:43:47 __________________________________ Calculating the results has taken: 2s 502.71ms ``` ''' import time from datetime import datetime # We need to know when the cell/calculation started execution start_time = datetime.now() datetime_display_format = "%Y-%m-%d %H:%M:%S" ''' Your code goes here ''' # Here we use a small pause to showcase the results time.sleep(2.5) # When the cell finished executing end_time = datetime.now() print('Calculation started at: ', start_time.strftime(datetime_display_format)) print('Calculation ended at: ', end_time.strftime(datetime_display_format)) # Difference between two timestamps # in hours:minutes:seconds format delta = end_time - start_time # Output: pretty print the result pretty_time_delta(delta)