Friday, March 22, 2013

Difference between a compiler and interpreter

What is the difference between a compiler and interpreter?

First, what is a program?
Program is set of instruction which tells computer what to do.

Compiler is a program who understand the instruction written by you in a particular language and outputs a new program and now new program is given to computer to act on.

Where interpreter does does both tasks at once.

What exactly it means when we say i have 2.5 GHz cpu

One day i thought what is exactly means when we say i have 2.5 GHz cpu in my system.

I was very confused some says its the speed how fast your computer can executes your program, but computer executes every thing in cycles. After some google i found the answer.

We know speed of light

299 792 458 meters / second  
1 meter = 100 centimeter
1 nanosecond  = 1/1000000000 seconds 

distance traveled by light in one nanosecond would be around
29.9 792 458 cm

2.5 GHz = 2.5 billion cycles per second
i.e 2.5 billion equals to 2500000000 cycles per second

when we talk in nano seconds it comes 2.5 cycles in 1 nano seconds



1 nano  = 29.9 792 458 cm in term of light
1 nano  = 2.5 cpu cycles

when we compare cpu cycle with distance traveled by light

1 cycle  =  29.972458/2.5 = 11.9889832 cm 

so cpu completes one cycle when the light travels only 11.9889832 cm
 
Imagine......:-)