Is it possible to calculate how much CPU and RAM uses block of code?

For example, I have the console app and I want calculate how much CPU and RAM uses by one method in my app.

```
//many difference methods

//method for which I want to calculate how RAM and CPU resources it uses
void test1(){
    //code
}

int main(int argc, char* argv[]) {
    //code

    //call test1
    test1();
    return 0;
}

```