Timing Our Search Scripts1:19 with Jay McGavren
Let's try our Linear Search and Binary Search scripts out with the `time` command and see how they compare.
Let's try our linear search and 0:00 binary search scripts out with the time command and see how they compare. 0:01 I've commented out the lines that print the indexes of matches in the two scripts. 0:05 That way, they'll still cull their respective search functions with 0:11 the 100 names we're searching for, but they won't actually print the indexes out. 0:14 So we won't have a bunch of output obscuring the results of the time command. 0:18 First, let's try the linear search script, 0:22 time python linear_search.py names. 0:26 And we can just use the unsorted list of names for linear search. 0:31 Remember, we want to ignore the real result and add the user and 0:37 sys results together. 0:41 It looks like it took about .9 seconds to find the 100 things in 0:42 the list of 100,000. 0:47 Now let us try timing the binary search script. 0:49 Time python binary_search.py, names/ and 0:52 for this one, we need to use the sorted list of names. 0:56 Looks like that took around a quarter second. 1:04 So less than half as long. 1:06 Bear in mind that part of this time is spent loading the file names into a list. 1:08 The difference between linear search and binary search will be even more pronounced 1:12 as you search through bigger lists or search for more items. 1:15
You need to sign up for Treehouse in order to download course files.Sign up