Nested loops are faster!

While solving a problem on hackerrank, I had to use for nested loops in problem related to 2D array.  Then, I realised I should use single loop rather than nested and then, I tried myself both the approaches to check which approach is better and faster.

Every time for similar iterations, nested loops were faster than the single loops.  Below is the python code to verify yourself.
The following code takes the inputs 10, 20, 50, 100 and outputs the time required by both the approaches.

Python Code:


import time

def loopinloop(n):
    StartTime = time.time()
    for i in range(0, n):
        for j in range(0, n):
            # Do nothing
            continue;
    return (time.time() - StartTime);

def loopalone(n):
    StartTime = time.time()
    for i in range(0, n**2):
        continue;
    return (time.time() - StartTime);

if __name__ == "__main__":
    number = [10, 20, 50, 100];
    withinloops = [loopinloop(num) for num in number];
    oneloop = [loopalone(num) for num in number];
    print("withinloops = {0}".format(withinloops))
    print("one loop = {0}".format(oneloop))

Output:

withinloops = [1.0013580322265625e-05, 1.9073486328125e-05, 7.987022399902344e-05, 0.0002682209014892578]
one loop = [4.0531158447265625e-06, 1.1920928955078125e-05, 9.298324584960938e-05, 0.0003771781921386719]


As the above code and its output suggests, nested loops are faster which is quite a contradiction in itself i.e. O(n^2) is faster than O(n).  But after searching a little I found this Stackoverflow answer.

Thus, single loop is not always faster than nested loops.  It depends on the statements it is executing.  Hope this helps :)

Till then,

To Infinity and Beyond!

Everybody, Somebody, Anybody, Nobody!

During studying Communication Skills for my college exams, I found an amazing story which I would like to share.

Everybody, Somebody, Anybody, Nobody!

- A Communication Gap

This is a story about four people Everybody, Somebody, Anybody, and Nobody.  There was an important job to be done and Everybody was sure that Somebody would do it.  Anybody could have done it, but Nobody did it.  Somebody got angry about that, because it was Everybody's job.  Everybody thought Anybody could do it, but Nobody realized that Everybody wouldn't do it.  It ended up that Everybody blamed Somebody, when Nobody did what Anybody could have done!


Conclusion:  This story is far deeper than it might look and is best describe in team collaborative projects.  If any of you find difficulty understanding, please Comment. (It is rather difficult for me to explain it all over here)

Boot Loader vs BIOS!

If you guys have read my previous blog on LibreBoot, you guys might know that I have started to work on LibreBoot and here is something I like to share what I learn along the way on BIOS and boot-loader.

BIOS

BIOS is short for Basic Input Output System and is a very critical part of any computer system and it is very first part which powers up your system.

 When the system is powered on, a firmware loaded in a ROM(Read Only Memory) chip is executed and is known as BIOS.  This firmware takes care of your initials drivers required by your system for the keyboards and mouse to interact. Once the BIOS firmware is loaded, the process of booting goes to boot-loader.

Boot Loader

Booting takes place in two steps.  BIOS checks all the storage devices connected to the system and if the boot loader is present or not.

Boot Loader then in first step, checks for the master boot partition, aka MBR and verifies whether it is working or not i.e. not corrupted.

Then, in second step, boot loader points to the storage partition which stores the operating system for our system and is referenced by the MBR, whether it be windows or any linux based distribution.

In multiboot systems, MBR has the entry for all the storage partitions for all the operating system, and thus boot loader provides user the option to choose the operating system, s/he wants to use.


Note: Since I am learning these concepts on bootloader, bios and kernel.  So use this material on your risk.  I wont be responsible if your system crashes. :p








LibreBoot: An openSource Firmware

LibreBoot!

As an open source enthusiast, I find new open-source softwares almost every week.  This week I get to know about a great one, which I never thought of.  A Open-Source BIOS firmware alternative, LibreBoot.  The thought never struck me that there might also be Open source BIOS firmware out there

How I found it?

For some weeks, I was looking for some opensource projects which I can contribute to but I was too confused about which one to pick.  The main reason being, every new thing fascinates me and thus I got distracted too easily.  Discussing these issues with my dgplug mentor Shakti kannan aka mbuf, I found my core competence (low level computer stuff, 0s and 1s) and most of all, I learnt to say No! to other fascinating stuff which distracted me a lot.

mbuf advised me to check on LibreBoot and see if it helps.  When I first encounter libreboot documentation, i couldn't understand much, but searching a little about it, I started to liked it.

What is it?

Libreboot (formerly known as GNU Libreboot) is a free software project aimed at replacing the proprietary BIOS firmware found in most computers with a libre, lightweight system designed to perform only the minimum number of tasks necessary to load and run a modern 32-bit or 64-bit operating system.


How can you get started?


I wont go into much detail, but there is one advice i would like to give: Hold on, take your time, it might not get to you at first.

  • Read about it and its history here.
  • Download the source code for libre boot from its git repository hosted here by:          git clone https://notabug.org/libreboot/libreboot.git

  • Try and install it on your system (Recommended on Test System).
  • See if you like it.
  • Have fun with its code.

As you can see in its documentation, its tested for limited devices/hardwares and here's your chance, go try and  test it on your on.












The Rabbit or Turlte

"The Rabbit and The Turtle"

We all have heard of this Aesop "The Rabbit and The Turtle". It is a story where a turtle despite being slow challenges rabbit for a race and rabbit out of overconfidence, stop to take a nap and lost it.

The moral behind this story was "Slow and Steady wins the race".

Most of you must have heard this story only up to here, let me tell you my friends, it was just a trailer.

"The Story Beyond"

At the end of the race, rabbit realized his mistake and out of shame (cause one of the fast animal was lost to one of the slowest animal) went to challenge the turtle again.
As expected, this time rabbit won the race.

The moral behind this part is "Fast and Persistent wins the race".

But Wait a minute, there's still something left,

"The Final Blow"


This time, turtle again challenges the rabbit with a condition of choosing the arena himself and Rabbit said yes! (No doubt)

Out of Rabbits surprise, the arena for the race was the pond.  And there is no doubt that this time turtle won the race.

The moral of the Final Blow is: "Never Underestimate your core competence"


Now, What I concluded of all this...

Conclusion

Part 1(Slow and Steady):

As a tech-geek, we should approach to learn any new technology Slow and Steady, never quit in between or you will loose to those, who were once lacking from you.  So Always, delve deeper into new technologies slow and steady to get a good grasp.

Part 2 (Fast and Persistent):

If Someone like me, wants to learn something in a very short time, this approach will be the best.  You have to approach the technologies with a faster pace and keep it persistent.
But also like me, most of you, might not be persistent and may take a pause which is their biggest mistake.

Part 3 (Core Competence):

Never Underestimate your Core Competence, everyone got something, everyone has something special. Everyone is pretty good at some things and not at all in other things.


Now, you might wonder how come we are discussing these stuff today.  Because..., I didn't know about these other two parts and When I did, I felt I should spread the word.

Moving!

It's been a long time, since I published anything here, but that doesn't mean I stop writing, I kept writing everyday, just didn...