- So the cool thing here and also in benchmarks
is we're also able to create sub benchmarks.
If you remember in the testing section,
which I hope you saw,
that we had the concept of sub test
where we were able to take data,
data driven tests, give them names,
run them individually, run them in parallel.
We've got the same concept here in Go with our benchmarks.
I wanna show you a really quick sub benchmark
and how we can leverage that as well.
So I've got that global variable again, GS.
Remember and I want that code to be thrown out
and we're gonna be using our S print
and our S print F's again.
But notice what I'm doing here in
the benchmark S print here.
I've actually created an un-exported function
on line 26 for our benchmarks.
Okay, line 26 now is the un-exported bench S print.
The un-exported bench S print F taking
our testing B pointer and we're gonna use
the name functions, not literal functions here
on the call to B dot run.
It's the same exact API using the B instead of the T.
And we've given it a name,
so this isn't necessarily data driven right?
Like our tests, but what we're gonna be able to do now is
filter,
okay?
Filter based on this sub name,
none or format, what we wanna do.
So there's our S print none,
we're not gonna do any formatting.
And then we give it the name format, there we are.
So I can run these benchmarks here as well.
I'm already in this command line.
There we are.
And I can do the go test again,
hey don't run anything that might
be called test something, get all that out of our way.
Let's do bench dot, let's change the bench time
to like three seconds, and we can still look
at memory for this test, there we go.
And throwing extra little keys in there
no big deal, we'll get it.
And we can see again that we've got that same output,
that same 68 nano seconds per op.
We ran a million,
50 million times, a hundred million times,
there it is all right there.
Let's run it again.
Just so we can see it a little bit cleaner again.
And you can see here how the sub name,
the sub name is now part of that output,
much cleaner output this way.
The same as before.
And the format.
And because now I've got the sub names
remember now what I can do here
is say okay, let's run S print, there it is.
And let's just focus on none.
And now it just comes in and just runs
S print slash none, so I just were able to focus now on
one of those tests instead of both.
Again at the sub testing level.
Now I would be very careful
of running sub benchmarks in parallel.
Only because you've gotta make sure
your machine is idle when we're doing all of this.
I'm gonna come back very soon
and we're gonna start talking about profiling.
I'm gonna be very focused around
what state your machine should be in,
but just as a note right now,
that when you're running these types
of performance benchmarks, okay?
Especially CPU based benchmarks,
I mean the machine has to be idle.
You can't be browsing the internet
and doing things because that machine
now is eating up CPU cycles you know, on the hardware,
so it's
not necessarily want to be running
benchmarks in parallel, right?
We still wanna run them
in series.
It just gives us a little extra granularity
for the benchmarks that we're creating.