How Much Water Under the Bridge?
Vector 8:4, page 25
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 25
The MULTIPLY function listed in the Editorial for January contained the following expression twice:
This was used to calculate the amount of time taken by the user to perform the multiplication test. There are several ways of calculating elapsed time in APL, some easier to use than others. In many systems, the Accounting Information (⎕AI) system function includes (often in the second component) an "elapsed seconds since start of session" value. Where present, this provides by far the easiest means of calculating elapsed time, but unfortunately it is not always available, and even if it is, it may measure milliseconds rather than seconds.
In Education Vector, we like to use methods that work with as many APL systems as possible. The Time Stamp (⎕TS) system function provides the most universal method of calculating elapsed time. This produces a seven-component vector: year, month, day, hour, minute, second, millisecond. Of course, it relies on your system clock being right!
MULTIPLY was concerned to present time in seconds, and so the millisecond component was ignored. Thus ¯4↑ selects the last four components of ⎕TS and ¯1↓ drops the final one, leaving hours, minutes and seconds. The Represent function (⊥), with left argument 0 60 60, converts the result to seconds. Note that the lengths of the two arguments of ⊥ must match, so the first component of the left argument can be any value, but it must be present. An alternative approach is to use a scalar left argument - since both minutes and seconds are measured in 60s, a left argument of 60 will do the trick. This is equivalent to a vector value of 60 60 60.
Subtracting the time the test is started from the time the test is completed, using this method of calculating time, will give the time taken (provided the test does not start before midnight and end after midnight!).
If you are worried about the problem of midnight, put 86400 | in front of the final calculation (86400 is 60×60×24). Finally, of course, if you want to measure time more accurately, the m’sec component can be kept in. Just use: