It’s Running Time Wednesday!
Hey friends 👋
Like I stated last week, today, we are learning something that every developer should understand — running time, also known as Big O notation.
It sounds fancy, but it’s just a way to measure how fast (or slow) your code runs as your input grows.
Let’s break it down.
What’s Running Time?
Running time tells you how the performance of your code changes as the amount of data increases.
For example, sorting 10 items is quick. Sorting 10, 000 items? That’s where efficiency comes into play.
So, Big O helps you predict how your program behaves when things scale (up or down).
Why “Big O”?
“Big O” describes the order of growth, in essence, how the number of operations grows compared to the size of the input (n
).
We’re not counting seconds; we’re counting how many steps your algorithm takes as n
increases.
Common Big O Notations
Notation | Name | Description | Example |
---|---|---|---|
O(1) | Constant time | Doesn’t depend on input size | Accessing an element by index |
O(log n) | Logarithmic | Grows slowly as input increases | Binary search |
O(n) | Linear | Grows directly with input | Looping through an array |
O(n log n) | Linearithmic | Common in efficient sorting | Merge sort, quicksort |
O(n²) | Quadratic | Grows fast with nested loops | Comparing every pair in a list |
O(2ⁿ) | Exponential | Doubles with every new element | Recursive Fibonacci |
O(n!) | Factorial | Blows up quickly | Generating all permutations |
Quick Examples
1️⃣ O(1) — Constant
function getFirst(arr) {
return arr[0]; // One step, no matter how big arr is
}
2️⃣ O(n) — Linear
function printAll(arr) {
for (let item of arr) console.log(item);
// Takes more time as arr grows
}
3️⃣ O(n²) — Quadratic
function printPairs(arr) {
for (let i of arr) {
for (let j of arr) {
console.log(i, j);
}
}
// For 10 items = 100 operations
}
Visualising Growth
O(1) → constant line
O(log n) → slow curve
O(n) → steady climb
O(n²) → sharp rise
O(2ⁿ) → rocket 🚀
You don’t need maths to get it — just imagine how the number of steps go up for larger inputs.
Try It Yourself in CodePen
👉 Play with Running Time Examples
- Pick a function type – O(1), O(n), or O(n²)
- Click “Run Test.” The chart shows how long each one takes for different array sizes.
Constant time stays flat, linear grows steadily, and quadratic shoots up fast.
Try tweaking it
In the JavaScript panel, find this line:
const sizes = [100, 500, 1000, 2000];
Change it to something bigger:
const sizes = [1000, 5000, 10000, 20000];
Then click Run again.
You’ll see the chart climb faster — that’s how running time scales with data.
🙋🏽♀️ Wrap up!
Here’s the takeaway:
- Running time = how your algorithm scales (go up or down).
- Think of Big O as a way to predict how an algorithm will handle a huge amount of data. It's about growth, not how fast it runs right now.
- Aim for O(1) or O(log n) when possible, but clarity comes first.
Next Wednesday, we’ll connect this to space complexity, that is, how much memory your program uses.
Till then, write clean code and stay curious!
Connect with me on GitHub
Was this tutorial helpful? Got questions? Or any insight to help me write better tutorials? Let me know in the 💬!
That’s it for today’s midweek mini tutorial!
I’m keeping things light, fun and useful; one small project at a time.
If you enjoyed this, leave a 💬 or 🧡 to let me know.
And if you’ve got an idea for something you'd like me to try out next Wednesday, drop it in the comments. 👇
Follow me to see more straight-forward and short tutorials like this :)
I'm still hunting for full stack roles,
contract or fulltime.
Please check out my [Portfolio](https://gift-egbonyi.onrender.com)
:-)
Web trails
You can also find me here on LinkedIn
or here X (Twitter)
✍🏾 I’m documenting my learning loudly every Wednesday. Follow along if you're learning JavaScript too!
Let’s keep learning together!
See you, same time, next Wednesday🚀
Top comments (1)