Is there a way to start and stop logging multiple lines of statements and time to execute?

Viewed 50

Let's say I have a unit test like this:

@Test
public void testSomething(){
    Car car = new Car();
    car.setColor("blue");
    car.setSize("big");
}

I want to see how much time it takes to execute the statement, is there a "Log with timer" feature like below to record every statement it has executed (and its time taken)?

@Test
public void testSomething(){
    logWithTimer.start();
    Car car = new Car();
    car.setColor("blue");
    car.setSize("big");
    logWithTimer.finish();
}

So when I run the unit test above, the output will be like this:

15:23:456 Car car = new Car();
15:23:470 car.setColor("blue");
15:23:500 car.setSize("big");
3 Answers
Related