What is the way to calculate time *(could be in shortest units)* between two steps in a running program ?

For example :

```
algo() {
  long time_1 = time_X
  .
  .
  .
  long time_2 = time_Y

  difference = time_2 - time_1;
}

```

I have been calculating using `new GregorianCalendar().getTimeInMillis()`. But the difference I get is `0`.

Is there any way I can know the difference between some steps in any algorithm ? Here I want to know the difference between the first and the last step of algorithm. Just before the algorithm will make a final return.