Last active
April 17, 2023 18:20
-
-
Save heyodai/ea06d1d8df5f8e7cb9a7345adb3e8163 to your computer and use it in GitHub Desktop.
This file contains 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 characters
Download statistics | |
Time taken: 4.29 seconds | |
File size: 45.47 MB | |
Network speed: 10.61 MB/s | |
Time taken: 2.53 seconds | |
File size: 45.47 MB | |
Network speed: 18.00 MB/s | |
Time taken: 4.13 seconds | |
File size: 45.47 MB | |
Network speed: 11.01 MB/s | |
Time taken: 3.36 seconds | |
File size: 45.47 MB | |
Network speed: 13.53 MB/s | |
Time taken: 2.32 seconds | |
File size: 45.47 MB | |
Network speed: 19.62 MB/s | |
This file contains 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 characters
Download statistics | |
Time taken: 21.95 seconds | |
File size: 45.47 MB | |
Network speed: 2.07 MB/s | |
Time taken: 21.55 seconds | |
File size: 45.47 MB | |
Network speed: 2.11 MB/s | |
Time taken: 21.42 seconds | |
File size: 45.47 MB | |
Network speed: 2.12 MB/s | |
Time taken: 21.96 seconds | |
File size: 45.47 MB | |
Network speed: 2.07 MB/s | |
Time taken: 21.52 seconds | |
File size: 45.47 MB | |
Network speed: 2.11 MB/s | |
This file contains 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 characters
import os | |
import requests | |
import time | |
# URL of the file to download | |
url = 'http://geoschemdata.wustl.edu/ExtData/GEOS_2x2.5/MERRA2/1980/01/MERRA2.19800101.A3cld.2x25.nc4' | |
# Start time | |
start_time = time.time() | |
# Download the file | |
response = requests.get(url) | |
# End time | |
end_time = time.time() | |
# Calculate the time taken, file size, and network speed | |
time_taken = end_time - start_time | |
file_size = len(response.content) / (1024 * 1024) # in MB | |
network_speed = file_size / time_taken # in MB/s | |
# Print the download statistics | |
print(f'Time taken to download the file: {time_taken:.2f} seconds') | |
print(f'Downloaded file size: {file_size:.2f} MB') | |
print(f'Network speed: {network_speed:.2f} MB/s') | |
# Save the download statistics to a text file | |
filename = 'download_statistics.txt' | |
mode = 'a' if os.path.exists(filename) else 'w' | |
with open(filename, mode) as f: | |
if mode == 'w': | |
f.write('Download statistics\n') | |
f.write(f'Time taken: {time_taken:.2f} seconds\n') | |
f.write(f'File size: {file_size:.2f} MB\n') | |
f.write(f'Network speed: {network_speed:.2f} MB/s\n\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment