Skip to content

Instantly share code, notes, and snippets.

@TheoOkafor
Created January 20, 2021 21:33
Show Gist options
  • Save TheoOkafor/0c9b044ca69dd8b4063cbf9c48ca7961 to your computer and use it in GitHub Desktop.
Save TheoOkafor/0c9b044ca69dd8b4063cbf9c48ca7961 to your computer and use it in GitHub Desktop.
Test the runtime with and without print statement
import time
def test_runtime_with_print():
start_time = time.time()
result = 0
for i in range(100):
result = result + i
print(result)
print("======= WITH PRINT =======: {} milliseconds".format((time.time() - start_time) * 1000))
return result
def test_runtime_without_print():
start_time = time.time()
result = 0
for i in range(99):
result = result + 1
print("======= WITHOUT PRINT =======: {} milliseconds".format((time.time() - start_time) * 1000))
return result
test_runtime_with_print()
test_runtime_without_print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment