0
votes

Suppose we have following method

private int add(int num_1, int num_2) 
{
  return num_1+num+2;
}

Does calling this method consumes one cpu cycle ? As there are 1 billion cycles in 1 ghz.

1
The number of cycles/second is not directly related to the number of cycles required for a particular action. In any case, you many be interested in examining the 'assembly'-dump of such a C program/function or looking at the function ABI / calling conventions to give a general idea of the different steps that are applied; and then there is the work done inside the function itself .. - user2864740
that will depend a lot on the yielded assembly and CPU - if num_1 and num_2 are not in cache it might take more (usually will) - Random Dev

1 Answers

-1
votes

No. consider the function call sleep(5000) which causes your code to pause for 5 seconds. That would take more than 1 clock cycle.