Count your 9s before blaming your CPU

Recently I was working on a Windows Forms application and I tried to create an async model, to see how long does it take to perform the loops. Although it doesn’t take much time for our CPU to calculate the results for our general loops; thousands, or hundred thousand maximum. I created the model for performing the loop as,

// loops, seconds are defined to be long variables.
private async void runAsync() 
     long res = await result();  
      resultLabel.Text = String.Format("Result of {0} loop addition is {1}.", loops, res);  
      // Done.. Stop the timer..  
      timerLabel.Text = String.Format("{0} seconds took to calculate result of {1} loops", seconds, loops);  
      seconds = 0;  
private async Task<long> result()  
     long res = 0;  
     return await Task.Run(() =>  
          for (var i = 0; i < loops; i++)  
               res += i;  
          return res;  

Well, it probably does what it is asked to do so. The only case of interest is, when the value is given to the loop. Let me show you the results for each of these cases…

Having 0-8 9s.

In case of 9s from 0 to 8, the execution takes only a fraction of one second.

Continuing to 8th result now,

Quite similar behavior being shown in these cases. Which shows that CPU is pretty much fast to calculate this much loops easily and to provide the result; if the result is not correct, please avoid mentioning it.

Adding a 9th 9

With a new 9th 9 being added to the loop; the results now amplify, instead of 1 2 or 3 seconds, it takes up to 8  seconds to execute the loop and provide the results.

That shows the significance of a 9 in the row of loops…

Adding a 10th 9

By using another 9 in the loop, I was finally able to manage to make the CPU work for a longer time… Much much longer time. My CPU doesn’t provide any result for this calculation, and took more than 7 or 8 hundred seconds.

Not bad, eh?

I will not say, CPU was not efficient as it was able to calculate the results for 0-8 9s and then started to topple the time by an increment of each 9 (each 9 made the first 9 in the left side tens, from ones, and hundreds from ones and so on making the loop counter to be billions). The number for the loops was, nine billion nine hundred ninety-nine million nine hundred ninety-nine thousand nine hundred ninety-nine. Which is quite reasonable for the CPU to take this much time.

This reminds me of the “Transistor as an amplifier“, current moves and at a critical level, voltage rises and just keeps rising… I am really glad I found this and took time to write a blog about it. 🙂 Hopefully, next time you will count your nines before saying your CPU is fast!


Don’t be shy – afraid

Most of the new programmers who’re new into this field are usually concerned about their information and knowledge about programming and the concepts. I, have been a part of this community where people; usually with no knowledge on language, are acting like they’ve mastered the skills and are already the perfect programmers.

They try to act like programming was the first thing they ever did, even before the po-po ca-ca; ewww! No one did that, usually I get to hear a lot from friends, some speciall friends and buddies that they’re perfect in this thing, they hacked this, they cracked that software, they successfully sent a bug to that and all that.

But, guys listen up! This is not a race to prove yourself. I don’t even know why and when did I change myself and became an optimist of the computing industry and the divine software programmer. But, yes I am a good guy and I believe that the new thing that you do, you learn, you test or you show off is nothing to smile or dance for. You’ve got a lot of new things in front of you, to prove yourself at, to prove that you’ve got enough guts to prove your perfection in every stage.

A master is not the one who can write the software application with first attempt, he is not the one who can crack a software, neither is the one who can easily hack into his neighbour’s Wi-fi connection and nor is the one who can hash the password of the friend – ewww, a programmer is never a criminal.

I can’t afford to live a life where I am never going to see an error again. I still love those nights when I pulled my hairs in agression when a simple “System.NullReferenceException” made me stay awake entire night and understand and fix the error. That taste, that feeling is just perfection and no other feeling can even match it. Feeling of getting an error in your programming is the feeling of having those masalas added to your chicken – hmmm, yummy!

A master is the one, who gets to learn from his mistakes, who is not afraid to make a mistake even if that causes a havoc in his life, those mistakes make him understand what programming is what he needs to do what happens when he does what and all other such concepts. A master can never be a pessimist, that is why mostly people don’t get to this stage and it is never about the fame – we all are after. Once fame gets in your head you can never show your best and your skills will start to wither away. You can try pissing yourself off – run for fame, it will run away, run for your self show your best, fame will come for you, searching like a dead zombie searching for flesh.

A programmer can never think of anything bad, he is the one who is responsible for a good computing world – for a good environment for people to come and sit together share their views assets and others. If criminals would start to create internet and other technology assets there won’t be anything left at all to smile at – to have our faith in. We build programs, not for fame, we build it because we want to, we start a new framework and foundation because we want to help our fellows get more sleep at night, not to get a chance to come on the television to tell our cell phone number to the public – specially the women. Do think about your identity first, computer programming is not a field for fame or money. We are a family, don’t call us a community, it is a family, where elders are respected, juniors are taught and everyone loves everyone! There is no offense, no hate and just a happy and peacefull environment – untill people who love fame enter.

Blog at

Up ↑