Snap! allows us to report how long a program takes to finish.
current (
date)
reporter. Drag it into the scripting area. From its input menu, select time in milliseconds.
This block can be used to time how long a reporter takes to output. Here’s an algorithm:
time function
that takes any reporter (with its inputs filled in), computes the result, but reports how long it took to do the computation. The answer will be in milliseconds.list from
block with any reporter. You can edit time function
to see how it works.In this example, it took 27 milliseconds to compute the list of integers from 1 to 1000. (The actual number will depend on how fast your computer is.)
time function
to compare Alphie and Betsy's ways of adding the integers from 1 to n. Try it with several different large numbers to see just how different the algorithms are in terms of the time it takes to compute their outputs.position of __ in unsorted list
works for any list as a linear search, checking element-by-element until it finds a match (or gets to the end and reports "Not In List"). The reporter position of __ in sorted list
works on sorted lists as a binary search algorithm. So, both will work on sorted lists. Compare them for some long sorted lists and make a table of your findings. You may have to use very large lists, say 1000 or 2000 items, to get meaningful results.
Time your algorithms for varying size inputs and describe the different behaviors you see. Again, use large inputs for meaningful results.