1 00:00:06,580 --> 00:00:08,910 - So the cool thing here and also in benchmarks 2 00:00:08,910 --> 00:00:11,650 is we're also able to create sub benchmarks. 3 00:00:11,650 --> 00:00:13,290 If you remember in the testing section, 4 00:00:13,290 --> 00:00:14,710 which I hope you saw, 5 00:00:14,710 --> 00:00:17,340 that we had the concept of sub test 6 00:00:17,340 --> 00:00:19,340 where we were able to take data, 7 00:00:19,340 --> 00:00:21,600 data driven tests, give them names, 8 00:00:21,600 --> 00:00:24,050 run them individually, run them in parallel. 9 00:00:24,050 --> 00:00:29,050 We've got the same concept here in Go with our benchmarks. 10 00:00:29,100 --> 00:00:31,780 I wanna show you a really quick sub benchmark 11 00:00:31,780 --> 00:00:34,300 and how we can leverage that as well. 12 00:00:34,300 --> 00:00:36,280 So I've got that global variable again, GS. 13 00:00:36,280 --> 00:00:38,070 Remember and I want that code to be thrown out 14 00:00:38,070 --> 00:00:39,310 and we're gonna be using our S print 15 00:00:39,310 --> 00:00:41,500 and our S print F's again. 16 00:00:41,500 --> 00:00:43,281 But notice what I'm doing here in 17 00:00:43,281 --> 00:00:46,090 the benchmark S print here. 18 00:00:46,090 --> 00:00:49,580 I've actually created an un-exported function 19 00:00:49,580 --> 00:00:52,210 on line 26 for our benchmarks. 20 00:00:52,210 --> 00:00:55,510 Okay, line 26 now is the un-exported bench S print. 21 00:00:55,510 --> 00:00:58,160 The un-exported bench S print F taking 22 00:00:58,160 --> 00:01:00,330 our testing B pointer and we're gonna use 23 00:01:00,330 --> 00:01:02,850 the name functions, not literal functions here 24 00:01:02,850 --> 00:01:04,640 on the call to B dot run. 25 00:01:04,640 --> 00:01:09,200 It's the same exact API using the B instead of the T. 26 00:01:09,200 --> 00:01:10,670 And we've given it a name, 27 00:01:10,670 --> 00:01:13,404 so this isn't necessarily data driven right? 28 00:01:13,404 --> 00:01:17,560 Like our tests, but what we're gonna be able to do now is 29 00:01:17,560 --> 00:01:19,070 filter, 30 00:01:19,070 --> 00:01:20,170 okay? 31 00:01:20,170 --> 00:01:22,980 Filter based on this sub name, 32 00:01:22,980 --> 00:01:25,840 none or format, what we wanna do. 33 00:01:25,840 --> 00:01:28,320 So there's our S print none, 34 00:01:28,320 --> 00:01:29,700 we're not gonna do any formatting. 35 00:01:29,700 --> 00:01:32,540 And then we give it the name format, there we are. 36 00:01:32,540 --> 00:01:35,490 So I can run these benchmarks here as well. 37 00:01:35,490 --> 00:01:37,690 I'm already in this command line. 38 00:01:37,690 --> 00:01:38,700 There we are. 39 00:01:38,700 --> 00:01:40,640 And I can do the go test again, 40 00:01:40,640 --> 00:01:42,390 hey don't run anything that might 41 00:01:42,390 --> 00:01:46,160 be called test something, get all that out of our way. 42 00:01:46,160 --> 00:01:49,810 Let's do bench dot, let's change the bench time 43 00:01:49,810 --> 00:01:52,640 to like three seconds, and we can still look 44 00:01:52,640 --> 00:01:56,130 at memory for this test, there we go. 45 00:01:56,130 --> 00:01:58,100 And throwing extra little keys in there 46 00:01:58,100 --> 00:01:59,800 no big deal, we'll get it. 47 00:01:59,800 --> 00:02:02,540 And we can see again that we've got that same output, 48 00:02:02,540 --> 00:02:05,410 that same 68 nano seconds per op. 49 00:02:05,410 --> 00:02:07,290 We ran a million, 50 00:02:07,290 --> 00:02:09,870 50 million times, a hundred million times, 51 00:02:09,870 --> 00:02:11,900 there it is all right there. 52 00:02:11,900 --> 00:02:12,933 Let's run it again. 53 00:02:14,010 --> 00:02:16,370 Just so we can see it a little bit cleaner again. 54 00:02:16,370 --> 00:02:18,970 And you can see here how the sub name, 55 00:02:18,970 --> 00:02:21,050 the sub name is now part of that output, 56 00:02:21,050 --> 00:02:22,270 much cleaner output this way. 57 00:02:22,270 --> 00:02:23,700 The same as before. 58 00:02:23,700 --> 00:02:24,760 And the format. 59 00:02:24,760 --> 00:02:27,530 And because now I've got the sub names 60 00:02:27,530 --> 00:02:30,480 remember now what I can do here 61 00:02:30,480 --> 00:02:34,110 is say okay, let's run S print, there it is. 62 00:02:34,110 --> 00:02:36,540 And let's just focus on none. 63 00:02:36,540 --> 00:02:38,860 And now it just comes in and just runs 64 00:02:38,860 --> 00:02:41,950 S print slash none, so I just were able to focus now on 65 00:02:41,950 --> 00:02:43,920 one of those tests instead of both. 66 00:02:43,920 --> 00:02:46,810 Again at the sub testing level. 67 00:02:46,810 --> 00:02:49,190 Now I would be very careful 68 00:02:49,190 --> 00:02:53,300 of running sub benchmarks in parallel. 69 00:02:53,300 --> 00:02:55,710 Only because you've gotta make sure 70 00:02:55,710 --> 00:02:58,470 your machine is idle when we're doing all of this. 71 00:02:58,470 --> 00:02:59,600 I'm gonna come back very soon 72 00:02:59,600 --> 00:03:01,890 and we're gonna start talking about profiling. 73 00:03:01,890 --> 00:03:03,690 I'm gonna be very focused around 74 00:03:03,690 --> 00:03:05,350 what state your machine should be in, 75 00:03:05,350 --> 00:03:07,570 but just as a note right now, 76 00:03:07,570 --> 00:03:09,040 that when you're running these types 77 00:03:09,040 --> 00:03:11,260 of performance benchmarks, okay? 78 00:03:11,260 --> 00:03:13,610 Especially CPU based benchmarks, 79 00:03:13,610 --> 00:03:15,030 I mean the machine has to be idle. 80 00:03:15,030 --> 00:03:16,940 You can't be browsing the internet 81 00:03:16,940 --> 00:03:19,300 and doing things because that machine 82 00:03:19,300 --> 00:03:22,500 now is eating up CPU cycles you know, on the hardware, 83 00:03:22,500 --> 00:03:23,490 so it's 84 00:03:23,490 --> 00:03:25,330 not necessarily want to be running 85 00:03:25,330 --> 00:03:27,250 benchmarks in parallel, right? 86 00:03:27,250 --> 00:03:28,480 We still wanna run them 87 00:03:29,360 --> 00:03:30,540 in series. 88 00:03:30,540 --> 00:03:33,060 It just gives us a little extra granularity 89 00:03:33,060 --> 00:03:35,010 for the benchmarks that we're creating.