Texas Instruments TI-89 Tip List page 336

Graphing calculator
Hide thumbs Also See for TI-89:
Table of Contents

Advertisement

tval()
Prgm
© Pass matrix by value
Local f1,k,r
Define f1(mat)=Func
Return mat[1,1]
EndFunc
For k,1,50
f1(m)→r
EndFor
EndPrgm
The tval() routine passes the matrix m by value, and tref() passes the matrix name as a string. tval()
takes about 199 mS for each function call, while tref() takes about 31 mS. This is an improvement of
about 84%.
Even though it is faster to call a function with the reference method, it takes longer to access the matrix
elements with indirection. For some combination of function calls and matrix element accesses the
total execution time is the same for either method. This is called the break-even point. In general, the
total execution time is
T = N c T c + N a T a
where Nc and Na are respectively the number of function calls and element accesses, and Tc and Ta
are the execution times for each function call and element access. More specifically, the total execution
times for each method are
T v = N cv T cv + N av T av
T r = N cr T cr + N ar T ar
The break-even point is at Tv = Tr. We want to compare the two methods with the same conditions, so
we equate the number of function calls and element accesses for each method:
N cv = N cr = N c
Equate the expressions for Tv and Tr:
and solve for Nc:
With equation [2], we can find the break-even point at which the two methods have the same execution
time, for some number of function calls and matrix accesses. Tcv is found with equation [1] above, and
Tcr is a constant:
T cr = 16.88 mS/access
Timing experiments show that the time required to access a matrix element depends on the number of
matrix rows and columns, as well as the element's location in the matrix. The access time also
changes slightly if the indices are constants or variables. Timing data shows that Tar - Tav is relatively
constant at about 5.7 mS, so equation [2] simplifies to
tref()
Prgm
© Pass matrix by reference (name)
Local f2,k,r
Define f2(mat)=Func
Return #mat[1,1]
EndFunc
For k,1,50
f2("m")→r
EndFor
EndPrgm
Value method
Reference method
N av = N ar = N a
N c T cv + N a T av = N c T cr + N a T av
T ar −T av
N c = N a
T cv −T cr
T ar −T av
N c
N a =
or
T cv −T cr
[2]
7 - 47

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ti-92+

Table of Contents