Storage commands (gsutil) in GCP - Time & Space Complexity
When using storage commands like gsutil, it's important to understand how the time to complete tasks grows as you work with more files or data.
We want to know how the number of operations changes when copying or listing many files.
Analyze the time complexity of copying multiple files from a local folder to a Google Cloud Storage bucket.
gsutil cp ./local-folder/* gs://my-bucket/
This command copies all files from a local folder to a cloud storage bucket.
Look at what happens repeatedly during this command.
- Primary operation: Uploading each file individually to the cloud bucket.
- How many times: Once per file in the local folder.
As the number of files grows, the total upload operations grow in the same way.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 uploads |
| 100 | 100 uploads |
| 1000 | 1000 uploads |
Pattern observation: The number of upload operations increases directly with the number of files.
Time Complexity: O(n)
This means the time to finish grows in direct proportion to how many files you copy.
[X] Wrong: "Copying many files happens in the same time as copying one file because the command runs once."
[OK] Correct: Each file upload is a separate operation, so more files mean more work and more time.
Understanding how commands scale with input size shows you can predict performance and plan for bigger workloads confidently.
"What if we used a command that uploads files in parallel? How would the time complexity change?"