WEBVTT

00:01.010 --> 00:01.520
Hi everyone.

00:01.520 --> 00:02.840
Welcome back to this tutorial.

00:02.840 --> 00:07.610
In this tutorial, we will explore the performance of these two methods.

00:07.610 --> 00:09.170
I missed one thing here.

00:09.290 --> 00:10.160
We take a look at this.

00:10.400 --> 00:12.920
In this method I'm not calling the parallel method.

00:13.040 --> 00:18.350
I'm going to make a call to this parallel method and then run this and then check whether the result

00:18.350 --> 00:19.430
are the same.

00:19.460 --> 00:20.270
We take a look at it.

00:20.270 --> 00:21.650
The result are the same.

00:21.650 --> 00:26.360
Now, in this tutorial we are going to focus on calculating the performance.

00:26.360 --> 00:26.840
Right?

00:26.840 --> 00:31.580
So for this purpose, what I'm going to do, I'm going to create a method called.

00:32.580 --> 00:33.360
Public.

00:36.400 --> 00:46.360
Static and then it is going to return a long it is going to be check performance result.

00:46.360 --> 00:49.240
And I would like to call these methods multiple times.

00:49.240 --> 00:54.070
So I want that to be a parameter to this method number of times.

00:55.300 --> 01:04.150
And then this is going to be so let's construct the for loop int I equal to zero I less than number

01:04.150 --> 01:06.940
of times then I plus plus.

01:08.360 --> 01:14.810
So in here we are going to call the some sequential stream and some parallel stream.

01:16.430 --> 01:20.330
And I would like to change this one to camel casing because that is a recommendation for the method

01:20.330 --> 01:21.500
names in Java.

01:21.650 --> 01:25.490
So I'm clicking refactor and then selecting the rename.

01:29.280 --> 01:30.840
Some sequential.

01:32.130 --> 01:35.190
Think, right, what is good.

01:35.190 --> 01:41.190
And then this is going to be some parallel string refactor rename.

01:43.930 --> 01:45.490
Some parallel string.

01:46.030 --> 01:46.570
There we go.

01:47.230 --> 01:49.120
All set in here.

01:49.120 --> 01:53.230
We are going to call some sequential stream and some parallel stream.

01:53.660 --> 01:54.250
Right.

01:54.250 --> 01:58.900
So I don't want to make the call to these two methods inside the for loop.

01:58.900 --> 02:04.310
I want to make the call separately and then take the result how it is performing.

02:04.330 --> 02:05.290
How can we do that?

02:05.290 --> 02:12.460
So for this method, right now I'm just passing the INT number of times I want to pass this method itself

02:12.460 --> 02:13.690
as a parameter to it.

02:13.810 --> 02:14.920
How can we achieve it?

02:15.130 --> 02:16.450
We take a look at this example.

02:16.450 --> 02:20.950
This looks like a supplier, if you remember from the previous tutorials, Supplier is a functional

02:20.950 --> 02:26.080
interface which doesn't accept any input, but it is going to return you a output.

02:26.230 --> 02:31.120
This particular method, these two methods look exactly like a.

02:32.460 --> 02:33.000
The player.

02:33.000 --> 02:38.970
So what I'm going to do in the place of this, I'm going to call, check performance result, and then

02:39.390 --> 02:41.220
I'm going to do parallel stream example.

02:41.220 --> 02:45.030
I'm going to make use of the method reference syntax.

02:45.270 --> 02:51.840
So as soon as I gave that to Colon is giving me the option, I'm going to call the sum sequential stream

02:51.840 --> 02:55.380
and then I'm going to make the call 20 times.

02:56.220 --> 02:57.930
So it is complaining.

02:58.290 --> 02:58.740
What is that?

02:58.740 --> 02:59.310
It is complaining.

02:59.310 --> 03:02.120
The parallel stream right now has only one method.

03:02.130 --> 03:02.490
Right?

03:02.490 --> 03:09.630
I'm going to change this one to supplier and of type integer because the return type is going to be

03:09.630 --> 03:15.450
an integer supplier and all those functional interfaces always refer to the wrapper version of the primitive

03:15.480 --> 03:15.930
type.

03:15.930 --> 03:19.290
So that's the reason why we have to give integer instead of int.

03:19.410 --> 03:21.330
I'm going to name this one as supplier.

03:21.360 --> 03:22.890
Let's import this.

03:23.220 --> 03:24.120
There you go.

03:24.120 --> 03:26.580
So and then the next one, what is the next one?

03:26.610 --> 03:32.790
The next one is going to be some parallel string, right?

03:33.000 --> 03:43.710
Let me give some code comments here is going to be sequential stream result.

03:47.150 --> 03:57.320
Can put this whole thing down and this is going to be a parallel stream result.

04:04.080 --> 04:06.330
So we take a look at it.

04:06.330 --> 04:10.260
This one is calling the sequential stream, and this one is calling the parallel stream.

04:10.260 --> 04:16.050
So in here, what we have to do, we have to call supplier dot get.

04:16.290 --> 04:20.640
So this is going to actually invoke these two methods, right?

04:20.640 --> 04:23.580
The next step is we want to calculate how long did it take?

04:23.580 --> 04:28.290
I'm going to use the system class for this purpose.

04:28.290 --> 04:33.720
It's going to be start time system dot current time milliseconds.

04:35.380 --> 04:46.030
And end time is going to be system dot runtime milliseconds and the return is going to be in time minus

04:46.030 --> 04:47.110
the start time.

04:47.890 --> 04:48.640
There you go.

04:48.670 --> 04:54.490
So this is going to give you the total time it took to execute this method, the number of times, the

04:54.490 --> 04:57.460
number of times value that we are passing is that 20 times.

04:57.460 --> 05:04.000
So this some sequential stream is going to be called 20 times and some parallel stream is going to be

05:04.000 --> 05:05.260
called 20 times.

05:05.260 --> 05:08.830
And then this is going to give you the number of.

05:09.850 --> 05:14.140
Then how many milliseconds that it took in order to calculate the output for you.

05:14.590 --> 05:14.890
Right.

05:14.890 --> 05:16.930
I'm going to run this example.

05:17.350 --> 05:18.490
We run this example.

05:18.490 --> 05:20.580
It took like this one.

05:20.590 --> 05:27.100
The sequential stream result took 15 milliseconds, but the parallel stream just took seven milliseconds.

05:27.100 --> 05:28.810
So what happens behind the scenes?

05:28.810 --> 05:30.050
What happens under the hood?

05:30.070 --> 05:31.750
How many threads got created?

05:31.780 --> 05:34.870
Those are the interesting things which might be running in your mind.

05:34.900 --> 05:38.080
I'm going to cover those in the next tutorial.

05:38.110 --> 05:40.280
With this, we came to the end of this tutorial.

05:40.300 --> 05:41.470
Thank you for watching.
