Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
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
binary search scripts out with the time command and see how they compare.
I've commented out the lines that print the indexes of matches in the two scripts.
That way, they'll still cull their respective search functions with
the 100 names we're searching for, but they won't actually print the indexes out.
So we won't have a bunch of output obscuring the results of the time command.
First, let's try the linear search script,
time python linear_search.py names.
And we can just use the unsorted list of names for linear search.
Remember, we want to ignore the real result and add the user and
sys results together.
It looks like it took about .9 seconds to find the 100 things in
the list of 100,000.
Now let us try timing the binary search script.
Time python binary_search.py, names/ and
for this one, we need to use the sorted list of names.
Looks like that took around a quarter second.
So less than half as long.
Bear in mind that part of this time is spent loading the file names into a list.
The difference between linear search and binary search will be even more pronounced
as you search through bigger lists or search for more items.
You need to sign up for Treehouse in order to download course files.Sign up